Richard Hughes | 02c90d8 | 2018-08-09 12:13:03 +0100 | [diff] [blame] | 1 | /* |
Richard Hughes | 2de8f13 | 2018-01-17 09:12:02 +0000 | [diff] [blame] | 2 | * Copyright (C) 2015-2018 Richard Hughes <richard@hughsie.com> |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3 | * |
Mario Limonciello | 51308e6 | 2018-05-28 20:05:46 -0500 | [diff] [blame] | 4 | * SPDX-License-Identifier: LGPL-2.1+ |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
Richard Hughes | b08e7bc | 2018-09-11 10:51:13 +0100 | [diff] [blame] | 7 | #define G_LOG_DOMAIN "FuEngine" |
| 8 | |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 9 | #include "config.h" |
| 10 | |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 11 | #include <gio/gio.h> |
Richard Hughes | 9e5675e | 2019-11-22 09:35:03 +0000 | [diff] [blame] | 12 | #ifdef HAVE_GIO_UNIX |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 13 | #include <gio/gunixinputstream.h> |
Richard Hughes | 9e5675e | 2019-11-22 09:35:03 +0000 | [diff] [blame] | 14 | #endif |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 15 | #include <glib-object.h> |
Richard Hughes | 1665837 | 2019-11-22 09:23:59 +0000 | [diff] [blame] | 16 | #ifdef HAVE_GUDEV |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 17 | #include <gudev/gudev.h> |
Richard Hughes | 1665837 | 2019-11-22 09:23:59 +0000 | [diff] [blame] | 18 | #endif |
Richard Hughes | bd4d285 | 2017-09-13 14:05:14 +0100 | [diff] [blame] | 19 | #include <string.h> |
Richard Hughes | fc1e267 | 2019-11-22 08:53:33 +0000 | [diff] [blame] | 20 | #ifdef HAVE_UTSNAME_H |
Richard Hughes | 473c520 | 2018-01-11 21:06:16 +0000 | [diff] [blame] | 21 | #include <sys/utsname.h> |
Richard Hughes | fc1e267 | 2019-11-22 08:53:33 +0000 | [diff] [blame] | 22 | #endif |
Richard Hughes | 019a1bc | 2019-11-26 10:19:33 +0000 | [diff] [blame] | 23 | #include <errno.h> |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 24 | |
| 25 | #include "fwupd-common-private.h" |
| 26 | #include "fwupd-enums-private.h" |
| 27 | #include "fwupd-error.h" |
| 28 | #include "fwupd-release-private.h" |
| 29 | #include "fwupd-remote-private.h" |
| 30 | #include "fwupd-resources.h" |
| 31 | |
Richard Hughes | c6eb416 | 2020-02-27 10:02:36 +0000 | [diff] [blame] | 32 | #include "fu-cabinet.h" |
Richard Hughes | deea2da | 2017-12-15 15:40:44 +0000 | [diff] [blame] | 33 | #include "fu-common-cab.h" |
Richard Hughes | 943d2c9 | 2017-06-21 09:04:39 +0100 | [diff] [blame] | 34 | #include "fu-common.h" |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 35 | #include "fu-config.h" |
| 36 | #include "fu-debug.h" |
Richard Hughes | 0a7e783 | 2017-11-22 11:01:13 +0000 | [diff] [blame] | 37 | #include "fu-device-list.h" |
Richard Hughes | 9dde04f | 2017-09-13 12:07:15 +0100 | [diff] [blame] | 38 | #include "fu-device-private.h" |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 39 | #include "fu-engine.h" |
Mario Limonciello | d81ea2e | 2020-01-13 14:11:43 -0600 | [diff] [blame] | 40 | #include "fu-engine-helper.h" |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 41 | #include "fu-hwids.h" |
Richard Hughes | 75b965d | 2018-11-15 13:51:21 +0000 | [diff] [blame] | 42 | #include "fu-idle.h" |
Richard Hughes | 7383ce2 | 2018-05-08 14:14:35 +0100 | [diff] [blame] | 43 | #include "fu-keyring-utils.h" |
Richard Hughes | f425d29 | 2019-01-18 17:57:39 +0000 | [diff] [blame] | 44 | #include "fu-hash.h" |
Richard Hughes | bc3a4e1 | 2018-01-06 22:41:47 +0000 | [diff] [blame] | 45 | #include "fu-history.h" |
Richard Hughes | 37d0943 | 2018-09-09 10:39:45 +0100 | [diff] [blame] | 46 | #include "fu-mutex.h" |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 47 | #include "fu-plugin.h" |
Richard Hughes | e7e9545 | 2017-11-22 09:05:53 +0000 | [diff] [blame] | 48 | #include "fu-plugin-list.h" |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 49 | #include "fu-plugin-private.h" |
| 50 | #include "fu-quirks.h" |
Richard Hughes | d1808aa | 2019-12-10 15:20:30 +0000 | [diff] [blame] | 51 | #include "fu-remote-list.h" |
Richard Hughes | b246bca | 2020-05-18 14:31:35 +0100 | [diff] [blame] | 52 | #include "fu-security-attr.h" |
Richard Hughes | f58ac73 | 2020-05-12 15:23:44 +0100 | [diff] [blame] | 53 | #include "fu-security-attrs-private.h" |
Mario Limonciello | 6b0e663 | 2019-11-22 13:04:32 -0600 | [diff] [blame] | 54 | #include "fu-smbios-private.h" |
Richard Hughes | 405baeb | 2018-09-06 14:23:08 +0100 | [diff] [blame] | 55 | #include "fu-udev-device-private.h" |
Richard Hughes | c125ec0 | 2018-09-05 19:35:17 +0100 | [diff] [blame] | 56 | #include "fu-usb-device-private.h" |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 57 | |
Richard Hughes | 95c98a9 | 2019-10-22 16:03:15 +0100 | [diff] [blame] | 58 | #include "fu-dfu-firmware.h" |
| 59 | #include "fu-ihex-firmware.h" |
| 60 | #include "fu-srec-firmware.h" |
| 61 | |
Richard Hughes | 3d00522 | 2019-05-17 14:02:41 +0100 | [diff] [blame] | 62 | #ifdef HAVE_SYSTEMD |
| 63 | #include "fu-systemd.h" |
| 64 | #endif |
| 65 | |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 66 | static void fu_engine_finalize (GObject *obj); |
| 67 | |
| 68 | struct _FuEngine |
| 69 | { |
| 70 | GObject parent_instance; |
Richard Hughes | 5b5f655 | 2018-05-18 10:22:39 +0100 | [diff] [blame] | 71 | FuAppFlags app_flags; |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 72 | GUsbContext *usb_ctx; |
Richard Hughes | 1665837 | 2019-11-22 09:23:59 +0000 | [diff] [blame] | 73 | #ifdef HAVE_GUDEV |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 74 | GUdevClient *gudev_client; |
Richard Hughes | 1665837 | 2019-11-22 09:23:59 +0000 | [diff] [blame] | 75 | #endif |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 76 | FuConfig *config; |
Richard Hughes | d1808aa | 2019-12-10 15:20:30 +0000 | [diff] [blame] | 77 | FuRemoteList *remote_list; |
Richard Hughes | 0a7e783 | 2017-11-22 11:01:13 +0000 | [diff] [blame] | 78 | FuDeviceList *device_list; |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 79 | FwupdStatus status; |
Richard Hughes | f425d29 | 2019-01-18 17:57:39 +0000 | [diff] [blame] | 80 | gboolean tainted; |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 81 | guint percentage; |
Richard Hughes | bc3a4e1 | 2018-01-06 22:41:47 +0000 | [diff] [blame] | 82 | FuHistory *history; |
Richard Hughes | 75b965d | 2018-11-15 13:51:21 +0000 | [diff] [blame] | 83 | FuIdle *idle; |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 84 | XbSilo *silo; |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 85 | gboolean coldplug_running; |
| 86 | guint coldplug_id; |
| 87 | guint coldplug_delay; |
Richard Hughes | e7e9545 | 2017-11-22 09:05:53 +0000 | [diff] [blame] | 88 | FuPluginList *plugin_list; |
Richard Hughes | c02ee4d | 2018-05-22 15:46:03 +0100 | [diff] [blame] | 89 | GPtrArray *plugin_filter; |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 90 | GPtrArray *udev_subsystems; |
Richard Hughes | 1665837 | 2019-11-22 09:23:59 +0000 | [diff] [blame] | 91 | #ifdef HAVE_GUDEV |
Richard Hughes | 5e952ce | 2019-08-26 11:09:46 +0100 | [diff] [blame] | 92 | GHashTable *udev_changed_ids; /* sysfs:FuEngineUdevChangedHelper */ |
Richard Hughes | 1665837 | 2019-11-22 09:23:59 +0000 | [diff] [blame] | 93 | #endif |
Richard Hughes | 49e5e05 | 2017-09-03 12:15:41 +0100 | [diff] [blame] | 94 | FuSmbios *smbios; |
Richard Hughes | d7704d4 | 2017-08-08 20:29:09 +0100 | [diff] [blame] | 95 | FuHwids *hwids; |
Richard Hughes | 9c028f0 | 2017-10-28 21:14:28 +0100 | [diff] [blame] | 96 | FuQuirks *quirks; |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 97 | GHashTable *runtime_versions; |
Richard Hughes | 34e0dab | 2018-04-20 16:43:00 +0100 | [diff] [blame] | 98 | GHashTable *compile_versions; |
Richard Hughes | 8dd4c1c | 2019-03-03 18:27:57 +0000 | [diff] [blame] | 99 | GHashTable *approved_firmware; |
Richard Hughes | 95c98a9 | 2019-10-22 16:03:15 +0100 | [diff] [blame] | 100 | GHashTable *firmware_gtypes; |
Richard Hughes | 0917fb6 | 2019-09-21 12:55:37 +0100 | [diff] [blame] | 101 | gchar *host_machine_id; |
Richard Hughes | d5aab65 | 2020-02-25 12:47:50 +0000 | [diff] [blame] | 102 | JcatContext *jcat_context; |
Mario Limonciello | 46aaee8 | 2019-01-10 12:58:00 -0600 | [diff] [blame] | 103 | gboolean loaded; |
Richard Hughes | 196c6c6 | 2020-05-11 19:42:47 +0100 | [diff] [blame] | 104 | gchar *host_security_id; |
| 105 | gboolean host_security_id_valid; |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 106 | }; |
| 107 | |
| 108 | enum { |
| 109 | SIGNAL_CHANGED, |
| 110 | SIGNAL_DEVICE_ADDED, |
| 111 | SIGNAL_DEVICE_REMOVED, |
| 112 | SIGNAL_DEVICE_CHANGED, |
| 113 | SIGNAL_STATUS_CHANGED, |
| 114 | SIGNAL_PERCENTAGE_CHANGED, |
| 115 | SIGNAL_LAST |
| 116 | }; |
| 117 | |
| 118 | static guint signals[SIGNAL_LAST] = { 0 }; |
| 119 | |
| 120 | G_DEFINE_TYPE (FuEngine, fu_engine, G_TYPE_OBJECT) |
| 121 | |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 122 | static void |
| 123 | fu_engine_emit_changed (FuEngine *self) |
| 124 | { |
| 125 | g_signal_emit (self, signals[SIGNAL_CHANGED], 0); |
Richard Hughes | 75b965d | 2018-11-15 13:51:21 +0000 | [diff] [blame] | 126 | fu_engine_idle_reset (self); |
Mario Limonciello | d81ea2e | 2020-01-13 14:11:43 -0600 | [diff] [blame] | 127 | |
| 128 | /* update the motd */ |
| 129 | if (self->loaded && |
| 130 | fu_config_get_update_motd (self->config)) { |
| 131 | g_autoptr(GError) error_local = NULL; |
| 132 | if (!fu_engine_update_motd (self, &error_local)) |
| 133 | g_debug ("%s", error_local->message); |
| 134 | } |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | static void |
Richard Hughes | 170c0c1 | 2017-11-22 11:26:24 +0000 | [diff] [blame] | 138 | fu_engine_emit_device_changed (FuEngine *self, FuDevice *device) |
| 139 | { |
Richard Hughes | 196c6c6 | 2020-05-11 19:42:47 +0100 | [diff] [blame] | 140 | self->host_security_id_valid = FALSE; |
Richard Hughes | 170c0c1 | 2017-11-22 11:26:24 +0000 | [diff] [blame] | 141 | g_signal_emit (self, signals[SIGNAL_DEVICE_CHANGED], 0, device); |
| 142 | } |
| 143 | |
Mario Limonciello | da0d188 | 2020-05-05 14:16:39 -0500 | [diff] [blame] | 144 | static gint |
| 145 | fu_engine_gtypes_sort_cb (gconstpointer a, gconstpointer b) |
| 146 | { |
| 147 | const gchar *stra = *((const gchar **) a); |
| 148 | const gchar *strb = *((const gchar **) b); |
| 149 | return g_strcmp0 (stra, strb); |
| 150 | } |
| 151 | |
Richard Hughes | 95c98a9 | 2019-10-22 16:03:15 +0100 | [diff] [blame] | 152 | GPtrArray * |
| 153 | fu_engine_get_firmware_gtype_ids (FuEngine *self) |
| 154 | { |
| 155 | GPtrArray *firmware_gtypes = g_ptr_array_new_with_free_func (g_free); |
| 156 | g_autoptr(GList) keys = g_hash_table_get_keys (self->firmware_gtypes); |
| 157 | for (GList *l = keys; l != NULL; l = l->next) { |
| 158 | const gchar *id = l->data; |
| 159 | g_ptr_array_add (firmware_gtypes, g_strdup (id)); |
| 160 | } |
Mario Limonciello | da0d188 | 2020-05-05 14:16:39 -0500 | [diff] [blame] | 161 | g_ptr_array_sort (firmware_gtypes, fu_engine_gtypes_sort_cb); |
Richard Hughes | 95c98a9 | 2019-10-22 16:03:15 +0100 | [diff] [blame] | 162 | return firmware_gtypes; |
| 163 | } |
| 164 | |
| 165 | GType |
| 166 | fu_engine_get_firmware_gtype_by_id (FuEngine *self, const gchar *id) |
| 167 | { |
| 168 | return GPOINTER_TO_SIZE (g_hash_table_lookup (self->firmware_gtypes, id)); |
| 169 | } |
| 170 | |
| 171 | static void |
| 172 | fu_engine_add_firmware_gtype (FuEngine *self, const gchar *id, GType gtype) |
| 173 | { |
| 174 | g_hash_table_insert (self->firmware_gtypes, g_strdup (id), GSIZE_TO_POINTER (gtype)); |
| 175 | } |
| 176 | |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 177 | /** |
| 178 | * fu_engine_get_status: |
| 179 | * @self: A #FuEngine |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 180 | * |
| 181 | * Gets the current engine status. |
| 182 | * |
| 183 | * Returns: a #FwupdStatus, e.g. %FWUPD_STATUS_DECOMPRESSING |
| 184 | **/ |
| 185 | FwupdStatus |
| 186 | fu_engine_get_status (FuEngine *self) |
| 187 | { |
| 188 | g_return_val_if_fail (FU_IS_ENGINE (self), 0); |
| 189 | return self->status; |
| 190 | } |
| 191 | |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 192 | static void |
| 193 | fu_engine_set_status (FuEngine *self, FwupdStatus status) |
| 194 | { |
| 195 | if (self->status == status) |
| 196 | return; |
| 197 | self->status = status; |
| 198 | |
| 199 | /* emit changed */ |
| 200 | g_debug ("Emitting PropertyChanged('Status'='%s')", |
| 201 | fwupd_status_to_string (status)); |
| 202 | g_signal_emit (self, signals[SIGNAL_STATUS_CHANGED], 0, status); |
| 203 | } |
| 204 | |
| 205 | static void |
| 206 | fu_engine_set_percentage (FuEngine *self, guint percentage) |
| 207 | { |
| 208 | if (self->percentage == percentage) |
| 209 | return; |
| 210 | self->percentage = percentage; |
| 211 | |
| 212 | /* emit changed */ |
| 213 | g_signal_emit (self, signals[SIGNAL_PERCENTAGE_CHANGED], 0, percentage); |
| 214 | } |
| 215 | |
| 216 | static void |
Richard Hughes | 4a03601 | 2017-11-30 16:33:24 +0000 | [diff] [blame] | 217 | fu_engine_progress_notify_cb (FuDevice *device, GParamSpec *pspec, FuEngine *self) |
| 218 | { |
Richard Hughes | 2a77afc | 2019-01-30 11:19:48 +0000 | [diff] [blame] | 219 | if (fu_device_get_status (device) == FWUPD_STATUS_UNKNOWN) |
| 220 | return; |
Richard Hughes | 4a03601 | 2017-11-30 16:33:24 +0000 | [diff] [blame] | 221 | fu_engine_set_percentage (self, fu_device_get_progress (device)); |
Richard Hughes | ec85ebc | 2018-08-10 09:52:30 +0100 | [diff] [blame] | 222 | fu_engine_emit_device_changed (self, device); |
Richard Hughes | 4a03601 | 2017-11-30 16:33:24 +0000 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | static void |
| 226 | fu_engine_status_notify_cb (FuDevice *device, GParamSpec *pspec, FuEngine *self) |
| 227 | { |
| 228 | fu_engine_set_status (self, fu_device_get_status (device)); |
Richard Hughes | ec85ebc | 2018-08-10 09:52:30 +0100 | [diff] [blame] | 229 | fu_engine_emit_device_changed (self, device); |
Richard Hughes | 4a03601 | 2017-11-30 16:33:24 +0000 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | static void |
Richard Hughes | fbcebe0 | 2017-12-11 16:37:19 +0000 | [diff] [blame] | 233 | fu_engine_watch_device (FuEngine *self, FuDevice *device) |
Richard Hughes | 4a03601 | 2017-11-30 16:33:24 +0000 | [diff] [blame] | 234 | { |
Richard Hughes | 5a9a6bd | 2018-09-10 10:02:20 +0100 | [diff] [blame] | 235 | g_autoptr(FuDevice) device_old = fu_device_list_get_old (self->device_list, device); |
Richard Hughes | fbcebe0 | 2017-12-11 16:37:19 +0000 | [diff] [blame] | 236 | if (device_old != NULL) { |
| 237 | g_signal_handlers_disconnect_by_func (device_old, |
| 238 | fu_engine_progress_notify_cb, |
| 239 | self); |
| 240 | g_signal_handlers_disconnect_by_func (device_old, |
| 241 | fu_engine_status_notify_cb, |
| 242 | self); |
| 243 | } |
Richard Hughes | 4a03601 | 2017-11-30 16:33:24 +0000 | [diff] [blame] | 244 | g_signal_connect (device, "notify::progress", |
| 245 | G_CALLBACK (fu_engine_progress_notify_cb), self); |
| 246 | g_signal_connect (device, "notify::status", |
| 247 | G_CALLBACK (fu_engine_status_notify_cb), self); |
Richard Hughes | fbcebe0 | 2017-12-11 16:37:19 +0000 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | static void |
| 251 | fu_engine_device_added_cb (FuDeviceList *device_list, FuDevice *device, FuEngine *self) |
| 252 | { |
| 253 | fu_engine_watch_device (self, device); |
Richard Hughes | 4a03601 | 2017-11-30 16:33:24 +0000 | [diff] [blame] | 254 | g_signal_emit (self, signals[SIGNAL_DEVICE_ADDED], 0, device); |
| 255 | } |
| 256 | |
| 257 | static void |
Mario Limonciello | e260ead | 2018-09-01 09:19:24 -0500 | [diff] [blame] | 258 | fu_engine_device_runner_device_removed (FuEngine *self, FuDevice *device) |
| 259 | { |
| 260 | GPtrArray *plugins = fu_plugin_list_get_all (self->plugin_list); |
| 261 | for (guint j = 0; j < plugins->len; j++) { |
| 262 | FuPlugin *plugin_tmp = g_ptr_array_index (plugins, j); |
| 263 | fu_plugin_runner_device_removed (plugin_tmp, device); |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | static void |
Richard Hughes | 4a03601 | 2017-11-30 16:33:24 +0000 | [diff] [blame] | 268 | fu_engine_device_removed_cb (FuDeviceList *device_list, FuDevice *device, FuEngine *self) |
| 269 | { |
Mario Limonciello | e260ead | 2018-09-01 09:19:24 -0500 | [diff] [blame] | 270 | fu_engine_device_runner_device_removed (self, device); |
Richard Hughes | 4a03601 | 2017-11-30 16:33:24 +0000 | [diff] [blame] | 271 | g_signal_handlers_disconnect_by_data (device, self); |
| 272 | g_signal_emit (self, signals[SIGNAL_DEVICE_REMOVED], 0, device); |
| 273 | } |
| 274 | |
| 275 | static void |
| 276 | fu_engine_device_changed_cb (FuDeviceList *device_list, FuDevice *device, FuEngine *self) |
| 277 | { |
Richard Hughes | fbcebe0 | 2017-12-11 16:37:19 +0000 | [diff] [blame] | 278 | fu_engine_watch_device (self, device); |
Richard Hughes | 4a03601 | 2017-11-30 16:33:24 +0000 | [diff] [blame] | 279 | fu_engine_emit_device_changed (self, device); |
| 280 | } |
| 281 | |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 282 | /* convert hex and decimal versions to dotted style */ |
| 283 | static gchar * |
Richard Hughes | 2c40b37 | 2019-04-17 13:41:47 +0100 | [diff] [blame] | 284 | fu_engine_get_release_version (FuEngine *self, FuDevice *dev, XbNode *rel, GError **error) |
Richard Hughes | 611f1a9 | 2018-01-11 11:54:28 +0000 | [diff] [blame] | 285 | { |
Mario Limonciello | f675c21 | 2020-02-25 11:12:35 -0600 | [diff] [blame] | 286 | FwupdVersionFormat fmt = fu_device_get_version_format (dev); |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 287 | const gchar *version; |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 288 | guint64 ver_uint32; |
| 289 | |
| 290 | /* get version */ |
| 291 | version = xb_node_get_attr (rel, "version"); |
Richard Hughes | 0b3e9fd | 2019-04-08 11:13:20 +0100 | [diff] [blame] | 292 | if (version == NULL) { |
| 293 | g_set_error_literal (error, |
| 294 | FWUPD_ERROR, |
| 295 | FWUPD_ERROR_NOT_SUPPORTED, |
| 296 | "version unset"); |
Richard Hughes | 611f1a9 | 2018-01-11 11:54:28 +0000 | [diff] [blame] | 297 | return NULL; |
Richard Hughes | 0b3e9fd | 2019-04-08 11:13:20 +0100 | [diff] [blame] | 298 | } |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 299 | |
| 300 | /* already dotted notation */ |
| 301 | if (g_strstr_len (version, -1, ".") != NULL) |
| 302 | return g_strdup (version); |
| 303 | |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 304 | /* don't touch my version! */ |
Richard Hughes | c84b36c | 2019-04-27 09:24:42 +0100 | [diff] [blame] | 305 | if (fmt == FWUPD_VERSION_FORMAT_PLAIN) |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 306 | return g_strdup (version); |
| 307 | |
| 308 | /* parse as integer */ |
| 309 | ver_uint32 = fu_common_strtoull (version); |
Mario Limonciello | f675c21 | 2020-02-25 11:12:35 -0600 | [diff] [blame] | 310 | if (fmt == FWUPD_VERSION_FORMAT_UNKNOWN || |
| 311 | ver_uint32 == 0 || ver_uint32 > G_MAXUINT32) |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 312 | return g_strdup (version); |
| 313 | |
| 314 | /* convert to dotted decimal */ |
| 315 | return fu_common_version_from_uint32 ((guint32) ver_uint32, fmt); |
Richard Hughes | 611f1a9 | 2018-01-11 11:54:28 +0000 | [diff] [blame] | 316 | } |
| 317 | |
Richard Hughes | 0b3e9fd | 2019-04-08 11:13:20 +0100 | [diff] [blame] | 318 | static gboolean |
Richard Hughes | bd4d285 | 2017-09-13 14:05:14 +0100 | [diff] [blame] | 319 | fu_engine_set_release_from_appstream (FuEngine *self, |
Richard Hughes | 2c40b37 | 2019-04-17 13:41:47 +0100 | [diff] [blame] | 320 | FuDevice *dev, |
Richard Hughes | bd4d285 | 2017-09-13 14:05:14 +0100 | [diff] [blame] | 321 | FwupdRelease *rel, |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 322 | XbNode *component, |
Richard Hughes | 0b3e9fd | 2019-04-08 11:13:20 +0100 | [diff] [blame] | 323 | XbNode *release, |
| 324 | GError **error) |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 325 | { |
Richard Hughes | c6afb51 | 2017-08-22 10:22:20 +0100 | [diff] [blame] | 326 | FwupdRemote *remote = NULL; |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 327 | const gchar *tmp; |
Richard Hughes | 611f1a9 | 2018-01-11 11:54:28 +0000 | [diff] [blame] | 328 | const gchar *remote_id; |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 329 | guint64 tmp64; |
| 330 | g_autofree gchar *version_rel = NULL; |
Richard Hughes | 02ac92c | 2019-03-29 17:56:46 +0000 | [diff] [blame] | 331 | g_autoptr(GPtrArray) cats = NULL; |
Richard Hughes | 0ad59cb | 2019-09-16 10:33:05 +0100 | [diff] [blame] | 332 | g_autoptr(GPtrArray) issues = NULL; |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 333 | g_autoptr(XbNode) description = NULL; |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 334 | |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 335 | /* set from the component */ |
| 336 | tmp = xb_node_query_text (component, "id", NULL); |
| 337 | if (tmp != NULL) |
| 338 | fwupd_release_set_appstream_id (rel, tmp); |
| 339 | tmp = xb_node_query_text (component, "url[@type='homepage']", NULL); |
| 340 | if (tmp != NULL) |
| 341 | fwupd_release_set_homepage (rel, tmp); |
| 342 | tmp = xb_node_query_text (component, "project_license", NULL); |
| 343 | if (tmp != NULL) |
| 344 | fwupd_release_set_license (rel, tmp); |
| 345 | tmp = xb_node_query_text (component, "name", NULL); |
| 346 | if (tmp != NULL) |
| 347 | fwupd_release_set_name (rel, tmp); |
| 348 | tmp = xb_node_query_text (component, "summary", NULL); |
| 349 | if (tmp != NULL) |
| 350 | fwupd_release_set_summary (rel, tmp); |
| 351 | tmp = xb_node_query_text (component, "developer_name", NULL); |
| 352 | if (tmp != NULL) |
| 353 | fwupd_release_set_vendor (rel, tmp); |
| 354 | |
Mario Limonciello | 92ff9c7 | 2020-03-09 16:54:56 -0500 | [diff] [blame] | 355 | /* refresh the device and release to the new version format too */ |
| 356 | fu_engine_md_refresh_device_from_component (self, dev, component); |
| 357 | |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 358 | /* the version is fixed up at runtime */ |
Richard Hughes | 2c40b37 | 2019-04-17 13:41:47 +0100 | [diff] [blame] | 359 | version_rel = fu_engine_get_release_version (self, dev, release, error); |
Richard Hughes | 0b3e9fd | 2019-04-08 11:13:20 +0100 | [diff] [blame] | 360 | if (version_rel == NULL) |
| 361 | return FALSE; |
| 362 | fwupd_release_set_version (rel, version_rel); |
Richard Hughes | 74fa2ca | 2018-01-10 21:33:39 +0000 | [diff] [blame] | 363 | |
Richard Hughes | c6afb51 | 2017-08-22 10:22:20 +0100 | [diff] [blame] | 364 | /* find the remote */ |
Richard Hughes | 33171fd | 2018-11-09 13:29:11 +0000 | [diff] [blame] | 365 | remote_id = xb_node_query_text (component, "../custom/value[@key='fwupd::RemoteId']", NULL); |
Richard Hughes | 611f1a9 | 2018-01-11 11:54:28 +0000 | [diff] [blame] | 366 | if (remote_id != NULL) { |
| 367 | fwupd_release_set_remote_id (rel, remote_id); |
Richard Hughes | d1808aa | 2019-12-10 15:20:30 +0000 | [diff] [blame] | 368 | remote = fu_remote_list_get_by_id (self->remote_list, remote_id); |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 369 | if (remote == NULL) |
| 370 | g_warning ("no remote found for release %s", version_rel); |
Richard Hughes | bd4d285 | 2017-09-13 14:05:14 +0100 | [diff] [blame] | 371 | } |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 372 | description = xb_node_query_first (release, "description", NULL); |
| 373 | if (description != NULL) { |
| 374 | g_autofree gchar *xml = NULL; |
| 375 | xml = xb_node_export (description, XB_NODE_EXPORT_FLAG_ONLY_CHILDREN, NULL); |
| 376 | if (xml != NULL) |
| 377 | fwupd_release_set_description (rel, xml); |
| 378 | } |
| 379 | tmp = xb_node_query_text (release, "location", NULL); |
Richard Hughes | c6afb51 | 2017-08-22 10:22:20 +0100 | [diff] [blame] | 380 | if (tmp != NULL) { |
| 381 | g_autofree gchar *uri = NULL; |
| 382 | if (remote != NULL) |
| 383 | uri = fwupd_remote_build_firmware_uri (remote, tmp, NULL); |
| 384 | if (uri == NULL) |
| 385 | uri = g_strdup (tmp); |
| 386 | fwupd_release_set_uri (rel, uri); |
Mario Limonciello | 4f24d0b | 2019-01-26 01:19:59 -0600 | [diff] [blame] | 387 | } else if (remote != NULL && |
| 388 | fwupd_remote_get_kind (remote) == FWUPD_REMOTE_KIND_DIRECTORY) { |
| 389 | g_autofree gchar *uri = NULL; |
| 390 | tmp = xb_node_query_text (component, "../custom/value[@key='fwupd::FilenameCache']", NULL); |
| 391 | if (tmp != NULL) { |
| 392 | uri = g_strdup_printf ("file://%s", tmp); |
| 393 | fwupd_release_set_uri (rel, uri); |
| 394 | } |
Richard Hughes | c6afb51 | 2017-08-22 10:22:20 +0100 | [diff] [blame] | 395 | } |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 396 | tmp = xb_node_query_text (release, "checksum[@target='content']", NULL); |
| 397 | if (tmp != NULL) |
| 398 | fwupd_release_set_filename (rel, tmp); |
Richard Hughes | 7185828 | 2019-01-26 12:15:55 +0000 | [diff] [blame] | 399 | tmp = xb_node_query_text (release, "url[@type='details']", NULL); |
| 400 | if (tmp != NULL) |
| 401 | fwupd_release_set_details_url (rel, tmp); |
| 402 | tmp = xb_node_query_text (release, "url[@type='source']", NULL); |
| 403 | if (tmp != NULL) |
| 404 | fwupd_release_set_source_url (rel, tmp); |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 405 | tmp = xb_node_query_text (release, "checksum[@target='container']", NULL); |
| 406 | if (tmp != NULL) |
| 407 | fwupd_release_add_checksum (rel, tmp); |
| 408 | tmp64 = xb_node_query_text_as_uint (release, "size[@type='installed']", NULL); |
| 409 | if (tmp64 != G_MAXUINT64) { |
| 410 | fwupd_release_set_size (rel, tmp64); |
| 411 | } else { |
| 412 | GBytes *sz = xb_node_get_data (release, "fwupd::ReleaseSize"); |
| 413 | if (sz != NULL) { |
| 414 | const guint64 *sizeptr = g_bytes_get_data (sz, NULL); |
| 415 | fwupd_release_set_size (rel, *sizeptr); |
| 416 | } |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 417 | } |
Richard Hughes | 52c1a4d | 2020-04-02 11:21:06 +0100 | [diff] [blame] | 418 | tmp = xb_node_get_attr (release, "urgency"); |
| 419 | if (tmp != NULL) |
| 420 | fwupd_release_set_urgency (rel, fwupd_release_urgency_from_string (tmp)); |
Richard Hughes | 6e0c8f8 | 2018-11-11 21:46:41 +0000 | [diff] [blame] | 421 | tmp64 = xb_node_get_attr_as_uint (release, "install_duration"); |
Richard Hughes | 319dbcb | 2018-12-18 17:59:05 +0000 | [diff] [blame] | 422 | if (tmp64 != G_MAXUINT64) |
Richard Hughes | 6e0c8f8 | 2018-11-11 21:46:41 +0000 | [diff] [blame] | 423 | fwupd_release_set_install_duration (rel, tmp64); |
Richard Hughes | 14797f8 | 2020-04-02 10:52:04 +0100 | [diff] [blame] | 424 | tmp64 = xb_node_get_attr_as_uint (release, "timestamp"); |
| 425 | if (tmp64 != G_MAXUINT64) |
| 426 | fwupd_release_set_created (rel, tmp64); |
Richard Hughes | 02ac92c | 2019-03-29 17:56:46 +0000 | [diff] [blame] | 427 | cats = xb_node_query (component, "categories/category", 0, NULL); |
| 428 | if (cats != NULL) { |
| 429 | for (guint i = 0; i < cats->len; i++) { |
| 430 | XbNode *n = g_ptr_array_index (cats, i); |
| 431 | fwupd_release_add_category (rel, xb_node_get_text (n)); |
| 432 | } |
| 433 | } |
Richard Hughes | 0ad59cb | 2019-09-16 10:33:05 +0100 | [diff] [blame] | 434 | issues = xb_node_query (component, "issues/issue", 0, NULL); |
| 435 | if (issues != NULL) { |
| 436 | for (guint i = 0; i < issues->len; i++) { |
| 437 | XbNode *n = g_ptr_array_index (issues, i); |
| 438 | fwupd_release_add_issue (rel, xb_node_get_text (n)); |
| 439 | } |
| 440 | } |
Richard Hughes | 868db4e | 2019-09-26 14:56:57 +0100 | [diff] [blame] | 441 | tmp = xb_node_query_text (component, "screenshots/screenshot/caption", NULL); |
| 442 | if (tmp != NULL) |
| 443 | fwupd_release_set_detach_caption (rel, tmp); |
| 444 | tmp = xb_node_query_text (component, "screenshots/screenshot/image", NULL); |
| 445 | if (tmp != NULL) |
| 446 | fwupd_release_set_detach_image (rel, tmp); |
Richard Hughes | adeb2b1 | 2018-12-14 11:56:41 +0000 | [diff] [blame] | 447 | tmp = xb_node_query_text (component, "custom/value[@key='LVFS::UpdateProtocol']", NULL); |
| 448 | if (tmp != NULL) |
| 449 | fwupd_release_set_protocol (rel, tmp); |
Mario Limonciello | 32241f4 | 2019-01-24 10:12:41 -0600 | [diff] [blame] | 450 | tmp = xb_node_query_text (component, "custom/value[@key='LVFS::UpdateMessage']", NULL); |
| 451 | if (tmp != NULL) |
| 452 | fwupd_release_set_update_message (rel, tmp); |
Richard Hughes | 0b3e9fd | 2019-04-08 11:13:20 +0100 | [diff] [blame] | 453 | return TRUE; |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 454 | } |
| 455 | |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 456 | /* finds the remote-id for the first firmware in the silo that matches this |
Richard Hughes | 534255c | 2018-01-28 19:51:56 +0000 | [diff] [blame] | 457 | * container checksum */ |
| 458 | static const gchar * |
| 459 | fu_engine_get_remote_id_for_checksum (FuEngine *self, const gchar *csum) |
| 460 | { |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 461 | g_autofree gchar *xpath = NULL; |
| 462 | g_autoptr(XbNode) key = NULL; |
Richard Hughes | 33171fd | 2018-11-09 13:29:11 +0000 | [diff] [blame] | 463 | xpath = g_strdup_printf ("components/component/releases/release/" |
| 464 | "checksum[@target='container'][text()='%s']/../../" |
| 465 | "../../custom/value[@key='fwupd::RemoteId']", csum); |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 466 | key = xb_silo_query_first (self->silo, xpath, NULL); |
| 467 | if (key == NULL) |
| 468 | return NULL; |
| 469 | return xb_node_get_text (key); |
Richard Hughes | 534255c | 2018-01-28 19:51:56 +0000 | [diff] [blame] | 470 | } |
| 471 | |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 472 | /** |
| 473 | * fu_engine_unlock: |
| 474 | * @self: A #FuEngine |
| 475 | * @device_id: A device ID |
| 476 | * @error: A #GError, or %NULL |
| 477 | * |
| 478 | * Unlocks a device. |
| 479 | * |
| 480 | * Returns: %TRUE for success |
| 481 | **/ |
| 482 | gboolean |
| 483 | fu_engine_unlock (FuEngine *self, const gchar *device_id, GError **error) |
| 484 | { |
Richard Hughes | 3483410 | 2017-11-21 21:55:00 +0000 | [diff] [blame] | 485 | FuPlugin *plugin; |
Richard Hughes | 5a9a6bd | 2018-09-10 10:02:20 +0100 | [diff] [blame] | 486 | g_autoptr(FuDevice) device = NULL; |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 487 | |
| 488 | g_return_val_if_fail (FU_IS_ENGINE (self), FALSE); |
| 489 | g_return_val_if_fail (device_id != NULL, FALSE); |
| 490 | g_return_val_if_fail (error == NULL || *error == NULL, FALSE); |
| 491 | |
| 492 | /* check the device exists */ |
Richard Hughes | 4012754 | 2018-01-12 20:25:55 +0000 | [diff] [blame] | 493 | device = fu_device_list_get_by_id (self->device_list, device_id, error); |
Richard Hughes | 0a7e783 | 2017-11-22 11:01:13 +0000 | [diff] [blame] | 494 | if (device == NULL) |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 495 | return FALSE; |
| 496 | |
Richard Hughes | 3483410 | 2017-11-21 21:55:00 +0000 | [diff] [blame] | 497 | /* get the plugin */ |
Richard Hughes | e7e9545 | 2017-11-22 09:05:53 +0000 | [diff] [blame] | 498 | plugin = fu_plugin_list_find_by_name (self->plugin_list, |
Richard Hughes | 0a7e783 | 2017-11-22 11:01:13 +0000 | [diff] [blame] | 499 | fu_device_get_plugin (device), |
Richard Hughes | e7e9545 | 2017-11-22 09:05:53 +0000 | [diff] [blame] | 500 | error); |
Richard Hughes | 3483410 | 2017-11-21 21:55:00 +0000 | [diff] [blame] | 501 | if (plugin == NULL) |
| 502 | return FALSE; |
| 503 | |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 504 | /* run the correct plugin that added this */ |
Richard Hughes | 0a7e783 | 2017-11-22 11:01:13 +0000 | [diff] [blame] | 505 | if (!fu_plugin_runner_unlock (plugin, device, error)) |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 506 | return FALSE; |
| 507 | |
| 508 | /* make the UI update */ |
Richard Hughes | 0a7e783 | 2017-11-22 11:01:13 +0000 | [diff] [blame] | 509 | fu_engine_emit_device_changed (self, device); |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 510 | fu_engine_emit_changed (self); |
| 511 | return TRUE; |
| 512 | } |
| 513 | |
Mario Limonciello | bfcf75b | 2019-04-17 15:05:39 +0100 | [diff] [blame] | 514 | gboolean |
| 515 | fu_engine_modify_config (FuEngine *self, const gchar *key, const gchar *value, GError **error) |
| 516 | { |
| 517 | const gchar *keys[] = { |
| 518 | "ArchiveSizeMax", |
| 519 | "BlacklistDevices", |
| 520 | "BlacklistPlugins", |
| 521 | "IdleTimeout", |
Mario Limonciello | 38027e6 | 2019-04-17 15:16:07 +0100 | [diff] [blame] | 522 | "VerboseDomains", |
Mario Limonciello | d81ea2e | 2020-01-13 14:11:43 -0600 | [diff] [blame] | 523 | "UpdateMotd", |
Mario Limonciello | 4fa95a7 | 2020-03-28 10:50:57 -0500 | [diff] [blame] | 524 | "EnumerateAllDevices", |
Mario Limonciello | bfcf75b | 2019-04-17 15:05:39 +0100 | [diff] [blame] | 525 | NULL }; |
| 526 | |
| 527 | g_return_val_if_fail (FU_IS_ENGINE (self), FALSE); |
| 528 | g_return_val_if_fail (key != NULL, FALSE); |
| 529 | g_return_val_if_fail (value != NULL, FALSE); |
| 530 | g_return_val_if_fail (error == NULL || *error == NULL, FALSE); |
| 531 | |
| 532 | /* check keys are valid */ |
| 533 | if (!g_strv_contains (keys, key)) { |
| 534 | g_set_error (error, |
| 535 | FWUPD_ERROR, |
| 536 | FWUPD_ERROR_NOT_FOUND, |
| 537 | "key %s not supported", key); |
| 538 | return FALSE; |
| 539 | } |
| 540 | |
| 541 | /* modify, effective next reboot */ |
Richard Hughes | d1808aa | 2019-12-10 15:20:30 +0000 | [diff] [blame] | 542 | return fu_config_set_key_value (self->config, key, value, error); |
Mario Limonciello | bfcf75b | 2019-04-17 15:05:39 +0100 | [diff] [blame] | 543 | } |
| 544 | |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 545 | /** |
Richard Hughes | a6bd558 | 2017-09-07 14:32:22 +0100 | [diff] [blame] | 546 | * fu_engine_modify_remote: |
| 547 | * @self: A #FuEngine |
| 548 | * @remote_id: A remote ID |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 549 | * @key: the key, e.g. `Enabled` |
| 550 | * @value: the key, e.g. `true` |
Richard Hughes | a6bd558 | 2017-09-07 14:32:22 +0100 | [diff] [blame] | 551 | * @error: A #GError, or %NULL |
| 552 | * |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 553 | * Updates the verification silo entry for a specific device. |
Richard Hughes | a6bd558 | 2017-09-07 14:32:22 +0100 | [diff] [blame] | 554 | * |
| 555 | * Returns: %TRUE for success |
| 556 | **/ |
| 557 | gboolean |
| 558 | fu_engine_modify_remote (FuEngine *self, |
| 559 | const gchar *remote_id, |
| 560 | const gchar *key, |
| 561 | const gchar *value, |
| 562 | GError **error) |
| 563 | { |
Richard Hughes | 9bc9deb | 2020-05-19 19:49:51 +0100 | [diff] [blame] | 564 | const gchar *keys[] = { |
| 565 | "AutomaticReports", |
| 566 | "AutomaticSecurityReports", |
| 567 | "Enabled", |
| 568 | "FirmwareBaseURI", |
| 569 | "MetadataURI", |
| 570 | "ReportURI", |
| 571 | "SecurityReportURI", |
| 572 | NULL, |
| 573 | }; |
Richard Hughes | a6bd558 | 2017-09-07 14:32:22 +0100 | [diff] [blame] | 574 | |
| 575 | /* check keys are valid */ |
| 576 | if (!g_strv_contains (keys, key)) { |
| 577 | g_set_error (error, |
| 578 | FWUPD_ERROR, |
| 579 | FWUPD_ERROR_NOT_FOUND, |
| 580 | "key %s not supported", key); |
| 581 | return FALSE; |
| 582 | } |
Richard Hughes | d1808aa | 2019-12-10 15:20:30 +0000 | [diff] [blame] | 583 | return fu_remote_list_set_key_value (self->remote_list, remote_id, key, value, error); |
Richard Hughes | a6bd558 | 2017-09-07 14:32:22 +0100 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | /** |
Richard Hughes | 6b22295 | 2018-01-11 10:20:48 +0000 | [diff] [blame] | 587 | * fu_engine_modify_device: |
| 588 | * @self: A #FuEngine |
| 589 | * @device_id: A device ID |
| 590 | * @key: the key, e.g. `Flags` |
| 591 | * @value: the key, e.g. `reported` |
| 592 | * @error: A #GError, or %NULL |
| 593 | * |
| 594 | * Sets the reported flag for a specific device. This ensures that other |
| 595 | * front-end clients for fwupd do not report the same event. |
| 596 | * |
| 597 | * Returns: %TRUE for success |
| 598 | **/ |
| 599 | gboolean |
| 600 | fu_engine_modify_device (FuEngine *self, |
| 601 | const gchar *device_id, |
| 602 | const gchar *key, |
| 603 | const gchar *value, |
| 604 | GError **error) |
| 605 | { |
| 606 | g_autoptr(FuDevice) device = NULL; |
| 607 | |
| 608 | /* find the correct device */ |
Richard Hughes | 0b9d996 | 2018-01-12 16:31:28 +0000 | [diff] [blame] | 609 | device = fu_history_get_device_by_id (self->history, device_id, error); |
Richard Hughes | 6b22295 | 2018-01-11 10:20:48 +0000 | [diff] [blame] | 610 | if (device == NULL) |
| 611 | return FALSE; |
| 612 | |
| 613 | /* support adding a subset of the device flags */ |
| 614 | if (g_strcmp0 (key, "Flags") == 0) { |
| 615 | FwupdDeviceFlags flag = fwupd_device_flag_from_string (value); |
| 616 | if (flag == FWUPD_DEVICE_FLAG_UNKNOWN) { |
| 617 | g_set_error (error, |
| 618 | FWUPD_ERROR, |
| 619 | FWUPD_ERROR_NOT_SUPPORTED, |
| 620 | "key %s not a valid flag", key); |
| 621 | return FALSE; |
| 622 | } |
Richard Hughes | ad54f65 | 2018-01-30 17:22:37 +0000 | [diff] [blame] | 623 | if (flag != FWUPD_DEVICE_FLAG_REPORTED && |
| 624 | flag != FWUPD_DEVICE_FLAG_NOTIFIED) { |
Richard Hughes | 6b22295 | 2018-01-11 10:20:48 +0000 | [diff] [blame] | 625 | g_set_error (error, |
| 626 | FWUPD_ERROR, |
| 627 | FWUPD_ERROR_NOT_SUPPORTED, |
| 628 | "flag %s cannot be set from client", key); |
| 629 | return FALSE; |
| 630 | } |
Richard Hughes | c0cd023 | 2018-01-31 15:02:00 +0000 | [diff] [blame] | 631 | fu_device_add_flag (device, flag); |
Richard Hughes | 0bbef29 | 2019-11-01 12:15:15 +0000 | [diff] [blame] | 632 | return fu_history_modify_device (self->history, device, error); |
Richard Hughes | 6b22295 | 2018-01-11 10:20:48 +0000 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | /* others invalid */ |
| 636 | g_set_error (error, |
| 637 | FWUPD_ERROR, |
| 638 | FWUPD_ERROR_NOT_SUPPORTED, |
| 639 | "key %s not supported", key); |
| 640 | return FALSE; |
| 641 | } |
| 642 | |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 643 | static const gchar * |
| 644 | fu_engine_checksum_type_to_string (GChecksumType checksum_type) |
| 645 | { |
| 646 | if (checksum_type == G_CHECKSUM_SHA1) |
| 647 | return "sha1"; |
| 648 | if (checksum_type == G_CHECKSUM_SHA256) |
| 649 | return "sha256"; |
| 650 | if (checksum_type == G_CHECKSUM_SHA512) |
| 651 | return "sha512"; |
| 652 | return "sha1"; |
| 653 | } |
| 654 | |
Richard Hughes | 6b22295 | 2018-01-11 10:20:48 +0000 | [diff] [blame] | 655 | /** |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 656 | * fu_engine_verify_update: |
| 657 | * @self: A #FuEngine |
| 658 | * @device_id: A device ID |
| 659 | * @error: A #GError, or %NULL |
| 660 | * |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 661 | * Updates the verification silo entry for a specific device. |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 662 | * |
| 663 | * Returns: %TRUE for success |
| 664 | **/ |
| 665 | gboolean |
| 666 | fu_engine_verify_update (FuEngine *self, const gchar *device_id, GError **error) |
| 667 | { |
Richard Hughes | 3483410 | 2017-11-21 21:55:00 +0000 | [diff] [blame] | 668 | FuPlugin *plugin; |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 669 | GPtrArray *checksums; |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 670 | GPtrArray *guids; |
| 671 | g_autofree gchar *fn = NULL; |
| 672 | g_autofree gchar *localstatedir = NULL; |
Richard Hughes | 5a9a6bd | 2018-09-10 10:02:20 +0100 | [diff] [blame] | 673 | g_autoptr(FuDevice) device = NULL; |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 674 | g_autoptr(GFile) file = NULL; |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 675 | g_autoptr(XbBuilder) builder = xb_builder_new (); |
| 676 | g_autoptr(XbBuilderNode) component = NULL; |
| 677 | g_autoptr(XbBuilderNode) provides = NULL; |
| 678 | g_autoptr(XbBuilderNode) release = NULL; |
| 679 | g_autoptr(XbBuilderNode) releases = NULL; |
| 680 | g_autoptr(XbSilo) silo = NULL; |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 681 | |
| 682 | g_return_val_if_fail (FU_IS_ENGINE (self), FALSE); |
| 683 | g_return_val_if_fail (device_id != NULL, FALSE); |
| 684 | g_return_val_if_fail (error == NULL || *error == NULL, FALSE); |
| 685 | |
| 686 | /* check the devices still exists */ |
Richard Hughes | 4012754 | 2018-01-12 20:25:55 +0000 | [diff] [blame] | 687 | device = fu_device_list_get_by_id (self->device_list, device_id, error); |
Richard Hughes | 0a7e783 | 2017-11-22 11:01:13 +0000 | [diff] [blame] | 688 | if (device == NULL) |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 689 | return FALSE; |
| 690 | |
Richard Hughes | 3483410 | 2017-11-21 21:55:00 +0000 | [diff] [blame] | 691 | /* get the plugin */ |
Richard Hughes | e7e9545 | 2017-11-22 09:05:53 +0000 | [diff] [blame] | 692 | plugin = fu_plugin_list_find_by_name (self->plugin_list, |
Richard Hughes | 0a7e783 | 2017-11-22 11:01:13 +0000 | [diff] [blame] | 693 | fu_device_get_plugin (device), |
Richard Hughes | e7e9545 | 2017-11-22 09:05:53 +0000 | [diff] [blame] | 694 | error); |
Richard Hughes | 3483410 | 2017-11-21 21:55:00 +0000 | [diff] [blame] | 695 | if (plugin == NULL) |
| 696 | return FALSE; |
| 697 | |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 698 | /* get the checksum */ |
Richard Hughes | 0a7e783 | 2017-11-22 11:01:13 +0000 | [diff] [blame] | 699 | checksums = fu_device_get_checksums (device); |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 700 | if (checksums->len == 0) { |
Richard Hughes | 0a7e783 | 2017-11-22 11:01:13 +0000 | [diff] [blame] | 701 | if (!fu_plugin_runner_verify (plugin, device, |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 702 | FU_PLUGIN_VERIFY_FLAG_NONE, |
| 703 | error)) |
| 704 | return FALSE; |
Richard Hughes | 0a7e783 | 2017-11-22 11:01:13 +0000 | [diff] [blame] | 705 | fu_engine_emit_device_changed (self, device); |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 706 | } |
| 707 | |
| 708 | /* we got nothing */ |
| 709 | if (checksums->len == 0) { |
| 710 | g_set_error_literal (error, |
| 711 | FWUPD_ERROR, |
| 712 | FWUPD_ERROR_NOT_SUPPORTED, |
| 713 | "device verification not supported"); |
| 714 | return FALSE; |
| 715 | } |
| 716 | |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 717 | /* build XML */ |
| 718 | component = xb_builder_node_insert (NULL, "component", |
| 719 | "type", "firmware", |
| 720 | NULL); |
| 721 | provides = xb_builder_node_insert (component, "provides", NULL); |
| 722 | guids = fu_device_get_guids (device); |
| 723 | for (guint i = 0; i < guids->len; i++) { |
| 724 | const gchar *guid = g_ptr_array_index (guids, i); |
| 725 | g_autoptr(XbBuilderNode) provide = NULL; |
| 726 | provide = xb_builder_node_insert (provides, "firmware", |
| 727 | "type", "flashed", |
| 728 | NULL); |
| 729 | xb_builder_node_set_text (provide, guid, -1); |
| 730 | } |
| 731 | releases = xb_builder_node_insert (component, "releases", NULL); |
| 732 | release = xb_builder_node_insert (releases, "release", |
| 733 | "version", fu_device_get_version (device), |
| 734 | NULL); |
| 735 | for (guint i = 0; i < checksums->len; i++) { |
| 736 | const gchar *checksum = g_ptr_array_index (checksums, i); |
| 737 | GChecksumType kind = fwupd_checksum_guess_kind (checksum); |
| 738 | g_autoptr(XbBuilderNode) csum = NULL; |
Richard Hughes | aaa60c6 | 2018-11-07 11:05:50 +0000 | [diff] [blame] | 739 | csum = xb_builder_node_insert (release, "checksum", |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 740 | "type", fu_engine_checksum_type_to_string (kind), |
| 741 | "target", "content", |
| 742 | NULL); |
| 743 | xb_builder_node_set_text (csum, checksum, -1); |
| 744 | } |
| 745 | xb_builder_import_node (builder, component); |
| 746 | |
| 747 | /* save silo */ |
| 748 | localstatedir = fu_common_get_path (FU_PATH_KIND_LOCALSTATEDIR_PKG); |
| 749 | fn = g_strdup_printf ("%s/verify/%s.xml", localstatedir, device_id); |
Richard Hughes | 11f612c | 2019-03-15 16:27:18 +0000 | [diff] [blame] | 750 | if (!fu_common_mkdir_parent (fn, error)) |
| 751 | return FALSE; |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 752 | file = g_file_new_for_path (fn); |
| 753 | silo = xb_builder_compile (builder, XB_BUILDER_COMPILE_FLAG_NONE, NULL, error); |
| 754 | if (silo == NULL) |
| 755 | return FALSE; |
| 756 | if (!xb_silo_export_file (silo, file, |
| 757 | XB_NODE_EXPORT_FLAG_FORMAT_MULTILINE, |
| 758 | NULL, error)) |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 759 | return FALSE; |
| 760 | |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 761 | /* success */ |
| 762 | return TRUE; |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 763 | } |
| 764 | |
Mario Limonciello | 4f24d0b | 2019-01-26 01:19:59 -0600 | [diff] [blame] | 765 | XbNode * |
| 766 | fu_engine_get_component_by_guids (FuEngine *self, FuDevice *device) |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 767 | { |
| 768 | GPtrArray *guids = fu_device_get_guids (device); |
Richard Hughes | ab1bc89 | 2018-11-15 15:04:35 +0000 | [diff] [blame] | 769 | g_autoptr(GString) xpath = g_string_new (NULL); |
| 770 | g_autoptr(XbNode) component = NULL; |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 771 | for (guint i = 0; i < guids->len; i++) { |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 772 | const gchar *guid = g_ptr_array_index (guids, i); |
Richard Hughes | ab1bc89 | 2018-11-15 15:04:35 +0000 | [diff] [blame] | 773 | xb_string_append_union (xpath, |
| 774 | "components/component/" |
| 775 | "provides/firmware[@type='flashed'][text()='%s']/" |
| 776 | "../..", guid); |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 777 | } |
Mario Limonciello | 4f24d0b | 2019-01-26 01:19:59 -0600 | [diff] [blame] | 778 | component = xb_silo_query_first (self->silo, xpath->str, NULL); |
Richard Hughes | ab1bc89 | 2018-11-15 15:04:35 +0000 | [diff] [blame] | 779 | if (component != NULL) |
| 780 | return g_steal_pointer (&component); |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 781 | return NULL; |
| 782 | } |
| 783 | |
| 784 | /** |
| 785 | * fu_engine_verify: |
| 786 | * @self: A #FuEngine |
| 787 | * @device_id: A device ID |
| 788 | * @error: A #GError, or %NULL |
| 789 | * |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 790 | * Verifies a device firmware checksum using the verification silo entry. |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 791 | * |
| 792 | * Returns: %TRUE for success |
| 793 | **/ |
| 794 | gboolean |
| 795 | fu_engine_verify (FuEngine *self, const gchar *device_id, GError **error) |
| 796 | { |
Richard Hughes | 3483410 | 2017-11-21 21:55:00 +0000 | [diff] [blame] | 797 | FuPlugin *plugin; |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 798 | GPtrArray *checksums; |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 799 | const gchar *version; |
| 800 | g_autofree gchar *fn = NULL; |
| 801 | g_autofree gchar *localstatedir = NULL; |
Richard Hughes | 5a9a6bd | 2018-09-10 10:02:20 +0100 | [diff] [blame] | 802 | g_autoptr(FuDevice) device = NULL; |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 803 | g_autoptr(GFile) file = NULL; |
Richard Hughes | 45bbfc9 | 2018-12-12 10:57:08 +0000 | [diff] [blame] | 804 | g_autoptr(GString) xpath_csum = g_string_new (NULL); |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 805 | g_autoptr(XbNode) csum = NULL; |
| 806 | g_autoptr(XbNode) release = NULL; |
| 807 | g_autoptr(XbSilo) silo = xb_silo_new (); |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 808 | |
| 809 | g_return_val_if_fail (FU_IS_ENGINE (self), FALSE); |
| 810 | g_return_val_if_fail (device_id != NULL, FALSE); |
| 811 | g_return_val_if_fail (error == NULL || *error == NULL, FALSE); |
| 812 | |
| 813 | /* check the id exists */ |
Richard Hughes | 4012754 | 2018-01-12 20:25:55 +0000 | [diff] [blame] | 814 | device = fu_device_list_get_by_id (self->device_list, device_id, error); |
Richard Hughes | 0a7e783 | 2017-11-22 11:01:13 +0000 | [diff] [blame] | 815 | if (device == NULL) |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 816 | return FALSE; |
| 817 | |
Richard Hughes | 3483410 | 2017-11-21 21:55:00 +0000 | [diff] [blame] | 818 | /* get the plugin */ |
Richard Hughes | e7e9545 | 2017-11-22 09:05:53 +0000 | [diff] [blame] | 819 | plugin = fu_plugin_list_find_by_name (self->plugin_list, |
Richard Hughes | 0a7e783 | 2017-11-22 11:01:13 +0000 | [diff] [blame] | 820 | fu_device_get_plugin (device), |
Richard Hughes | e7e9545 | 2017-11-22 09:05:53 +0000 | [diff] [blame] | 821 | error); |
Richard Hughes | 3483410 | 2017-11-21 21:55:00 +0000 | [diff] [blame] | 822 | if (plugin == NULL) |
| 823 | return FALSE; |
| 824 | |
Mario Limonciello | 8fa0b38 | 2019-10-14 07:36:04 -0500 | [diff] [blame] | 825 | /* update the device firmware hashes if possible */ |
| 826 | if (fu_device_has_flag (device, FWUPD_DEVICE_FLAG_CAN_VERIFY_IMAGE)) { |
| 827 | if (!fu_plugin_runner_verify (plugin, device, |
| 828 | FU_PLUGIN_VERIFY_FLAG_NONE, error)) |
| 829 | return FALSE; |
| 830 | } |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 831 | |
| 832 | /* find component in metadata */ |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 833 | version = fu_device_get_version (device); |
| 834 | localstatedir = fu_common_get_path (FU_PATH_KIND_LOCALSTATEDIR_PKG); |
| 835 | fn = g_strdup_printf ("%s/verify/%s.xml", localstatedir, device_id); |
| 836 | file = g_file_new_for_path (fn); |
| 837 | if (g_file_query_exists (file, NULL)) { |
| 838 | g_autofree gchar *xpath = NULL; |
| 839 | g_autoptr(XbBuilder) builder = xb_builder_new (); |
| 840 | g_autoptr(XbBuilderSource) source = xb_builder_source_new (); |
| 841 | if (!xb_builder_source_load_file (source, file, |
| 842 | XB_BUILDER_SOURCE_FLAG_NONE, |
| 843 | NULL, error)) |
| 844 | return FALSE; |
| 845 | xb_builder_import_source (builder, source); |
| 846 | silo = xb_builder_compile (builder, |
| 847 | XB_BUILDER_COMPILE_FLAG_NONE, |
| 848 | NULL, error); |
| 849 | if (silo == NULL) |
| 850 | return FALSE; |
| 851 | xpath = g_strdup_printf ("component/releases/release[@version='%s']", version); |
| 852 | release = xb_silo_query_first (silo, xpath, NULL); |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 853 | } |
| 854 | |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 855 | /* try again with the system metadata */ |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 856 | if (release == NULL) { |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 857 | GPtrArray *guids = fu_device_get_guids (device); |
Mario Limonciello | 91d3609 | 2019-10-14 08:44:39 -0500 | [diff] [blame] | 858 | FwupdVersionFormat fmt = fu_device_get_version_format (device); |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 859 | for (guint i = 0; i < guids->len; i++) { |
| 860 | const gchar *guid = g_ptr_array_index (guids, i); |
| 861 | g_autofree gchar *xpath2 = NULL; |
Mario Limonciello | 91d3609 | 2019-10-14 08:44:39 -0500 | [diff] [blame] | 862 | g_autoptr(GPtrArray) releases = NULL; |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 863 | xpath2 = g_strdup_printf ("components/component/" |
| 864 | "provides/firmware[@type='flashed'][text()='%s']/" |
Mario Limonciello | 91d3609 | 2019-10-14 08:44:39 -0500 | [diff] [blame] | 865 | "../../releases/release", |
| 866 | guid); |
| 867 | releases = xb_silo_query (self->silo, xpath2, 0, error); |
| 868 | if (releases == NULL) |
| 869 | return FALSE; |
| 870 | for (guint j = 0; j < releases->len; j++) { |
| 871 | XbNode *rel = g_ptr_array_index (releases, j); |
| 872 | const gchar *rel_ver = xb_node_get_attr (rel, "version"); |
| 873 | g_autofree gchar *tmp_ver = fu_common_version_parse_from_format (rel_ver, fmt); |
Richard Hughes | 9a68084 | 2020-02-20 11:11:13 +0000 | [diff] [blame] | 874 | if (fu_common_vercmp_full (tmp_ver, version, fmt) == 0) { |
Mario Limonciello | 91d3609 | 2019-10-14 08:44:39 -0500 | [diff] [blame] | 875 | release = g_object_ref (rel); |
| 876 | break; |
| 877 | } |
| 878 | } |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 879 | if (release != NULL) |
| 880 | break; |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 881 | } |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 882 | } |
| 883 | if (release == NULL) { |
| 884 | g_set_error (error, |
| 885 | FWUPD_ERROR, |
| 886 | FWUPD_ERROR_NOT_FOUND, |
Mario Limonciello | 8fa0b38 | 2019-10-14 07:36:04 -0500 | [diff] [blame] | 887 | "No release found for version %s", version); |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 888 | return FALSE; |
| 889 | } |
| 890 | |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 891 | /* get the matching checksum */ |
Richard Hughes | 0a7e783 | 2017-11-22 11:01:13 +0000 | [diff] [blame] | 892 | checksums = fu_device_get_checksums (device); |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 893 | if (checksums->len == 0) { |
| 894 | g_set_error (error, |
| 895 | FWUPD_ERROR, |
| 896 | FWUPD_ERROR_NOT_FOUND, |
| 897 | "No device checksums for %s", version); |
| 898 | return FALSE; |
| 899 | } |
Richard Hughes | 45bbfc9 | 2018-12-12 10:57:08 +0000 | [diff] [blame] | 900 | |
| 901 | /* do any of the checksums in the release match any in the device */ |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 902 | for (guint j = 0; j < checksums->len; j++) { |
| 903 | const gchar *hash_tmp = g_ptr_array_index (checksums, j); |
Richard Hughes | 45bbfc9 | 2018-12-12 10:57:08 +0000 | [diff] [blame] | 904 | xb_string_append_union (xpath_csum, |
| 905 | "checksum[@target='device'][text()='%s']", |
| 906 | hash_tmp); |
| 907 | xb_string_append_union (xpath_csum, |
| 908 | "checksum[@target='content'][text()='%s']", |
| 909 | hash_tmp); |
| 910 | } |
| 911 | csum = xb_node_query_first (release, xpath_csum->str, NULL); |
| 912 | if (csum == NULL) { |
| 913 | g_autoptr(GString) checksums_device = g_string_new (NULL); |
| 914 | g_autoptr(GString) checksums_metadata = g_string_new (NULL); |
| 915 | g_autoptr(GPtrArray) csums = NULL; |
| 916 | g_autoptr(GString) xpath = g_string_new (NULL); |
| 917 | |
| 918 | /* get all checksums to display a useful error */ |
| 919 | xb_string_append_union (xpath, "checksum[@target='device']"); |
Mario Limonciello | 2a0e20b | 2019-10-14 12:09:35 -0500 | [diff] [blame] | 920 | if (fu_device_has_flag (device, FWUPD_DEVICE_FLAG_CAN_VERIFY_IMAGE)) |
| 921 | xb_string_append_union (xpath, "checksum[@target='content']"); |
Richard Hughes | 45bbfc9 | 2018-12-12 10:57:08 +0000 | [diff] [blame] | 922 | csums = xb_node_query (release, xpath->str, 0, NULL); |
| 923 | if (csums == NULL) { |
| 924 | g_set_error (error, |
| 925 | FWUPD_ERROR, |
| 926 | FWUPD_ERROR_NOT_FOUND, |
Mario Limonciello | 2a0e20b | 2019-10-14 12:09:35 -0500 | [diff] [blame] | 927 | "No stored checksums for %s", |
Richard Hughes | 45bbfc9 | 2018-12-12 10:57:08 +0000 | [diff] [blame] | 928 | version); |
| 929 | return FALSE; |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 930 | } |
Richard Hughes | 45bbfc9 | 2018-12-12 10:57:08 +0000 | [diff] [blame] | 931 | for (guint i = 0; i < csums->len; i++) { |
| 932 | XbNode *csum_tmp = g_ptr_array_index (csums, i); |
| 933 | xb_string_append_union (checksums_metadata, |
| 934 | "%s", xb_node_get_text (csum_tmp)); |
| 935 | } |
| 936 | for (guint i = 0; i < checksums->len; i++) { |
| 937 | const gchar *hash_tmp = g_ptr_array_index (checksums, i); |
| 938 | xb_string_append_union (checksums_device, "%s", hash_tmp); |
| 939 | } |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 940 | g_set_error (error, |
| 941 | FWUPD_ERROR, |
| 942 | FWUPD_ERROR_NOT_FOUND, |
Mario Limonciello | 2a0e20b | 2019-10-14 12:09:35 -0500 | [diff] [blame] | 943 | "For %s %s expected %s, got %s", |
| 944 | fu_device_get_name (device), |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 945 | version, |
Richard Hughes | 45bbfc9 | 2018-12-12 10:57:08 +0000 | [diff] [blame] | 946 | checksums_metadata->str, |
| 947 | checksums_device->str); |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 948 | return FALSE; |
| 949 | } |
| 950 | |
| 951 | /* success */ |
| 952 | return TRUE; |
| 953 | } |
| 954 | |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 955 | static gboolean |
Richard Hughes | 9a68084 | 2020-02-20 11:11:13 +0000 | [diff] [blame] | 956 | fu_engine_require_vercmp (XbNode *req, |
| 957 | const gchar *version, |
| 958 | FwupdVersionFormat fmt, |
| 959 | GError **error) |
Richard Hughes | 650dade | 2017-12-14 14:43:11 +0000 | [diff] [blame] | 960 | { |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 961 | gboolean ret = FALSE; |
| 962 | gint rc = 0; |
| 963 | const gchar *tmp = xb_node_get_attr (req, "compare"); |
| 964 | const gchar *version_req = xb_node_get_attr (req, "version"); |
| 965 | |
| 966 | if (g_strcmp0 (tmp, "eq") == 0) { |
Richard Hughes | 9a68084 | 2020-02-20 11:11:13 +0000 | [diff] [blame] | 967 | rc = fu_common_vercmp_full (version, version_req, fmt); |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 968 | ret = rc == 0; |
| 969 | } else if (g_strcmp0 (tmp, "ne") == 0) { |
Richard Hughes | 9a68084 | 2020-02-20 11:11:13 +0000 | [diff] [blame] | 970 | rc = fu_common_vercmp_full (version, version_req, fmt); |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 971 | ret = rc != 0; |
| 972 | } else if (g_strcmp0 (tmp, "lt") == 0) { |
Richard Hughes | 9a68084 | 2020-02-20 11:11:13 +0000 | [diff] [blame] | 973 | rc = fu_common_vercmp_full (version, version_req, fmt); |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 974 | ret = rc < 0; |
| 975 | } else if (g_strcmp0 (tmp, "gt") == 0) { |
Richard Hughes | 9a68084 | 2020-02-20 11:11:13 +0000 | [diff] [blame] | 976 | rc = fu_common_vercmp_full (version, version_req, fmt); |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 977 | ret = rc > 0; |
| 978 | } else if (g_strcmp0 (tmp, "le") == 0) { |
Richard Hughes | 9a68084 | 2020-02-20 11:11:13 +0000 | [diff] [blame] | 979 | rc = fu_common_vercmp_full (version, version_req, fmt); |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 980 | ret = rc <= 0; |
| 981 | } else if (g_strcmp0 (tmp, "ge") == 0) { |
Richard Hughes | 9a68084 | 2020-02-20 11:11:13 +0000 | [diff] [blame] | 982 | rc = fu_common_vercmp_full (version, version_req, fmt); |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 983 | ret = rc >= 0; |
| 984 | } else if (g_strcmp0 (tmp, "glob") == 0) { |
Richard Hughes | 5c508de | 2019-11-22 09:57:34 +0000 | [diff] [blame] | 985 | ret = fu_common_fnmatch (version_req, version); |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 986 | } else if (g_strcmp0 (tmp, "regex") == 0) { |
| 987 | ret = g_regex_match_simple (version_req, version, 0, 0); |
| 988 | } else { |
| 989 | g_set_error (error, |
| 990 | FWUPD_ERROR, |
| 991 | FWUPD_ERROR_NOT_SUPPORTED, |
| 992 | "failed to compare [%s] and [%s]", |
| 993 | version_req, |
| 994 | version); |
| 995 | return FALSE; |
Richard Hughes | 650dade | 2017-12-14 14:43:11 +0000 | [diff] [blame] | 996 | } |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 997 | |
| 998 | /* set error */ |
| 999 | if (!ret) { |
| 1000 | g_set_error (error, |
| 1001 | FWUPD_ERROR, |
| 1002 | FWUPD_ERROR_INTERNAL, |
| 1003 | "failed predicate [%s %s %s]", |
| 1004 | version_req, tmp, version); |
| 1005 | } |
| 1006 | return ret; |
Richard Hughes | 650dade | 2017-12-14 14:43:11 +0000 | [diff] [blame] | 1007 | } |
| 1008 | |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 1009 | static gboolean |
Richard Hughes | b62c3a4 | 2019-04-08 12:13:47 +0100 | [diff] [blame] | 1010 | fu_engine_check_requirement_not_child (FuEngine *self, XbNode *req, |
| 1011 | FuDevice *device, GError **error) |
| 1012 | { |
| 1013 | GPtrArray *children = fu_device_get_children (device); |
| 1014 | |
| 1015 | /* only <firmware> supported */ |
| 1016 | if (g_strcmp0 (xb_node_get_element (req), "firmware") != 0) { |
| 1017 | g_set_error (error, |
| 1018 | FWUPD_ERROR, |
| 1019 | FWUPD_ERROR_NOT_SUPPORTED, |
| 1020 | "cannot handle not-child %s requirement", |
| 1021 | xb_node_get_element (req)); |
| 1022 | return FALSE; |
| 1023 | } |
| 1024 | |
| 1025 | /* check each child */ |
| 1026 | for (guint i = 0; i < children->len; i++) { |
| 1027 | FuDevice *child = g_ptr_array_index (children, i); |
| 1028 | const gchar *version = fu_device_get_version (child); |
Richard Hughes | ec14e4b | 2019-11-01 12:07:10 +0000 | [diff] [blame] | 1029 | if (version == NULL) { |
| 1030 | g_set_error (error, |
| 1031 | FWUPD_ERROR, |
| 1032 | FWUPD_ERROR_NOT_SUPPORTED, |
| 1033 | "no version provided by %s, child of %s", |
| 1034 | fu_device_get_name (child), |
| 1035 | fu_device_get_name (device)); |
| 1036 | return FALSE; |
| 1037 | } |
Richard Hughes | 9a68084 | 2020-02-20 11:11:13 +0000 | [diff] [blame] | 1038 | if (fu_engine_require_vercmp (req, version, |
| 1039 | fu_device_get_version_format (child), |
| 1040 | NULL)) { |
Richard Hughes | b62c3a4 | 2019-04-08 12:13:47 +0100 | [diff] [blame] | 1041 | g_set_error (error, |
| 1042 | FWUPD_ERROR, |
| 1043 | FWUPD_ERROR_NOT_SUPPORTED, |
| 1044 | "Not compatible with child device version %s", |
| 1045 | version); |
| 1046 | return FALSE; |
| 1047 | } |
| 1048 | } |
| 1049 | return TRUE; |
| 1050 | } |
| 1051 | |
| 1052 | static gboolean |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 1053 | fu_engine_check_requirement_firmware (FuEngine *self, XbNode *req, |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 1054 | FuDevice *device, GError **error) |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 1055 | { |
Richard Hughes | f7006d2 | 2019-11-14 13:42:52 +0000 | [diff] [blame] | 1056 | guint64 depth; |
| 1057 | g_autoptr(FuDevice) device_actual = g_object_ref (device); |
Richard Hughes | 88adcbe | 2017-11-21 14:33:56 +0000 | [diff] [blame] | 1058 | g_autoptr(GError) error_local = NULL; |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 1059 | |
Richard Hughes | f7006d2 | 2019-11-14 13:42:52 +0000 | [diff] [blame] | 1060 | /* look at the parent device */ |
| 1061 | depth = xb_node_get_attr_as_uint (req, "depth"); |
| 1062 | if (depth != G_MAXUINT64) { |
| 1063 | for (guint64 i = 0; i < depth; i++) { |
| 1064 | FuDevice *device_tmp = fu_device_get_parent (device_actual); |
| 1065 | if (device_actual == NULL) { |
| 1066 | g_set_error (error, |
| 1067 | FWUPD_ERROR, |
| 1068 | FWUPD_ERROR_NOT_SUPPORTED, |
| 1069 | "No parent device for %s " |
| 1070 | "(%" G_GUINT64_FORMAT "/%" G_GUINT64_FORMAT ")", |
| 1071 | fu_device_get_name (device_actual), i, depth); |
| 1072 | return FALSE; |
| 1073 | } |
| 1074 | g_set_object (&device_actual, device_tmp); |
| 1075 | } |
| 1076 | } |
| 1077 | |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 1078 | /* old firmware version */ |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 1079 | if (xb_node_get_text (req) == NULL) { |
Richard Hughes | f7006d2 | 2019-11-14 13:42:52 +0000 | [diff] [blame] | 1080 | const gchar *version = fu_device_get_version (device_actual); |
Richard Hughes | 9a68084 | 2020-02-20 11:11:13 +0000 | [diff] [blame] | 1081 | if (!fu_engine_require_vercmp (req, version, |
| 1082 | fu_device_get_version_format (device_actual), |
| 1083 | &error_local)) { |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 1084 | if (g_strcmp0 (xb_node_get_attr (req, "compare"), "ge") == 0) { |
Richard Hughes | 88adcbe | 2017-11-21 14:33:56 +0000 | [diff] [blame] | 1085 | g_set_error (error, |
| 1086 | FWUPD_ERROR, |
| 1087 | FWUPD_ERROR_INVALID_FILE, |
| 1088 | "Not compatible with firmware version %s, requires >= %s", |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 1089 | version, xb_node_get_attr (req, "version")); |
Richard Hughes | 88adcbe | 2017-11-21 14:33:56 +0000 | [diff] [blame] | 1090 | } else { |
| 1091 | g_set_error (error, |
| 1092 | FWUPD_ERROR, |
| 1093 | FWUPD_ERROR_INVALID_FILE, |
| 1094 | "Not compatible with firmware version: %s", |
| 1095 | error_local->message); |
| 1096 | } |
| 1097 | return FALSE; |
| 1098 | } |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 1099 | return TRUE; |
| 1100 | } |
Richard Hughes | 88adcbe | 2017-11-21 14:33:56 +0000 | [diff] [blame] | 1101 | |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 1102 | /* bootloader version */ |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 1103 | if (g_strcmp0 (xb_node_get_text (req), "bootloader") == 0) { |
Richard Hughes | f7006d2 | 2019-11-14 13:42:52 +0000 | [diff] [blame] | 1104 | const gchar *version = fu_device_get_version_bootloader (device_actual); |
Richard Hughes | 9a68084 | 2020-02-20 11:11:13 +0000 | [diff] [blame] | 1105 | if (!fu_engine_require_vercmp (req, version, |
| 1106 | fu_device_get_version_format (device_actual), |
| 1107 | &error_local)) { |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 1108 | if (g_strcmp0 (xb_node_get_attr (req, "compare"), "ge") == 0) { |
Richard Hughes | 88adcbe | 2017-11-21 14:33:56 +0000 | [diff] [blame] | 1109 | g_set_error (error, |
| 1110 | FWUPD_ERROR, |
Mario Limonciello | c23e612 | 2019-12-12 14:30:27 -0600 | [diff] [blame] | 1111 | FWUPD_ERROR_NOT_SUPPORTED, |
Richard Hughes | 88adcbe | 2017-11-21 14:33:56 +0000 | [diff] [blame] | 1112 | "Not compatible with bootloader version %s, requires >= %s", |
Mario Limonciello | c23e612 | 2019-12-12 14:30:27 -0600 | [diff] [blame] | 1113 | version, xb_node_get_attr (req, "version")); |
| 1114 | |
Richard Hughes | 88adcbe | 2017-11-21 14:33:56 +0000 | [diff] [blame] | 1115 | } else { |
Mario Limonciello | c23e612 | 2019-12-12 14:30:27 -0600 | [diff] [blame] | 1116 | g_debug ("Bootloader is not compatible: %s", error_local->message); |
| 1117 | g_set_error_literal (error, |
| 1118 | FWUPD_ERROR, |
| 1119 | FWUPD_ERROR_NOT_SUPPORTED, |
| 1120 | "Bootloader is not compatible"); |
Richard Hughes | 88adcbe | 2017-11-21 14:33:56 +0000 | [diff] [blame] | 1121 | } |
| 1122 | return FALSE; |
| 1123 | } |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 1124 | return TRUE; |
| 1125 | } |
Richard Hughes | 88adcbe | 2017-11-21 14:33:56 +0000 | [diff] [blame] | 1126 | |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 1127 | /* vendor ID */ |
Richard Hughes | 12843af | 2019-12-09 10:30:19 +0000 | [diff] [blame] | 1128 | if (g_strcmp0 (xb_node_get_text (req), "vendor-id") == 0 && |
| 1129 | fu_device_get_vendor_id (device_actual) != NULL) { |
Richard Hughes | f7006d2 | 2019-11-14 13:42:52 +0000 | [diff] [blame] | 1130 | const gchar *version = fu_device_get_vendor_id (device_actual); |
Richard Hughes | 9a68084 | 2020-02-20 11:11:13 +0000 | [diff] [blame] | 1131 | if (!fu_engine_require_vercmp (req, version, |
| 1132 | fu_device_get_version_format (device_actual), |
| 1133 | &error_local)) { |
Richard Hughes | 3885789 | 2019-12-09 10:32:00 +0000 | [diff] [blame] | 1134 | g_set_error (error, |
| 1135 | FWUPD_ERROR, |
| 1136 | FWUPD_ERROR_INVALID_FILE, |
| 1137 | "Not compatible with vendor: %s", |
| 1138 | error_local->message); |
Richard Hughes | 88adcbe | 2017-11-21 14:33:56 +0000 | [diff] [blame] | 1139 | return FALSE; |
| 1140 | } |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 1141 | return TRUE; |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 1142 | } |
| 1143 | |
Richard Hughes | b62c3a4 | 2019-04-08 12:13:47 +0100 | [diff] [blame] | 1144 | /* child version */ |
| 1145 | if (g_strcmp0 (xb_node_get_text (req), "not-child") == 0) |
Richard Hughes | f7006d2 | 2019-11-14 13:42:52 +0000 | [diff] [blame] | 1146 | return fu_engine_check_requirement_not_child (self, req, device_actual, error); |
Richard Hughes | b62c3a4 | 2019-04-08 12:13:47 +0100 | [diff] [blame] | 1147 | |
Richard Hughes | 12c8499 | 2018-10-02 11:07:28 +0100 | [diff] [blame] | 1148 | /* another device */ |
Richard Hughes | 592baed | 2019-02-03 18:30:24 +0000 | [diff] [blame] | 1149 | if (fwupd_guid_is_valid (xb_node_get_text (req))) { |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 1150 | const gchar *guid = xb_node_get_text (req); |
Richard Hughes | 12c8499 | 2018-10-02 11:07:28 +0100 | [diff] [blame] | 1151 | const gchar *version; |
Richard Hughes | 12c8499 | 2018-10-02 11:07:28 +0100 | [diff] [blame] | 1152 | |
| 1153 | /* find if the other device exists */ |
Richard Hughes | f7006d2 | 2019-11-14 13:42:52 +0000 | [diff] [blame] | 1154 | if (depth == G_MAXUINT64) { |
| 1155 | g_autoptr(FuDevice) device_tmp = NULL; |
| 1156 | device_tmp = fu_device_list_get_by_guid (self->device_list, guid, error); |
| 1157 | if (device_tmp == NULL) |
| 1158 | return FALSE; |
| 1159 | g_set_object (&device_actual, device_tmp); |
| 1160 | |
| 1161 | /* verify the parent device has the GUID */ |
| 1162 | } else { |
| 1163 | if (!fu_device_has_guid (device_actual, guid)) { |
| 1164 | g_set_error (error, |
| 1165 | FWUPD_ERROR, |
| 1166 | FWUPD_ERROR_NOT_SUPPORTED, |
| 1167 | "No GUID of %s on parent device %s", |
| 1168 | guid, fu_device_get_name (device_actual)); |
| 1169 | return FALSE; |
| 1170 | } |
| 1171 | } |
Richard Hughes | 12c8499 | 2018-10-02 11:07:28 +0100 | [diff] [blame] | 1172 | |
| 1173 | /* get the version of the other device */ |
Richard Hughes | f7006d2 | 2019-11-14 13:42:52 +0000 | [diff] [blame] | 1174 | version = fu_device_get_version (device_actual); |
Richard Hughes | aaf0ce7 | 2019-07-16 08:43:57 +0100 | [diff] [blame] | 1175 | if (version != NULL && |
Richard Hughes | f7006d2 | 2019-11-14 13:42:52 +0000 | [diff] [blame] | 1176 | xb_node_get_attr (req, "compare") != NULL && |
Richard Hughes | 9a68084 | 2020-02-20 11:11:13 +0000 | [diff] [blame] | 1177 | !fu_engine_require_vercmp (req, version, |
| 1178 | fu_device_get_version_format (device_actual), |
| 1179 | &error_local)) { |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 1180 | if (g_strcmp0 (xb_node_get_attr (req, "compare"), "ge") == 0) { |
Richard Hughes | 12c8499 | 2018-10-02 11:07:28 +0100 | [diff] [blame] | 1181 | g_set_error (error, |
| 1182 | FWUPD_ERROR, |
| 1183 | FWUPD_ERROR_INVALID_FILE, |
| 1184 | "Not compatible with %s version %s, requires >= %s", |
Richard Hughes | f7006d2 | 2019-11-14 13:42:52 +0000 | [diff] [blame] | 1185 | fu_device_get_name (device_actual), |
Richard Hughes | 12c8499 | 2018-10-02 11:07:28 +0100 | [diff] [blame] | 1186 | version, |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 1187 | xb_node_get_attr (req, "version")); |
Richard Hughes | 12c8499 | 2018-10-02 11:07:28 +0100 | [diff] [blame] | 1188 | } else { |
| 1189 | g_set_error (error, |
| 1190 | FWUPD_ERROR, |
| 1191 | FWUPD_ERROR_INVALID_FILE, |
| 1192 | "Not compatible with %s: %s", |
Richard Hughes | f7006d2 | 2019-11-14 13:42:52 +0000 | [diff] [blame] | 1193 | fu_device_get_name (device_actual), |
Richard Hughes | 12c8499 | 2018-10-02 11:07:28 +0100 | [diff] [blame] | 1194 | error_local->message); |
| 1195 | } |
| 1196 | return FALSE; |
| 1197 | } |
| 1198 | return TRUE; |
| 1199 | |
| 1200 | } |
| 1201 | |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 1202 | /* not supported */ |
| 1203 | g_set_error (error, |
| 1204 | FWUPD_ERROR, |
| 1205 | FWUPD_ERROR_NOT_SUPPORTED, |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 1206 | "cannot handle firmware requirement '%s'", |
| 1207 | xb_node_get_text (req)); |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 1208 | return FALSE; |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 1209 | } |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 1210 | |
| 1211 | static gboolean |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 1212 | fu_engine_check_requirement_id (FuEngine *self, XbNode *req, GError **error) |
Richard Hughes | 2ec78d6 | 2017-11-03 21:48:54 +0000 | [diff] [blame] | 1213 | { |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 1214 | g_autoptr(GError) error_local = NULL; |
| 1215 | const gchar *version = g_hash_table_lookup (self->runtime_versions, |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 1216 | xb_node_get_text (req)); |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 1217 | if (version == NULL) { |
| 1218 | g_set_error (error, |
| 1219 | FWUPD_ERROR, |
| 1220 | FWUPD_ERROR_NOT_FOUND, |
| 1221 | "no version available for %s", |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 1222 | xb_node_get_text (req)); |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 1223 | return FALSE; |
| 1224 | } |
Richard Hughes | 9a68084 | 2020-02-20 11:11:13 +0000 | [diff] [blame] | 1225 | if (!fu_engine_require_vercmp (req, version, FWUPD_VERSION_FORMAT_UNKNOWN, &error_local)) { |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 1226 | if (g_strcmp0 (xb_node_get_attr (req, "compare"), "ge") == 0) { |
Richard Hughes | 2ec78d6 | 2017-11-03 21:48:54 +0000 | [diff] [blame] | 1227 | g_set_error (error, |
| 1228 | FWUPD_ERROR, |
| 1229 | FWUPD_ERROR_INVALID_FILE, |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 1230 | "Not compatible with %s version %s, requires >= %s", |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 1231 | xb_node_get_text (req), version, |
| 1232 | xb_node_get_attr (req, "version")); |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 1233 | } else { |
| 1234 | g_set_error (error, |
| 1235 | FWUPD_ERROR, |
| 1236 | FWUPD_ERROR_INVALID_FILE, |
| 1237 | "Not compatible with %s version: %s", |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 1238 | xb_node_get_text (req), error_local->message); |
Richard Hughes | 2ec78d6 | 2017-11-03 21:48:54 +0000 | [diff] [blame] | 1239 | } |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 1240 | return FALSE; |
Richard Hughes | 2ec78d6 | 2017-11-03 21:48:54 +0000 | [diff] [blame] | 1241 | } |
| 1242 | |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 1243 | g_debug ("requirement %s %s %s on %s passed", |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 1244 | xb_node_get_attr (req, "version"), |
| 1245 | xb_node_get_attr (req, "compare"), |
| 1246 | version, xb_node_get_text (req)); |
Richard Hughes | 2ec78d6 | 2017-11-03 21:48:54 +0000 | [diff] [blame] | 1247 | return TRUE; |
| 1248 | } |
Richard Hughes | 2ec78d6 | 2017-11-03 21:48:54 +0000 | [diff] [blame] | 1249 | |
| 1250 | static gboolean |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 1251 | fu_engine_check_requirement_hardware (FuEngine *self, XbNode *req, GError **error) |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 1252 | { |
Richard Hughes | 3d71c16 | 2018-04-30 16:40:44 +0100 | [diff] [blame] | 1253 | g_auto(GStrv) hwid_split = NULL; |
| 1254 | |
| 1255 | /* split and treat as OR */ |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 1256 | hwid_split = g_strsplit (xb_node_get_text (req), "|", -1); |
Richard Hughes | 3d71c16 | 2018-04-30 16:40:44 +0100 | [diff] [blame] | 1257 | for (guint i = 0; hwid_split[i] != NULL; i++) { |
| 1258 | if (fu_hwids_has_guid (self->hwids, hwid_split[i])) { |
| 1259 | g_debug ("HWID provided %s", hwid_split[i]); |
| 1260 | return TRUE; |
| 1261 | } |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 1262 | } |
Richard Hughes | 3d71c16 | 2018-04-30 16:40:44 +0100 | [diff] [blame] | 1263 | |
| 1264 | /* nothing matched */ |
| 1265 | g_set_error (error, |
| 1266 | FWUPD_ERROR, |
| 1267 | FWUPD_ERROR_INVALID_FILE, |
| 1268 | "no HWIDs matched %s", |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 1269 | xb_node_get_text (req)); |
Richard Hughes | 3d71c16 | 2018-04-30 16:40:44 +0100 | [diff] [blame] | 1270 | return FALSE; |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 1271 | } |
| 1272 | |
| 1273 | static gboolean |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 1274 | fu_engine_check_requirement (FuEngine *self, XbNode *req, FuDevice *device, GError **error) |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 1275 | { |
| 1276 | /* ensure component requirement */ |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 1277 | if (g_strcmp0 (xb_node_get_element (req), "id") == 0) |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 1278 | return fu_engine_check_requirement_id (self, req, error); |
| 1279 | |
| 1280 | /* ensure firmware requirement */ |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 1281 | if (g_strcmp0 (xb_node_get_element (req), "firmware") == 0) { |
Richard Hughes | 881f624 | 2018-08-06 11:03:06 +0100 | [diff] [blame] | 1282 | if (device == NULL) |
| 1283 | return TRUE; |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 1284 | return fu_engine_check_requirement_firmware (self, req, device, error); |
Richard Hughes | 881f624 | 2018-08-06 11:03:06 +0100 | [diff] [blame] | 1285 | } |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 1286 | |
| 1287 | /* ensure hardware requirement */ |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 1288 | if (g_strcmp0 (xb_node_get_element (req), "hardware") == 0) |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 1289 | return fu_engine_check_requirement_hardware (self, req, error); |
| 1290 | |
| 1291 | /* not supported */ |
| 1292 | g_set_error (error, |
| 1293 | FWUPD_ERROR, |
| 1294 | FWUPD_ERROR_NOT_SUPPORTED, |
| 1295 | "cannot handle requirement type %s", |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 1296 | xb_node_get_element (req)); |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 1297 | return FALSE; |
| 1298 | } |
| 1299 | |
| 1300 | gboolean |
Richard Hughes | 1d1f5cf | 2018-05-19 23:06:03 +0100 | [diff] [blame] | 1301 | fu_engine_check_requirements (FuEngine *self, FuInstallTask *task, |
| 1302 | FwupdInstallFlags flags, GError **error) |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 1303 | { |
Richard Hughes | 1d1f5cf | 2018-05-19 23:06:03 +0100 | [diff] [blame] | 1304 | FuDevice *device = fu_install_task_get_device (task); |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 1305 | g_autoptr(GError) error_local = NULL; |
| 1306 | g_autoptr(GPtrArray) reqs = NULL; |
Richard Hughes | 1d1f5cf | 2018-05-19 23:06:03 +0100 | [diff] [blame] | 1307 | |
| 1308 | /* all install task checks require a device */ |
| 1309 | if (device != NULL) { |
| 1310 | if (!fu_install_task_check_requirements (task, flags, error)) |
| 1311 | return FALSE; |
| 1312 | } |
| 1313 | |
| 1314 | /* do engine checks */ |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 1315 | reqs = xb_node_query (fu_install_task_get_component (task), |
| 1316 | "requires/*", 0, &error_local); |
| 1317 | if (reqs == NULL) { |
| 1318 | if (g_error_matches (error_local, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) |
| 1319 | return TRUE; |
| 1320 | if (g_error_matches (error_local, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT)) |
| 1321 | return TRUE; |
| 1322 | g_propagate_error (error, g_steal_pointer (&error_local)); |
| 1323 | return FALSE; |
| 1324 | } |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 1325 | for (guint i = 0; i < reqs->len; i++) { |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 1326 | XbNode *req = g_ptr_array_index (reqs, i); |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 1327 | if (!fu_engine_check_requirement (self, req, device, error)) |
| 1328 | return FALSE; |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 1329 | } |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 1330 | return TRUE; |
| 1331 | } |
| 1332 | |
Richard Hughes | 75b965d | 2018-11-15 13:51:21 +0000 | [diff] [blame] | 1333 | void |
| 1334 | fu_engine_idle_reset (FuEngine *self) |
| 1335 | { |
| 1336 | fu_idle_reset (self->idle); |
| 1337 | } |
| 1338 | |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 1339 | static gchar * |
Richard Hughes | 59c2ebe | 2018-01-12 09:47:40 +0000 | [diff] [blame] | 1340 | fu_engine_get_boot_time (void) |
| 1341 | { |
| 1342 | g_autofree gchar *buf = NULL; |
| 1343 | g_auto(GStrv) lines = NULL; |
| 1344 | if (!g_file_get_contents ("/proc/stat", &buf, NULL, NULL)) |
| 1345 | return NULL; |
| 1346 | lines = g_strsplit (buf, "\n", -1); |
| 1347 | for (guint i = 0; lines[i] != NULL; i++) { |
| 1348 | if (g_str_has_prefix (lines[i], "btime ")) |
| 1349 | return g_strdup (lines[i] + 6); |
| 1350 | } |
| 1351 | return NULL; |
| 1352 | } |
| 1353 | |
Richard Hughes | 6ecc4ca | 2020-05-20 18:42:46 +0100 | [diff] [blame] | 1354 | static gboolean |
| 1355 | fu_engine_get_report_metadata_os_release (GHashTable *hash, GError **error) |
Richard Hughes | 473c520 | 2018-01-11 21:06:16 +0000 | [diff] [blame] | 1356 | { |
Richard Hughes | 6ecc4ca | 2020-05-20 18:42:46 +0100 | [diff] [blame] | 1357 | g_autoptr(GHashTable) os_release = NULL; |
| 1358 | struct { |
| 1359 | const gchar *key; |
| 1360 | const gchar *val; |
| 1361 | } distro_kv[] = { |
| 1362 | { "ID", "DistroId" }, |
| 1363 | { "VERSION_ID", "DistroVersion" }, |
| 1364 | { "VARIANT_ID", "DistroVariant" }, |
| 1365 | { NULL, NULL } |
| 1366 | }; |
| 1367 | |
| 1368 | /* get all required os-release keys */ |
| 1369 | os_release = fwupd_get_os_release (error); |
| 1370 | if (os_release == NULL) |
| 1371 | return FALSE; |
| 1372 | for (guint i = 0; distro_kv[i].key != NULL; i++) { |
| 1373 | const gchar *tmp = g_hash_table_lookup (os_release, distro_kv[i].key); |
| 1374 | if (tmp != NULL) { |
| 1375 | g_hash_table_insert (hash, |
| 1376 | g_strdup (distro_kv[i].val), |
| 1377 | g_strdup (tmp)); |
| 1378 | } |
| 1379 | } |
| 1380 | return TRUE; |
| 1381 | } |
| 1382 | |
Richard Hughes | dc867dd | 2020-05-20 18:47:20 +0100 | [diff] [blame] | 1383 | static gboolean |
| 1384 | fu_engine_get_report_metadata_kernel_cmdline (GHashTable *hash, GError **error) |
| 1385 | { |
| 1386 | gsize bufsz = 0; |
| 1387 | g_autofree gchar *buf = NULL; |
| 1388 | const gchar *ignore[] = { |
| 1389 | "", |
Richard Hughes | c05ac2d | 2020-05-20 22:35:09 +0100 | [diff] [blame] | 1390 | "auto", |
Richard Hughes | dc867dd | 2020-05-20 18:47:20 +0100 | [diff] [blame] | 1391 | "BOOT_IMAGE", |
| 1392 | "console", |
| 1393 | "cryptdevice", |
| 1394 | "initrd", |
| 1395 | "LANG", |
| 1396 | "loglevel", |
Richard Hughes | c05ac2d | 2020-05-20 22:35:09 +0100 | [diff] [blame] | 1397 | "noplymouth", |
Richard Hughes | dc867dd | 2020-05-20 18:47:20 +0100 | [diff] [blame] | 1398 | "ostree", |
| 1399 | "quiet", |
| 1400 | "rd.luks.uuid", |
| 1401 | "rd.lvm.lv", |
Richard Hughes | 4a62329 | 2020-05-21 20:58:28 +0100 | [diff] [blame] | 1402 | "rd.md.uuid", |
Richard Hughes | dc867dd | 2020-05-20 18:47:20 +0100 | [diff] [blame] | 1403 | "resume", |
| 1404 | "rhgb", |
| 1405 | "ro", |
| 1406 | "root", |
| 1407 | "rootflags", |
| 1408 | "rw", |
| 1409 | "showopts", |
| 1410 | "splash", |
| 1411 | "swap", |
Richard Hughes | c05ac2d | 2020-05-20 22:35:09 +0100 | [diff] [blame] | 1412 | "verbose", |
Richard Hughes | dc867dd | 2020-05-20 18:47:20 +0100 | [diff] [blame] | 1413 | "vt.handoff", |
| 1414 | "zfs", |
| 1415 | NULL, /* last entry */ |
| 1416 | }; |
| 1417 | |
| 1418 | /* get a PII-safe kernel command line */ |
| 1419 | if (!g_file_get_contents ("/proc/cmdline", &buf, &bufsz, error)) |
| 1420 | return FALSE; |
| 1421 | if (bufsz > 0) { |
| 1422 | g_auto(GStrv) tokens = fu_common_strnsplit (buf, bufsz - 1, " ", -1); |
| 1423 | g_autoptr(GString) cmdline_safe = g_string_new (NULL); |
| 1424 | for (guint i = 0; tokens[i] != NULL; i++) { |
| 1425 | g_auto(GStrv) kv = g_strsplit (tokens[i], "=", 2); |
| 1426 | if (g_strv_contains (ignore, kv[0])) |
| 1427 | continue; |
| 1428 | if (cmdline_safe->len > 0) |
| 1429 | g_string_append (cmdline_safe, " "); |
| 1430 | g_string_append (cmdline_safe, tokens[i]); |
| 1431 | } |
| 1432 | if (cmdline_safe->len > 0) { |
| 1433 | g_hash_table_insert (hash, |
| 1434 | g_strdup ("KernelCmdline"), |
| 1435 | g_strdup (cmdline_safe->str)); |
| 1436 | } |
| 1437 | } |
| 1438 | return TRUE; |
| 1439 | } |
| 1440 | |
Richard Hughes | 6ecc4ca | 2020-05-20 18:42:46 +0100 | [diff] [blame] | 1441 | GHashTable * |
| 1442 | fu_engine_get_report_metadata (FuEngine *self, GError **error) |
| 1443 | { |
Richard Hughes | a778ac9 | 2020-05-20 18:44:24 +0100 | [diff] [blame] | 1444 | const gchar *tmp; |
Richard Hughes | 59c2ebe | 2018-01-12 09:47:40 +0000 | [diff] [blame] | 1445 | gchar *btime; |
Richard Hughes | fc1e267 | 2019-11-22 08:53:33 +0000 | [diff] [blame] | 1446 | #ifdef HAVE_UTSNAME_H |
Mario Limonciello | ed1ac2a | 2018-04-17 14:43:28 -0500 | [diff] [blame] | 1447 | struct utsname name_tmp; |
Richard Hughes | fc1e267 | 2019-11-22 08:53:33 +0000 | [diff] [blame] | 1448 | #endif |
Richard Hughes | 6ecc4ca | 2020-05-20 18:42:46 +0100 | [diff] [blame] | 1449 | g_autoptr(GHashTable) hash = NULL; |
Richard Hughes | 34e0dab | 2018-04-20 16:43:00 +0100 | [diff] [blame] | 1450 | g_autoptr(GList) compile_keys = g_hash_table_get_keys (self->compile_versions); |
| 1451 | g_autoptr(GList) runtime_keys = g_hash_table_get_keys (self->runtime_versions); |
Richard Hughes | 473c520 | 2018-01-11 21:06:16 +0000 | [diff] [blame] | 1452 | |
Richard Hughes | 34e0dab | 2018-04-20 16:43:00 +0100 | [diff] [blame] | 1453 | /* convert all the runtime and compile-time versions */ |
Richard Hughes | 473c520 | 2018-01-11 21:06:16 +0000 | [diff] [blame] | 1454 | hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); |
Richard Hughes | 34e0dab | 2018-04-20 16:43:00 +0100 | [diff] [blame] | 1455 | for (GList *l = compile_keys; l != NULL; l = l->next) { |
| 1456 | const gchar *id = l->data; |
| 1457 | const gchar *version = g_hash_table_lookup (self->compile_versions, id); |
| 1458 | g_hash_table_insert (hash, |
| 1459 | g_strdup_printf ("CompileVersion(%s)", id), |
| 1460 | g_strdup (version)); |
| 1461 | } |
| 1462 | for (GList *l = runtime_keys; l != NULL; l = l->next) { |
| 1463 | const gchar *id = l->data; |
| 1464 | const gchar *version = g_hash_table_lookup (self->runtime_versions, id); |
| 1465 | g_hash_table_insert (hash, |
| 1466 | g_strdup_printf ("RuntimeVersion(%s)", id), |
| 1467 | g_strdup (version)); |
| 1468 | } |
Richard Hughes | 6ecc4ca | 2020-05-20 18:42:46 +0100 | [diff] [blame] | 1469 | if (!fu_engine_get_report_metadata_os_release (hash, error)) |
| 1470 | return NULL; |
Richard Hughes | dc867dd | 2020-05-20 18:47:20 +0100 | [diff] [blame] | 1471 | if (!fu_engine_get_report_metadata_kernel_cmdline (hash, error)) |
| 1472 | return NULL; |
Richard Hughes | 473c520 | 2018-01-11 21:06:16 +0000 | [diff] [blame] | 1473 | |
Richard Hughes | a778ac9 | 2020-05-20 18:44:24 +0100 | [diff] [blame] | 1474 | /* DMI data */ |
| 1475 | tmp = fu_hwids_get_value (self->hwids, FU_HWIDS_KEY_PRODUCT_NAME); |
| 1476 | if (tmp != NULL) |
| 1477 | g_hash_table_insert (hash, g_strdup ("HostProduct"), g_strdup (tmp)); |
| 1478 | tmp = fu_hwids_get_value (self->hwids, FU_HWIDS_KEY_FAMILY); |
| 1479 | if (tmp != NULL) |
| 1480 | g_hash_table_insert (hash, g_strdup ("HostFamily"), g_strdup (tmp)); |
| 1481 | tmp = fu_hwids_get_value (self->hwids, FU_HWIDS_KEY_PRODUCT_SKU); |
| 1482 | if (tmp != NULL) |
| 1483 | g_hash_table_insert (hash, g_strdup ("HostSku"), g_strdup (tmp)); |
| 1484 | tmp = fu_hwids_get_value (self->hwids, FU_HWIDS_KEY_MANUFACTURER); |
| 1485 | if (tmp != NULL) |
| 1486 | g_hash_table_insert (hash, g_strdup ("HostVendor"), g_strdup (tmp)); |
| 1487 | |
Richard Hughes | 473c520 | 2018-01-11 21:06:16 +0000 | [diff] [blame] | 1488 | /* kernel version is often important for debugging failures */ |
Richard Hughes | fc1e267 | 2019-11-22 08:53:33 +0000 | [diff] [blame] | 1489 | #ifdef HAVE_UTSNAME_H |
Mario Limonciello | ed1ac2a | 2018-04-17 14:43:28 -0500 | [diff] [blame] | 1490 | memset (&name_tmp, 0, sizeof (struct utsname)); |
Richard Hughes | 473c520 | 2018-01-11 21:06:16 +0000 | [diff] [blame] | 1491 | if (uname (&name_tmp) >= 0) { |
| 1492 | g_hash_table_insert (hash, |
| 1493 | g_strdup ("CpuArchitecture"), |
| 1494 | g_strdup (name_tmp.machine)); |
Richard Hughes | 08bb922 | 2020-05-20 18:43:59 +0100 | [diff] [blame] | 1495 | g_hash_table_insert (hash, |
| 1496 | g_strdup ("KernelVersion"), |
| 1497 | g_strdup (name_tmp.release)); |
Richard Hughes | 473c520 | 2018-01-11 21:06:16 +0000 | [diff] [blame] | 1498 | } |
Richard Hughes | fc1e267 | 2019-11-22 08:53:33 +0000 | [diff] [blame] | 1499 | #endif |
Richard Hughes | 473c520 | 2018-01-11 21:06:16 +0000 | [diff] [blame] | 1500 | |
Richard Hughes | 59c2ebe | 2018-01-12 09:47:40 +0000 | [diff] [blame] | 1501 | /* add the kernel boot time so we can detect a reboot */ |
| 1502 | btime = fu_engine_get_boot_time (); |
| 1503 | if (btime != NULL) |
| 1504 | g_hash_table_insert (hash, g_strdup ("BootTime"), btime); |
| 1505 | |
Richard Hughes | 6ecc4ca | 2020-05-20 18:42:46 +0100 | [diff] [blame] | 1506 | return g_steal_pointer (&hash); |
Richard Hughes | 473c520 | 2018-01-11 21:06:16 +0000 | [diff] [blame] | 1507 | } |
| 1508 | |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 1509 | /** |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 1510 | * fu_engine_composite_prepare: |
| 1511 | * @self: A #FuEngine |
| 1512 | * @devices: (element-type #FuDevice): devices that will be updated |
| 1513 | * @error: A #GError, or %NULL |
| 1514 | * |
| 1515 | * Calls into the plugin loader, informing each plugin of the pending upgrade(s). |
| 1516 | * |
| 1517 | * Any failure in any plugin will abort all of the actions before they are started. |
| 1518 | * |
| 1519 | * Returns: %TRUE for success |
| 1520 | **/ |
| 1521 | gboolean |
| 1522 | fu_engine_composite_prepare (FuEngine *self, GPtrArray *devices, GError **error) |
| 1523 | { |
| 1524 | GPtrArray *plugins = fu_plugin_list_get_all (self->plugin_list); |
| 1525 | for (guint j = 0; j < plugins->len; j++) { |
| 1526 | FuPlugin *plugin_tmp = g_ptr_array_index (plugins, j); |
| 1527 | if (!fu_plugin_runner_composite_prepare (plugin_tmp, devices, error)) |
| 1528 | return FALSE; |
| 1529 | } |
| 1530 | return TRUE; |
| 1531 | } |
| 1532 | |
| 1533 | /** |
| 1534 | * fu_engine_composite_cleanup: |
| 1535 | * @self: A #FuEngine |
| 1536 | * @devices: (element-type #FuDevice): devices that will be updated |
| 1537 | * @error: A #GError, or %NULL |
| 1538 | * |
| 1539 | * Calls into the plugin loader, informing each plugin of the pending upgrade(s). |
| 1540 | * |
| 1541 | * Returns: %TRUE for success |
| 1542 | **/ |
| 1543 | gboolean |
| 1544 | fu_engine_composite_cleanup (FuEngine *self, GPtrArray *devices, GError **error) |
| 1545 | { |
| 1546 | GPtrArray *plugins = fu_plugin_list_get_all (self->plugin_list); |
| 1547 | for (guint j = 0; j < plugins->len; j++) { |
| 1548 | FuPlugin *plugin_tmp = g_ptr_array_index (plugins, j); |
| 1549 | if (!fu_plugin_runner_composite_cleanup (plugin_tmp, devices, error)) |
| 1550 | return FALSE; |
| 1551 | } |
| 1552 | return TRUE; |
| 1553 | } |
| 1554 | |
| 1555 | /** |
| 1556 | * fu_engine_install_tasks: |
| 1557 | * @self: A #FuEngine |
| 1558 | * @install_tasks: (element-type FuInstallTask): A #FuDevice |
| 1559 | * @blob_cab: The #GBytes of the .cab file |
| 1560 | * @flags: The #FwupdInstallFlags, e.g. %FWUPD_DEVICE_FLAG_UPDATABLE |
| 1561 | * @error: A #GError, or %NULL |
| 1562 | * |
| 1563 | * Installs a specific firmware file on one or more install tasks. |
| 1564 | * |
| 1565 | * By this point all the requirements and tests should have been done in |
| 1566 | * fu_engine_check_requirements() so this should not fail before running |
| 1567 | * the plugin loader. |
| 1568 | * |
| 1569 | * Returns: %TRUE for success |
| 1570 | **/ |
| 1571 | gboolean |
| 1572 | fu_engine_install_tasks (FuEngine *self, |
| 1573 | GPtrArray *install_tasks, |
| 1574 | GBytes *blob_cab, |
| 1575 | FwupdInstallFlags flags, |
| 1576 | GError **error) |
| 1577 | { |
Richard Hughes | 75b965d | 2018-11-15 13:51:21 +0000 | [diff] [blame] | 1578 | g_autoptr(FuIdleLocker) locker = NULL; |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 1579 | g_autoptr(GPtrArray) devices = NULL; |
Mario Limonciello | b6fa473 | 2018-09-07 15:12:33 +0100 | [diff] [blame] | 1580 | g_autoptr(GPtrArray) devices_new = NULL; |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 1581 | |
Richard Hughes | 75b965d | 2018-11-15 13:51:21 +0000 | [diff] [blame] | 1582 | /* do not allow auto-shutdown during this time */ |
| 1583 | locker = fu_idle_locker_new (self->idle, "performing update"); |
| 1584 | g_assert (locker != NULL); |
| 1585 | |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 1586 | /* notify the plugins about the composite action */ |
| 1587 | devices = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref); |
| 1588 | for (guint i = 0; i < install_tasks->len; i++) { |
| 1589 | FuInstallTask *task = g_ptr_array_index (install_tasks, i); |
Richard Hughes | ca6af0b | 2020-04-16 17:08:33 +0100 | [diff] [blame] | 1590 | g_debug ("composite update %u: %s", i + 1, |
| 1591 | fu_device_get_id (fu_install_task_get_device (task))); |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 1592 | g_ptr_array_add (devices, g_object_ref (fu_install_task_get_device (task))); |
| 1593 | } |
| 1594 | if (!fu_engine_composite_prepare (self, devices, error)) { |
| 1595 | g_prefix_error (error, "failed to prepare composite action: "); |
| 1596 | return FALSE; |
| 1597 | } |
| 1598 | |
| 1599 | /* all authenticated, so install all the things */ |
| 1600 | for (guint i = 0; i < install_tasks->len; i++) { |
| 1601 | FuInstallTask *task = g_ptr_array_index (install_tasks, i); |
| 1602 | if (!fu_engine_install (self, task, blob_cab, flags, error)) { |
| 1603 | g_autoptr(GError) error_local = NULL; |
| 1604 | if (!fu_engine_composite_cleanup (self, devices, &error_local)) { |
| 1605 | g_warning ("failed to cleanup failed composite action: %s", |
| 1606 | error_local->message); |
| 1607 | } |
| 1608 | return FALSE; |
| 1609 | } |
| 1610 | } |
| 1611 | |
Richard Hughes | 96019e8 | 2019-01-30 11:12:57 +0000 | [diff] [blame] | 1612 | /* set all the device statuses back to unknown */ |
| 1613 | for (guint i = 0; i < install_tasks->len; i++) { |
| 1614 | FuInstallTask *task = g_ptr_array_index (install_tasks, i); |
| 1615 | FuDevice *device = fu_install_task_get_device (task); |
| 1616 | fu_device_set_status (device, FWUPD_STATUS_UNKNOWN); |
| 1617 | } |
| 1618 | |
Mario Limonciello | b6fa473 | 2018-09-07 15:12:33 +0100 | [diff] [blame] | 1619 | /* get a new list of devices in case they replugged */ |
| 1620 | devices_new = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref); |
| 1621 | for (guint i = 0; i < devices->len; i++) { |
| 1622 | FuDevice *device; |
Richard Hughes | 5a9a6bd | 2018-09-10 10:02:20 +0100 | [diff] [blame] | 1623 | g_autoptr(FuDevice) device_new = NULL; |
Mario Limonciello | b6fa473 | 2018-09-07 15:12:33 +0100 | [diff] [blame] | 1624 | g_autoptr(GError) error_local = NULL; |
| 1625 | device = g_ptr_array_index (devices, i); |
| 1626 | device_new = fu_device_list_get_by_id (self->device_list, |
| 1627 | fu_device_get_id (device), |
| 1628 | &error_local); |
| 1629 | if (device_new == NULL) { |
Mario Limonciello | 769d768 | 2018-09-28 08:43:37 -0500 | [diff] [blame] | 1630 | g_debug ("failed to find new device: %s", |
| 1631 | error_local->message); |
Mario Limonciello | b6fa473 | 2018-09-07 15:12:33 +0100 | [diff] [blame] | 1632 | continue; |
| 1633 | } |
Richard Hughes | 5a9a6bd | 2018-09-10 10:02:20 +0100 | [diff] [blame] | 1634 | g_ptr_array_add (devices_new, g_steal_pointer (&device_new)); |
Mario Limonciello | b6fa473 | 2018-09-07 15:12:33 +0100 | [diff] [blame] | 1635 | } |
| 1636 | |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 1637 | /* notify the plugins about the composite action */ |
Mario Limonciello | b6fa473 | 2018-09-07 15:12:33 +0100 | [diff] [blame] | 1638 | if (!fu_engine_composite_cleanup (self, devices_new, error)) { |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 1639 | g_prefix_error (error, "failed to cleanup composite action: "); |
| 1640 | return FALSE; |
| 1641 | } |
| 1642 | |
| 1643 | /* success */ |
| 1644 | return TRUE; |
| 1645 | } |
| 1646 | |
Richard Hughes | 81d7a5c | 2019-03-25 14:26:04 +0000 | [diff] [blame] | 1647 | static FwupdRelease * |
| 1648 | fu_engine_create_release_metadata (FuEngine *self, FuPlugin *plugin, GError **error) |
| 1649 | { |
Richard Hughes | dad3597 | 2019-12-06 11:00:25 +0000 | [diff] [blame] | 1650 | GPtrArray *metadata_sources; |
Richard Hughes | 81d7a5c | 2019-03-25 14:26:04 +0000 | [diff] [blame] | 1651 | g_autoptr(FwupdRelease) release = fwupd_release_new (); |
| 1652 | g_autoptr(GHashTable) metadata_hash = NULL; |
Richard Hughes | 81d7a5c | 2019-03-25 14:26:04 +0000 | [diff] [blame] | 1653 | |
| 1654 | /* build the version metadata */ |
Richard Hughes | 6ecc4ca | 2020-05-20 18:42:46 +0100 | [diff] [blame] | 1655 | metadata_hash = fu_engine_get_report_metadata (self, error); |
| 1656 | if (metadata_hash == NULL) |
| 1657 | return NULL; |
Richard Hughes | 81d7a5c | 2019-03-25 14:26:04 +0000 | [diff] [blame] | 1658 | fwupd_release_add_metadata (release, metadata_hash); |
| 1659 | fwupd_release_add_metadata (release, fu_plugin_get_report_metadata (plugin)); |
| 1660 | |
Richard Hughes | dad3597 | 2019-12-06 11:00:25 +0000 | [diff] [blame] | 1661 | /* allow other plugins to contribute metadata too */ |
| 1662 | metadata_sources = fu_plugin_get_rules (plugin, FU_PLUGIN_RULE_METADATA_SOURCE); |
| 1663 | for (guint i = 0; i < metadata_sources->len; i++) { |
| 1664 | FuPlugin *plugin_tmp; |
| 1665 | const gchar *plugin_name = g_ptr_array_index (metadata_sources, i); |
| 1666 | g_autoptr(GError) error_local = NULL; |
| 1667 | |
| 1668 | plugin_tmp = fu_plugin_list_find_by_name (self->plugin_list, |
| 1669 | plugin_name, |
| 1670 | &error_local); |
| 1671 | if (plugin_tmp == NULL) { |
| 1672 | g_warning ("could not add metadata for %s: %s", |
| 1673 | plugin_name, |
| 1674 | error_local->message); |
| 1675 | continue; |
| 1676 | } |
| 1677 | fwupd_release_add_metadata (release, |
| 1678 | fu_plugin_get_report_metadata (plugin_tmp)); |
| 1679 | } |
Richard Hughes | 81d7a5c | 2019-03-25 14:26:04 +0000 | [diff] [blame] | 1680 | return g_steal_pointer (&release); |
| 1681 | } |
| 1682 | |
Richard Hughes | 3d00522 | 2019-05-17 14:02:41 +0100 | [diff] [blame] | 1683 | static gboolean |
| 1684 | fu_engine_is_running_offline (FuEngine *self) |
| 1685 | { |
| 1686 | #ifdef HAVE_SYSTEMD |
| 1687 | g_autofree gchar *default_target = NULL; |
| 1688 | g_autoptr(GError) error = NULL; |
| 1689 | default_target = fu_systemd_get_default_target (&error); |
| 1690 | if (default_target == NULL) { |
| 1691 | g_warning ("failed to get default.target: %s", error->message); |
| 1692 | return FALSE; |
| 1693 | } |
| 1694 | return g_strcmp0 (default_target, "system-update.target") == 0; |
| 1695 | #else |
| 1696 | return FALSE; |
| 1697 | #endif |
| 1698 | } |
| 1699 | |
Richard Hughes | 019a1bc | 2019-11-26 10:19:33 +0000 | [diff] [blame] | 1700 | static gboolean |
| 1701 | fu_engine_offline_setup (GError **error) |
| 1702 | { |
Richard Hughes | 9e5675e | 2019-11-22 09:35:03 +0000 | [diff] [blame] | 1703 | #ifdef HAVE_GIO_UNIX |
Richard Hughes | 019a1bc | 2019-11-26 10:19:33 +0000 | [diff] [blame] | 1704 | gint rc; |
| 1705 | g_autofree gchar *filename = NULL; |
| 1706 | g_autofree gchar *symlink_target = fu_common_get_path (FU_PATH_KIND_LOCALSTATEDIR_PKG); |
| 1707 | g_autofree gchar *trigger = fu_common_get_path (FU_PATH_KIND_OFFLINE_TRIGGER); |
| 1708 | |
| 1709 | g_return_val_if_fail (error == NULL || *error == NULL, FALSE); |
| 1710 | |
| 1711 | /* does already exist */ |
| 1712 | filename = fu_common_realpath (trigger, NULL); |
| 1713 | if (g_strcmp0 (filename, symlink_target) == 0) { |
| 1714 | g_debug ("%s already points to %s, skipping creation", |
| 1715 | trigger, symlink_target); |
| 1716 | return TRUE; |
| 1717 | } |
| 1718 | |
| 1719 | /* create symlink for the systemd-system-update-generator */ |
| 1720 | rc = symlink (symlink_target, trigger); |
| 1721 | if (rc < 0) { |
| 1722 | g_set_error (error, |
| 1723 | FWUPD_ERROR, |
| 1724 | FWUPD_ERROR_INTERNAL, |
| 1725 | "Failed to create symlink %s to %s: %s", |
| 1726 | trigger, symlink_target, strerror (errno)); |
| 1727 | return FALSE; |
| 1728 | } |
| 1729 | return TRUE; |
Richard Hughes | 9e5675e | 2019-11-22 09:35:03 +0000 | [diff] [blame] | 1730 | #else |
| 1731 | g_set_error (error, |
| 1732 | FWUPD_ERROR, |
| 1733 | FWUPD_ERROR_NOT_SUPPORTED, |
| 1734 | "Not supported as <gio-unix.h> not available"); |
| 1735 | return FALSE; |
| 1736 | #endif |
| 1737 | |
Richard Hughes | 019a1bc | 2019-11-26 10:19:33 +0000 | [diff] [blame] | 1738 | } |
| 1739 | |
| 1740 | static gboolean |
| 1741 | fu_engine_offline_invalidate (GError **error) |
| 1742 | { |
| 1743 | g_autofree gchar *trigger = fu_common_get_path (FU_PATH_KIND_OFFLINE_TRIGGER); |
| 1744 | g_autoptr(GError) error_local = NULL; |
| 1745 | g_autoptr(GFile) file1 = NULL; |
| 1746 | |
| 1747 | g_return_val_if_fail (error == NULL || *error == NULL, FALSE); |
| 1748 | |
| 1749 | file1 = g_file_new_for_path (trigger); |
| 1750 | if (!g_file_query_exists (file1, NULL)) |
| 1751 | return TRUE; |
| 1752 | if (!g_file_delete (file1, NULL, &error_local)) { |
| 1753 | g_set_error (error, |
| 1754 | FWUPD_ERROR, |
| 1755 | FWUPD_ERROR_INTERNAL, |
| 1756 | "Cannot delete %s: %s", |
| 1757 | trigger, |
| 1758 | error_local->message); |
| 1759 | return FALSE; |
| 1760 | } |
| 1761 | return TRUE; |
| 1762 | } |
| 1763 | |
| 1764 | /** |
| 1765 | * fu_engine_schedule_update: |
| 1766 | * @self: a #FuEngine |
| 1767 | * @device: a #FuDevice |
| 1768 | * @release: A #FwupdRelease |
| 1769 | * @blob_cab: A #GBytes |
| 1770 | * @flags: #FwupdInstallFlags |
| 1771 | * @error: A #GError or NULL |
| 1772 | * |
| 1773 | * Schedule an offline update for the device |
| 1774 | * |
| 1775 | * Returns: #TRUE for success, #FALSE for failure |
| 1776 | * |
| 1777 | * Since: 1.3.5 |
| 1778 | **/ |
| 1779 | gboolean |
| 1780 | fu_engine_schedule_update (FuEngine *self, |
| 1781 | FuDevice *device, |
| 1782 | FwupdRelease *release, |
| 1783 | GBytes *blob_cab, |
| 1784 | FwupdInstallFlags flags, |
| 1785 | GError **error) |
| 1786 | { |
| 1787 | gchar tmpname[] = {"XXXXXX.cab"}; |
| 1788 | g_autofree gchar *dirname = NULL; |
| 1789 | g_autofree gchar *filename = NULL; |
| 1790 | g_autoptr(FuHistory) history = NULL; |
| 1791 | g_autoptr(GFile) file = NULL; |
| 1792 | |
| 1793 | /* id already exists */ |
| 1794 | history = fu_history_new (); |
| 1795 | if ((flags & FWUPD_INSTALL_FLAG_FORCE) == 0) { |
| 1796 | g_autoptr(FuDevice) res_tmp = NULL; |
| 1797 | res_tmp = fu_history_get_device_by_id (history, fu_device_get_id (device), NULL); |
| 1798 | if (res_tmp != NULL && |
| 1799 | fu_device_get_update_state (res_tmp) == FWUPD_UPDATE_STATE_PENDING) { |
| 1800 | g_set_error (error, |
| 1801 | FWUPD_ERROR, |
| 1802 | FWUPD_ERROR_ALREADY_PENDING, |
| 1803 | "%s is already scheduled to be updated", |
| 1804 | fu_device_get_id (device)); |
| 1805 | return FALSE; |
| 1806 | } |
| 1807 | } |
| 1808 | |
| 1809 | /* create directory */ |
| 1810 | dirname = fu_common_get_path (FU_PATH_KIND_LOCALSTATEDIR_PKG); |
| 1811 | file = g_file_new_for_path (dirname); |
| 1812 | if (!g_file_query_exists (file, NULL)) { |
| 1813 | if (!g_file_make_directory_with_parents (file, NULL, error)) |
| 1814 | return FALSE; |
| 1815 | } |
| 1816 | |
| 1817 | /* get a random filename */ |
| 1818 | for (guint i = 0; i < 6; i++) |
| 1819 | tmpname[i] = (gchar) g_random_int_range ('A', 'Z'); |
| 1820 | filename = g_build_filename (dirname, tmpname, NULL); |
| 1821 | |
| 1822 | /* just copy to the temp file */ |
| 1823 | fu_device_set_status (device, FWUPD_STATUS_SCHEDULING); |
| 1824 | if (!g_file_set_contents (filename, |
| 1825 | g_bytes_get_data (blob_cab, NULL), |
| 1826 | (gssize) g_bytes_get_size (blob_cab), |
| 1827 | error)) |
| 1828 | return FALSE; |
| 1829 | |
| 1830 | /* schedule for next boot */ |
| 1831 | g_debug ("schedule %s to be installed to %s on next boot", |
| 1832 | filename, fu_device_get_id (device)); |
| 1833 | fwupd_release_set_filename (release, filename); |
| 1834 | |
| 1835 | /* add to database */ |
| 1836 | fu_device_add_flag (device, FWUPD_DEVICE_FLAG_NEEDS_REBOOT); |
| 1837 | fu_device_set_update_state (device, FWUPD_UPDATE_STATE_PENDING); |
| 1838 | if (!fu_history_add_device (history, device, release, error)) |
| 1839 | return FALSE; |
| 1840 | |
| 1841 | /* next boot we run offline */ |
| 1842 | fu_device_set_progress (device, 100); |
| 1843 | return fu_engine_offline_setup (error); |
| 1844 | } |
| 1845 | |
Richard Hughes | 4bd2e04 | 2019-12-22 12:19:52 +0000 | [diff] [blame] | 1846 | static gboolean |
| 1847 | fu_engine_install_release (FuEngine *self, |
Richard Hughes | 293a64d | 2020-02-14 12:08:08 +0000 | [diff] [blame] | 1848 | FuDevice *device_orig, |
Richard Hughes | 4bd2e04 | 2019-12-22 12:19:52 +0000 | [diff] [blame] | 1849 | XbNode *component, |
| 1850 | XbNode *rel, |
| 1851 | FwupdInstallFlags flags, |
| 1852 | GError **error) |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 1853 | { |
Richard Hughes | afca203 | 2019-02-01 18:05:30 +0000 | [diff] [blame] | 1854 | FuPlugin *plugin; |
Richard Hughes | 9a68084 | 2020-02-20 11:11:13 +0000 | [diff] [blame] | 1855 | FwupdVersionFormat fmt; |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 1856 | GBytes *blob_fw; |
Richard Hughes | d5aab65 | 2020-02-25 12:47:50 +0000 | [diff] [blame] | 1857 | const gchar *tmp; |
Richard Hughes | 84af6e7 | 2019-02-01 18:19:41 +0000 | [diff] [blame] | 1858 | g_autofree gchar *version_orig = NULL; |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 1859 | g_autofree gchar *version_rel = NULL; |
Richard Hughes | 68db74b | 2019-03-14 09:52:05 +0000 | [diff] [blame] | 1860 | g_autoptr(FuDevice) device_tmp = NULL; |
Richard Hughes | 293a64d | 2020-02-14 12:08:08 +0000 | [diff] [blame] | 1861 | g_autoptr(FuDevice) device = g_object_ref (device_orig); |
Richard Hughes | 41cbe2a | 2017-08-08 14:13:35 +0100 | [diff] [blame] | 1862 | g_autoptr(GBytes) blob_fw2 = NULL; |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 1863 | g_autoptr(GError) error_local = NULL; |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 1864 | |
Richard Hughes | d5aab65 | 2020-02-25 12:47:50 +0000 | [diff] [blame] | 1865 | /* get per-release firmware blob */ |
| 1866 | blob_fw = xb_node_get_data (rel, "fwupd::FirmwareBlob"); |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 1867 | if (blob_fw == NULL) { |
Richard Hughes | d5aab65 | 2020-02-25 12:47:50 +0000 | [diff] [blame] | 1868 | g_set_error_literal (error, |
| 1869 | FWUPD_ERROR, |
| 1870 | FWUPD_ERROR_INTERNAL, |
| 1871 | "Failed to get firmware blob from release"); |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 1872 | return FALSE; |
| 1873 | } |
| 1874 | |
Richard Hughes | 41cbe2a | 2017-08-08 14:13:35 +0100 | [diff] [blame] | 1875 | /* use a bubblewrap helper script to build the firmware */ |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 1876 | tmp = g_object_get_data (G_OBJECT (component), "fwupd::BuilderScript"); |
Richard Hughes | 41cbe2a | 2017-08-08 14:13:35 +0100 | [diff] [blame] | 1877 | if (tmp != NULL) { |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 1878 | const gchar *tmp2 = g_object_get_data (G_OBJECT (component), "fwupd::BuilderOutput"); |
Richard Hughes | 41cbe2a | 2017-08-08 14:13:35 +0100 | [diff] [blame] | 1879 | if (tmp2 == NULL) |
| 1880 | tmp2 = "firmware.bin"; |
| 1881 | blob_fw2 = fu_common_firmware_builder (blob_fw, tmp, tmp2, error); |
| 1882 | if (blob_fw2 == NULL) |
| 1883 | return FALSE; |
| 1884 | } else { |
| 1885 | blob_fw2 = g_bytes_ref (blob_fw); |
| 1886 | } |
| 1887 | |
Richard Hughes | afca203 | 2019-02-01 18:05:30 +0000 | [diff] [blame] | 1888 | /* get the plugin */ |
| 1889 | plugin = fu_plugin_list_find_by_name (self->plugin_list, |
| 1890 | fu_device_get_plugin (device), |
| 1891 | error); |
| 1892 | if (plugin == NULL) |
| 1893 | return FALSE; |
| 1894 | |
Richard Hughes | f8e353e | 2019-03-25 14:26:57 +0000 | [diff] [blame] | 1895 | /* schedule this for the next reboot if not in system-update.target, |
| 1896 | * but first check if allowed on battery power */ |
Richard Hughes | 2c40b37 | 2019-04-17 13:41:47 +0100 | [diff] [blame] | 1897 | version_rel = fu_engine_get_release_version (self, device, rel, error); |
Richard Hughes | 0b3e9fd | 2019-04-08 11:13:20 +0100 | [diff] [blame] | 1898 | if (version_rel == NULL) { |
| 1899 | g_prefix_error (error, "failed to get release version: "); |
| 1900 | return FALSE; |
| 1901 | } |
Richard Hughes | f8e353e | 2019-03-25 14:26:57 +0000 | [diff] [blame] | 1902 | |
Richard Hughes | afca203 | 2019-02-01 18:05:30 +0000 | [diff] [blame] | 1903 | /* add device to database */ |
Richard Hughes | afca203 | 2019-02-01 18:05:30 +0000 | [diff] [blame] | 1904 | if ((flags & FWUPD_INSTALL_FLAG_NO_HISTORY) == 0) { |
Richard Hughes | 81d7a5c | 2019-03-25 14:26:04 +0000 | [diff] [blame] | 1905 | g_autoptr(FwupdRelease) release_tmp = NULL; |
| 1906 | release_tmp = fu_engine_create_release_metadata (self, plugin, error); |
| 1907 | if (release_tmp == NULL) |
Richard Hughes | afca203 | 2019-02-01 18:05:30 +0000 | [diff] [blame] | 1908 | return FALSE; |
Richard Hughes | afca203 | 2019-02-01 18:05:30 +0000 | [diff] [blame] | 1909 | tmp = xb_node_query_text (component, |
| 1910 | "releases/release/checksum[@target='container']", |
| 1911 | NULL); |
Richard Hughes | b9bbe4c | 2019-03-25 14:03:27 +0000 | [diff] [blame] | 1912 | if (tmp != NULL) |
Richard Hughes | 81d7a5c | 2019-03-25 14:26:04 +0000 | [diff] [blame] | 1913 | fwupd_release_add_checksum (release_tmp, tmp); |
| 1914 | fwupd_release_set_version (release_tmp, version_rel); |
Richard Hughes | afca203 | 2019-02-01 18:05:30 +0000 | [diff] [blame] | 1915 | fu_device_set_update_state (device, FWUPD_UPDATE_STATE_FAILED); |
Richard Hughes | 81d7a5c | 2019-03-25 14:26:04 +0000 | [diff] [blame] | 1916 | if (!fu_history_add_device (self->history, device, release_tmp, error)) |
Richard Hughes | afca203 | 2019-02-01 18:05:30 +0000 | [diff] [blame] | 1917 | return FALSE; |
| 1918 | } |
| 1919 | |
| 1920 | /* install firmware blob */ |
Richard Hughes | 84af6e7 | 2019-02-01 18:19:41 +0000 | [diff] [blame] | 1921 | version_orig = g_strdup (fu_device_get_version (device)); |
Richard Hughes | 03df0d5 | 2019-02-01 18:31:39 +0000 | [diff] [blame] | 1922 | if (!fu_engine_install_blob (self, device, blob_fw2, flags, &error_local)) { |
| 1923 | fu_device_set_status (device, FWUPD_STATUS_IDLE); |
Richard Hughes | cce6a1c | 2019-04-16 17:25:48 +0100 | [diff] [blame] | 1924 | if (g_error_matches (error_local, |
| 1925 | FWUPD_ERROR, |
Richard Hughes | 7886c08 | 2019-04-18 10:00:17 +0100 | [diff] [blame] | 1926 | FWUPD_ERROR_AC_POWER_REQUIRED) || |
| 1927 | g_error_matches (error_local, |
| 1928 | FWUPD_ERROR, |
Richard Hughes | 4266ac4 | 2019-07-11 16:49:50 +0100 | [diff] [blame] | 1929 | FWUPD_ERROR_BATTERY_LEVEL_TOO_LOW) || |
| 1930 | g_error_matches (error_local, |
| 1931 | FWUPD_ERROR, |
Mario Limonciello | 2e06dcd | 2019-10-30 19:28:52 -0500 | [diff] [blame] | 1932 | FWUPD_ERROR_NEEDS_USER_ACTION) || |
| 1933 | g_error_matches (error_local, |
| 1934 | FWUPD_ERROR, |
Richard Hughes | 7886c08 | 2019-04-18 10:00:17 +0100 | [diff] [blame] | 1935 | FWUPD_ERROR_BROKEN_SYSTEM)) { |
Richard Hughes | cce6a1c | 2019-04-16 17:25:48 +0100 | [diff] [blame] | 1936 | fu_device_set_update_state (device, FWUPD_UPDATE_STATE_FAILED_TRANSIENT); |
| 1937 | } else { |
| 1938 | fu_device_set_update_state (device, FWUPD_UPDATE_STATE_FAILED); |
| 1939 | } |
Richard Hughes | 03df0d5 | 2019-02-01 18:31:39 +0000 | [diff] [blame] | 1940 | fu_device_set_update_error (device, error_local->message); |
| 1941 | if ((flags & FWUPD_INSTALL_FLAG_NO_HISTORY) == 0 && |
Richard Hughes | 0bbef29 | 2019-11-01 12:15:15 +0000 | [diff] [blame] | 1942 | !fu_history_modify_device (self->history, device, error)) { |
Richard Hughes | 03df0d5 | 2019-02-01 18:31:39 +0000 | [diff] [blame] | 1943 | return FALSE; |
| 1944 | } |
| 1945 | g_propagate_error (error, g_steal_pointer (&error_local)); |
Richard Hughes | 84af6e7 | 2019-02-01 18:19:41 +0000 | [diff] [blame] | 1946 | return FALSE; |
Richard Hughes | 03df0d5 | 2019-02-01 18:31:39 +0000 | [diff] [blame] | 1947 | } |
Richard Hughes | 84af6e7 | 2019-02-01 18:19:41 +0000 | [diff] [blame] | 1948 | |
Richard Hughes | 68db74b | 2019-03-14 09:52:05 +0000 | [diff] [blame] | 1949 | /* the device may have changed */ |
| 1950 | device_tmp = fu_device_list_get_by_id (self->device_list, |
| 1951 | fu_device_get_id (device), |
| 1952 | error); |
| 1953 | if (device_tmp == NULL) { |
| 1954 | g_prefix_error (error, "failed to get device after install: "); |
| 1955 | return FALSE; |
| 1956 | } |
| 1957 | g_set_object (&device, device_tmp); |
| 1958 | |
Richard Hughes | 84af6e7 | 2019-02-01 18:19:41 +0000 | [diff] [blame] | 1959 | /* update database */ |
| 1960 | if (fu_device_has_flag (device, FWUPD_DEVICE_FLAG_NEEDS_REBOOT) || |
| 1961 | fu_device_has_flag (device, FWUPD_DEVICE_FLAG_NEEDS_SHUTDOWN)) { |
| 1962 | fu_device_set_update_state (device, FWUPD_UPDATE_STATE_NEEDS_REBOOT); |
| 1963 | if ((flags & FWUPD_INSTALL_FLAG_NO_HISTORY) == 0 && |
Richard Hughes | 0bbef29 | 2019-11-01 12:15:15 +0000 | [diff] [blame] | 1964 | !fu_history_modify_device (self->history, device, error)) |
Richard Hughes | 84af6e7 | 2019-02-01 18:19:41 +0000 | [diff] [blame] | 1965 | return FALSE; |
| 1966 | /* success */ |
| 1967 | return TRUE; |
| 1968 | } |
| 1969 | |
| 1970 | /* for online updates, verify the version changed if not a re-install */ |
Richard Hughes | 9a68084 | 2020-02-20 11:11:13 +0000 | [diff] [blame] | 1971 | fmt = fu_device_get_version_format (device); |
Richard Hughes | 84af6e7 | 2019-02-01 18:19:41 +0000 | [diff] [blame] | 1972 | if (version_rel != NULL && |
Richard Hughes | 9a68084 | 2020-02-20 11:11:13 +0000 | [diff] [blame] | 1973 | fu_common_vercmp_full (version_orig, version_rel, fmt) != 0 && |
| 1974 | fu_common_vercmp_full (version_orig, fu_device_get_version (device), fmt) == 0) { |
Richard Hughes | 68db74b | 2019-03-14 09:52:05 +0000 | [diff] [blame] | 1975 | g_autofree gchar *str = NULL; |
Richard Hughes | 84af6e7 | 2019-02-01 18:19:41 +0000 | [diff] [blame] | 1976 | fu_device_set_update_state (device, FWUPD_UPDATE_STATE_FAILED); |
Richard Hughes | 68db74b | 2019-03-14 09:52:05 +0000 | [diff] [blame] | 1977 | str = g_strdup_printf ("device version not updated on success, %s != %s", |
| 1978 | version_rel, fu_device_get_version (device)); |
| 1979 | fu_device_set_update_error (device, str); |
Richard Hughes | 84af6e7 | 2019-02-01 18:19:41 +0000 | [diff] [blame] | 1980 | if ((flags & FWUPD_INSTALL_FLAG_NO_HISTORY) == 0 && |
Richard Hughes | 0bbef29 | 2019-11-01 12:15:15 +0000 | [diff] [blame] | 1981 | !fu_history_modify_device (self->history, device, error)) |
Richard Hughes | 84af6e7 | 2019-02-01 18:19:41 +0000 | [diff] [blame] | 1982 | return FALSE; |
| 1983 | /* success */ |
| 1984 | return TRUE; |
| 1985 | } |
| 1986 | |
| 1987 | /* ensure the new version matched what we expected */ |
| 1988 | if (version_rel != NULL && |
| 1989 | g_strcmp0 (fu_device_get_version (device), version_rel) != 0) { |
| 1990 | g_warning ("new device version '%s' was is not '%s', fixing up", |
| 1991 | fu_device_get_version (device), version_rel); |
Richard Hughes | f50ff2c | 2020-02-25 09:45:15 +0000 | [diff] [blame] | 1992 | fu_device_set_version_format (device, fu_device_get_version_format (device)); |
| 1993 | fu_device_set_version (device, version_rel); |
Richard Hughes | 84af6e7 | 2019-02-01 18:19:41 +0000 | [diff] [blame] | 1994 | } |
| 1995 | |
| 1996 | /* success */ |
Richard Hughes | 84af6e7 | 2019-02-01 18:19:41 +0000 | [diff] [blame] | 1997 | if ((flags & FWUPD_INSTALL_FLAG_NO_HISTORY) == 0 && |
Richard Hughes | 0bbef29 | 2019-11-01 12:15:15 +0000 | [diff] [blame] | 1998 | !fu_history_modify_device (self->history, device, error)) |
Richard Hughes | 84af6e7 | 2019-02-01 18:19:41 +0000 | [diff] [blame] | 1999 | return FALSE; |
Mario Limonciello | d81ea2e | 2020-01-13 14:11:43 -0600 | [diff] [blame] | 2000 | |
| 2001 | /* make the UI update */ |
| 2002 | fu_engine_emit_changed (self); |
| 2003 | |
Richard Hughes | 84af6e7 | 2019-02-01 18:19:41 +0000 | [diff] [blame] | 2004 | return TRUE; |
Richard Hughes | 6e7419d | 2018-05-18 10:11:36 +0100 | [diff] [blame] | 2005 | } |
| 2006 | |
Richard Hughes | af14073 | 2019-12-22 18:42:12 +0000 | [diff] [blame] | 2007 | typedef struct { |
| 2008 | gboolean ret; |
| 2009 | GError **error; |
| 2010 | FuEngine *self; |
| 2011 | FuDevice *device; |
| 2012 | } FuEngineSortHelper; |
| 2013 | |
| 2014 | static gint |
| 2015 | fu_engine_sort_release_versions_cb (gconstpointer a, gconstpointer b, gpointer user_data) |
| 2016 | { |
| 2017 | FuEngineSortHelper *helper = (FuEngineSortHelper *) user_data; |
| 2018 | XbNode *na = *((XbNode **) a); |
| 2019 | XbNode *nb = *((XbNode **) b); |
| 2020 | g_autofree gchar *va = NULL; |
| 2021 | g_autofree gchar *vb = NULL; |
| 2022 | |
| 2023 | /* already failed */ |
| 2024 | if (!helper->ret) |
| 2025 | return 0; |
| 2026 | |
| 2027 | /* get the semver from the release */ |
| 2028 | va = fu_engine_get_release_version (helper->self, helper->device, na, helper->error); |
| 2029 | if (va == NULL) { |
| 2030 | g_prefix_error (helper->error, "failed to get release version: "); |
| 2031 | return 0; |
| 2032 | } |
| 2033 | vb = fu_engine_get_release_version (helper->self, helper->device, nb, helper->error); |
| 2034 | if (vb == NULL) { |
| 2035 | g_prefix_error (helper->error, "failed to get release version: "); |
| 2036 | return 0; |
| 2037 | } |
Richard Hughes | 9a68084 | 2020-02-20 11:11:13 +0000 | [diff] [blame] | 2038 | return fu_common_vercmp_full (va, vb, fu_device_get_version_format (helper->device)); |
Richard Hughes | af14073 | 2019-12-22 18:42:12 +0000 | [diff] [blame] | 2039 | } |
| 2040 | |
| 2041 | static gboolean |
| 2042 | fu_engine_sort_releases (FuEngine *self, FuDevice *device, GPtrArray *rels, GError **error) |
| 2043 | { |
| 2044 | FuEngineSortHelper helper = { |
| 2045 | .ret = TRUE, |
| 2046 | .self = self, |
| 2047 | .device = device, |
| 2048 | .error = error, |
| 2049 | }; |
| 2050 | g_ptr_array_sort_with_data (rels, fu_engine_sort_release_versions_cb, &helper); |
| 2051 | return helper.ret; |
| 2052 | } |
| 2053 | |
Richard Hughes | 8c71a3f | 2018-05-22 19:19:52 +0100 | [diff] [blame] | 2054 | /** |
Richard Hughes | 4bd2e04 | 2019-12-22 12:19:52 +0000 | [diff] [blame] | 2055 | * fu_engine_install: |
| 2056 | * @self: A #FuEngine |
| 2057 | * @task: A #FuInstallTask |
| 2058 | * @blob_cab: The #GBytes of the .cab file |
| 2059 | * @flags: The #FwupdInstallFlags, e.g. %FWUPD_DEVICE_FLAG_UPDATABLE |
| 2060 | * @error: A #GError, or %NULL |
| 2061 | * |
| 2062 | * Installs a specific firmware file on a device. |
| 2063 | * |
| 2064 | * By this point all the requirements and tests should have been done in |
| 2065 | * fu_engine_check_requirements() so this should not fail before running |
| 2066 | * the plugin loader. |
| 2067 | * |
| 2068 | * Returns: %TRUE for success |
| 2069 | **/ |
| 2070 | gboolean |
| 2071 | fu_engine_install (FuEngine *self, |
| 2072 | FuInstallTask *task, |
| 2073 | GBytes *blob_cab, |
| 2074 | FwupdInstallFlags flags, |
| 2075 | GError **error) |
| 2076 | { |
| 2077 | XbNode *component = fu_install_task_get_component (task); |
| 2078 | g_autoptr(FuDevice) device = NULL; |
| 2079 | g_autoptr(GError) error_local = NULL; |
| 2080 | g_autoptr(XbNode) rel_newest = NULL; |
| 2081 | |
| 2082 | g_return_val_if_fail (FU_IS_ENGINE (self), FALSE); |
| 2083 | g_return_val_if_fail (XB_IS_NODE (component), FALSE); |
| 2084 | g_return_val_if_fail (blob_cab != NULL, FALSE); |
| 2085 | g_return_val_if_fail (error == NULL || *error == NULL, FALSE); |
| 2086 | |
| 2087 | /* not in bootloader mode */ |
| 2088 | device = g_object_ref (fu_install_task_get_device (task)); |
| 2089 | if (fu_device_has_flag (device, FWUPD_DEVICE_FLAG_NEEDS_BOOTLOADER)) { |
| 2090 | const gchar *caption = NULL; |
| 2091 | caption = xb_node_query_text (component, |
| 2092 | "screenshots/screenshot/caption", |
| 2093 | NULL); |
| 2094 | if (caption != NULL) { |
| 2095 | g_set_error (error, |
| 2096 | FWUPD_ERROR, |
| 2097 | FWUPD_ERROR_NEEDS_USER_ACTION, |
| 2098 | "Device %s needs to manually be put in update mode: %s", |
| 2099 | fu_device_get_name (device), caption); |
| 2100 | } else { |
| 2101 | g_set_error (error, |
| 2102 | FWUPD_ERROR, |
| 2103 | FWUPD_ERROR_NEEDS_USER_ACTION, |
| 2104 | "Device %s needs to manually be put in update mode", |
| 2105 | fu_device_get_name (device)); |
| 2106 | } |
| 2107 | fu_device_set_update_state (device, FWUPD_UPDATE_STATE_FAILED_TRANSIENT); |
| 2108 | if (error != NULL) |
| 2109 | fu_device_set_update_error (device, (*error)->message); |
| 2110 | return FALSE; |
| 2111 | } |
| 2112 | |
| 2113 | /* get the newest version */ |
| 2114 | rel_newest = xb_node_query_first (component, "releases/release", &error_local); |
| 2115 | if (rel_newest == NULL) { |
| 2116 | g_set_error (error, |
| 2117 | FWUPD_ERROR, |
| 2118 | FWUPD_ERROR_INVALID_FILE, |
| 2119 | "No releases in the firmware component: %s", |
| 2120 | error_local->message); |
| 2121 | return FALSE; |
| 2122 | } |
| 2123 | |
| 2124 | /* schedule this for the next reboot if not in system-update.target, |
| 2125 | * but first check if allowed on battery power */ |
| 2126 | if ((flags & FWUPD_INSTALL_FLAG_OFFLINE) > 0 && |
| 2127 | !fu_engine_is_running_offline (self)) { |
| 2128 | FuPlugin *plugin; |
| 2129 | g_autoptr(FwupdRelease) release_tmp = NULL; |
| 2130 | g_autofree gchar *version_rel = NULL; |
| 2131 | version_rel = fu_engine_get_release_version (self, device, rel_newest, error); |
| 2132 | if (version_rel == NULL) { |
| 2133 | g_prefix_error (error, "failed to get release version: "); |
| 2134 | return FALSE; |
| 2135 | } |
| 2136 | plugin = fu_plugin_list_find_by_name (self->plugin_list, "upower", NULL); |
| 2137 | if (plugin != NULL) { |
| 2138 | if (!fu_plugin_runner_update_prepare (plugin, flags, device, error)) |
| 2139 | return FALSE; |
| 2140 | } |
| 2141 | release_tmp = fu_engine_create_release_metadata (self, plugin, error); |
| 2142 | if (release_tmp == NULL) |
| 2143 | return FALSE; |
| 2144 | fwupd_release_set_version (release_tmp, version_rel); |
| 2145 | return fu_engine_schedule_update (self, device, release_tmp, |
| 2146 | blob_cab, flags, error); |
| 2147 | } |
| 2148 | |
Richard Hughes | af14073 | 2019-12-22 18:42:12 +0000 | [diff] [blame] | 2149 | /* install each intermediate release, or install only the newest version */ |
| 2150 | if (fu_device_has_flag (device, FWUPD_DEVICE_FLAG_INSTALL_ALL_RELEASES)) { |
| 2151 | g_autoptr(GPtrArray) rels = NULL; |
| 2152 | rels = xb_node_query (component, "releases/release", 0, &error_local); |
| 2153 | if (rels == NULL) { |
| 2154 | g_set_error (error, |
| 2155 | FWUPD_ERROR, |
| 2156 | FWUPD_ERROR_INVALID_FILE, |
| 2157 | "No releases in the firmware component: %s", |
| 2158 | error_local->message); |
| 2159 | return FALSE; |
| 2160 | } |
| 2161 | if (!fu_engine_sort_releases (self, device, rels, error)) |
| 2162 | return FALSE; |
| 2163 | for (guint i = 0; i < rels->len; i++) { |
| 2164 | XbNode *rel = g_ptr_array_index (rels, i); |
| 2165 | if (!fu_engine_install_release (self, device, component, rel, flags, error)) |
| 2166 | return FALSE; |
| 2167 | } |
| 2168 | } else { |
| 2169 | if (!fu_engine_install_release (self, device, component, rel_newest, flags, error)) |
| 2170 | return FALSE; |
| 2171 | } |
Richard Hughes | 4bd2e04 | 2019-12-22 12:19:52 +0000 | [diff] [blame] | 2172 | |
| 2173 | /* success */ |
| 2174 | fu_device_set_update_state (device, FWUPD_UPDATE_STATE_SUCCESS); |
| 2175 | return TRUE; |
| 2176 | } |
| 2177 | |
| 2178 | /** |
Richard Hughes | 8c71a3f | 2018-05-22 19:19:52 +0100 | [diff] [blame] | 2179 | * fu_engine_get_plugins: |
| 2180 | * @self: A #FuPluginList |
| 2181 | * |
| 2182 | * Gets all the plugins that have been added. |
| 2183 | * |
| 2184 | * Returns: (transfer none) (element-type FuPlugin): the plugins |
| 2185 | * |
| 2186 | * Since: 1.0.8 |
| 2187 | **/ |
| 2188 | GPtrArray * |
| 2189 | fu_engine_get_plugins (FuEngine *self) |
| 2190 | { |
| 2191 | g_return_val_if_fail (FU_IS_ENGINE (self), NULL); |
| 2192 | return fu_plugin_list_get_all (self->plugin_list); |
| 2193 | } |
| 2194 | |
Richard Hughes | d583baf | 2018-11-23 13:57:22 +0000 | [diff] [blame] | 2195 | static FuDevice * |
| 2196 | fu_engine_get_device_by_id (FuEngine *self, const gchar *device_id, GError **error) |
| 2197 | { |
| 2198 | g_autoptr(FuDevice) device1 = NULL; |
| 2199 | g_autoptr(FuDevice) device2 = NULL; |
Richard Hughes | c3afed3 | 2020-03-10 16:05:29 +0000 | [diff] [blame] | 2200 | g_autoptr(FuDevice) root = NULL; |
Richard Hughes | d583baf | 2018-11-23 13:57:22 +0000 | [diff] [blame] | 2201 | |
| 2202 | /* find device */ |
| 2203 | device1 = fu_device_list_get_by_id (self->device_list, device_id, error); |
| 2204 | if (device1 == NULL) |
| 2205 | return NULL; |
| 2206 | |
Richard Hughes | d583baf | 2018-11-23 13:57:22 +0000 | [diff] [blame] | 2207 | /* wait for device to disconnect and reconnect */ |
Richard Hughes | c3afed3 | 2020-03-10 16:05:29 +0000 | [diff] [blame] | 2208 | root = fu_device_get_root (device1); |
| 2209 | if (fu_device_has_flag (device1, FWUPD_DEVICE_FLAG_WAIT_FOR_REPLUG)) { |
| 2210 | if (!fu_device_list_wait_for_replug (self->device_list, device1, error)) { |
| 2211 | g_prefix_error (error, "failed to wait for detach replug: "); |
| 2212 | return NULL; |
| 2213 | } |
| 2214 | } else if (fu_device_has_flag (root, FWUPD_DEVICE_FLAG_WAIT_FOR_REPLUG)) { |
| 2215 | if (!fu_device_list_wait_for_replug (self->device_list, root, error)) { |
| 2216 | g_prefix_error (error, "failed to wait for detach replug: "); |
| 2217 | return NULL; |
| 2218 | } |
| 2219 | } else { |
| 2220 | /* no replug required */ |
| 2221 | return g_steal_pointer (&device1); |
Richard Hughes | d583baf | 2018-11-23 13:57:22 +0000 | [diff] [blame] | 2222 | } |
| 2223 | |
| 2224 | /* get the new device */ |
| 2225 | device2 = fu_device_list_get_by_id (self->device_list, device_id, error); |
| 2226 | if (device2 == NULL) { |
| 2227 | g_prefix_error (error, "failed to get device after replug: "); |
| 2228 | return NULL; |
| 2229 | } |
| 2230 | |
| 2231 | /* success */ |
| 2232 | return g_steal_pointer (&device2); |
| 2233 | } |
| 2234 | |
Richard Hughes | 2031ce3 | 2019-10-30 14:16:24 +0000 | [diff] [blame] | 2235 | /* same as FuDevice->prepare, but with the device open */ |
| 2236 | static gboolean |
| 2237 | fu_engine_device_prepare (FuEngine *self, |
| 2238 | FuDevice *device, |
| 2239 | FwupdInstallFlags flags, |
| 2240 | GError **error) |
| 2241 | { |
| 2242 | g_autoptr(FuDeviceLocker) locker = fu_device_locker_new (device, error); |
Richard Hughes | 8bb6498 | 2020-04-16 17:03:18 +0100 | [diff] [blame] | 2243 | if (locker == NULL) { |
| 2244 | g_prefix_error (error, "failed to open device for prepare: "); |
Richard Hughes | 2031ce3 | 2019-10-30 14:16:24 +0000 | [diff] [blame] | 2245 | return FALSE; |
Richard Hughes | 8bb6498 | 2020-04-16 17:03:18 +0100 | [diff] [blame] | 2246 | } |
Richard Hughes | 2031ce3 | 2019-10-30 14:16:24 +0000 | [diff] [blame] | 2247 | return fu_device_prepare (device, flags, error); |
| 2248 | } |
| 2249 | |
| 2250 | /* same as FuDevice->cleanup, but with the device open */ |
| 2251 | static gboolean |
| 2252 | fu_engine_device_cleanup (FuEngine *self, |
| 2253 | FuDevice *device, |
| 2254 | FwupdInstallFlags flags, |
| 2255 | GError **error) |
| 2256 | { |
Mario Limonciello | e2b8a27 | 2019-11-09 22:10:35 -0600 | [diff] [blame] | 2257 | g_autoptr(FuDeviceLocker) locker = NULL; |
| 2258 | |
| 2259 | if (fu_device_has_flag (device, FWUPD_DEVICE_FLAG_WILL_DISAPPEAR)) { |
| 2260 | g_debug ("skipping device cleanup due to will-disappear flag"); |
| 2261 | return TRUE; |
| 2262 | } |
| 2263 | |
| 2264 | locker = fu_device_locker_new (device, error); |
Richard Hughes | 8bb6498 | 2020-04-16 17:03:18 +0100 | [diff] [blame] | 2265 | if (locker == NULL) { |
| 2266 | g_prefix_error (error, "failed to open device for cleanup: "); |
Richard Hughes | 2031ce3 | 2019-10-30 14:16:24 +0000 | [diff] [blame] | 2267 | return FALSE; |
Richard Hughes | 8bb6498 | 2020-04-16 17:03:18 +0100 | [diff] [blame] | 2268 | } |
Richard Hughes | 2031ce3 | 2019-10-30 14:16:24 +0000 | [diff] [blame] | 2269 | return fu_device_cleanup (device, flags, error); |
| 2270 | } |
| 2271 | |
Richard Hughes | 03df0d5 | 2019-02-01 18:31:39 +0000 | [diff] [blame] | 2272 | static gboolean |
| 2273 | fu_engine_update_prepare (FuEngine *self, |
| 2274 | FwupdInstallFlags flags, |
| 2275 | const gchar *device_id, |
| 2276 | GError **error) |
| 2277 | { |
| 2278 | GPtrArray *plugins = fu_plugin_list_get_all (self->plugin_list); |
Richard Hughes | 791c91b | 2019-10-17 13:33:30 +0100 | [diff] [blame] | 2279 | g_autofree gchar *str = NULL; |
Richard Hughes | 03df0d5 | 2019-02-01 18:31:39 +0000 | [diff] [blame] | 2280 | g_autoptr(FuDevice) device = NULL; |
| 2281 | |
| 2282 | /* the device and plugin both may have changed */ |
| 2283 | device = fu_engine_get_device_by_id (self, device_id, error); |
| 2284 | if (device == NULL) |
| 2285 | return FALSE; |
Richard Hughes | 791c91b | 2019-10-17 13:33:30 +0100 | [diff] [blame] | 2286 | str = fu_device_to_string (device); |
| 2287 | g_debug ("performing prepare on %s", str); |
Richard Hughes | 2031ce3 | 2019-10-30 14:16:24 +0000 | [diff] [blame] | 2288 | if (!fu_engine_device_prepare (self, device, flags, error)) |
Mario Limonciello | 44b9e46 | 2019-10-22 14:32:10 -0500 | [diff] [blame] | 2289 | return FALSE; |
Richard Hughes | 03df0d5 | 2019-02-01 18:31:39 +0000 | [diff] [blame] | 2290 | for (guint j = 0; j < plugins->len; j++) { |
| 2291 | FuPlugin *plugin_tmp = g_ptr_array_index (plugins, j); |
| 2292 | if (!fu_plugin_runner_update_prepare (plugin_tmp, flags, device, error)) |
| 2293 | return FALSE; |
| 2294 | } |
Richard Hughes | 802bb31 | 2019-10-17 13:32:23 +0100 | [diff] [blame] | 2295 | |
| 2296 | /* wait for device to disconnect and reconnect */ |
| 2297 | if (fu_device_has_flag (device, FWUPD_DEVICE_FLAG_WAIT_FOR_REPLUG)) { |
| 2298 | if (!fu_device_list_wait_for_replug (self->device_list, device, error)) { |
| 2299 | g_prefix_error (error, "failed to wait for prepare replug: "); |
| 2300 | return FALSE; |
| 2301 | } |
| 2302 | } |
Richard Hughes | 03df0d5 | 2019-02-01 18:31:39 +0000 | [diff] [blame] | 2303 | return TRUE; |
| 2304 | } |
| 2305 | |
| 2306 | static gboolean |
| 2307 | fu_engine_update_cleanup (FuEngine *self, |
| 2308 | FwupdInstallFlags flags, |
| 2309 | const gchar *device_id, |
| 2310 | GError **error) |
| 2311 | { |
| 2312 | GPtrArray *plugins = fu_plugin_list_get_all (self->plugin_list); |
Richard Hughes | 791c91b | 2019-10-17 13:33:30 +0100 | [diff] [blame] | 2313 | g_autofree gchar *str = NULL; |
Richard Hughes | 03df0d5 | 2019-02-01 18:31:39 +0000 | [diff] [blame] | 2314 | g_autoptr(FuDevice) device = NULL; |
| 2315 | |
| 2316 | /* the device and plugin both may have changed */ |
| 2317 | device = fu_engine_get_device_by_id (self, device_id, error); |
| 2318 | if (device == NULL) |
| 2319 | return FALSE; |
Richard Hughes | 791c91b | 2019-10-17 13:33:30 +0100 | [diff] [blame] | 2320 | str = fu_device_to_string (device); |
| 2321 | g_debug ("performing cleanup on %s", str); |
Richard Hughes | 2031ce3 | 2019-10-30 14:16:24 +0000 | [diff] [blame] | 2322 | if (!fu_engine_device_cleanup (self, device, flags, error)) |
Richard Hughes | 791c91b | 2019-10-17 13:33:30 +0100 | [diff] [blame] | 2323 | return FALSE; |
Richard Hughes | 03df0d5 | 2019-02-01 18:31:39 +0000 | [diff] [blame] | 2324 | for (guint j = 0; j < plugins->len; j++) { |
| 2325 | FuPlugin *plugin_tmp = g_ptr_array_index (plugins, j); |
| 2326 | if (!fu_plugin_runner_update_cleanup (plugin_tmp, flags, device, error)) |
| 2327 | return FALSE; |
| 2328 | } |
Richard Hughes | 802bb31 | 2019-10-17 13:32:23 +0100 | [diff] [blame] | 2329 | |
| 2330 | /* wait for device to disconnect and reconnect */ |
| 2331 | if (fu_device_has_flag (device, FWUPD_DEVICE_FLAG_WAIT_FOR_REPLUG)) { |
| 2332 | if (!fu_device_list_wait_for_replug (self->device_list, device, error)) { |
| 2333 | g_prefix_error (error, "failed to wait for cleanup replug: "); |
| 2334 | return FALSE; |
| 2335 | } |
| 2336 | } |
Richard Hughes | 03df0d5 | 2019-02-01 18:31:39 +0000 | [diff] [blame] | 2337 | return TRUE; |
| 2338 | } |
| 2339 | |
| 2340 | static gboolean |
| 2341 | fu_engine_update_detach (FuEngine *self, const gchar *device_id, GError **error) |
| 2342 | { |
| 2343 | FuPlugin *plugin; |
Richard Hughes | 791c91b | 2019-10-17 13:33:30 +0100 | [diff] [blame] | 2344 | g_autofree gchar *str = NULL; |
Richard Hughes | 03df0d5 | 2019-02-01 18:31:39 +0000 | [diff] [blame] | 2345 | g_autoptr(FuDevice) device = NULL; |
| 2346 | |
| 2347 | /* the device and plugin both may have changed */ |
| 2348 | device = fu_engine_get_device_by_id (self, device_id, error); |
| 2349 | if (device == NULL) |
| 2350 | return FALSE; |
Richard Hughes | 791c91b | 2019-10-17 13:33:30 +0100 | [diff] [blame] | 2351 | str = fu_device_to_string (device); |
| 2352 | g_debug ("performing detach on %s", str); |
Richard Hughes | 03df0d5 | 2019-02-01 18:31:39 +0000 | [diff] [blame] | 2353 | plugin = fu_plugin_list_find_by_name (self->plugin_list, |
| 2354 | fu_device_get_plugin (device), |
| 2355 | error); |
| 2356 | if (plugin == NULL) |
| 2357 | return FALSE; |
| 2358 | if (!fu_plugin_runner_update_detach (plugin, device, error)) |
| 2359 | return FALSE; |
| 2360 | return TRUE; |
| 2361 | } |
| 2362 | |
| 2363 | static gboolean |
| 2364 | fu_engine_update_attach (FuEngine *self, const gchar *device_id, GError **error) |
| 2365 | { |
| 2366 | FuPlugin *plugin; |
Richard Hughes | 791c91b | 2019-10-17 13:33:30 +0100 | [diff] [blame] | 2367 | g_autofree gchar *str = NULL; |
Richard Hughes | 03df0d5 | 2019-02-01 18:31:39 +0000 | [diff] [blame] | 2368 | g_autoptr(FuDevice) device = NULL; |
| 2369 | |
| 2370 | /* the device and plugin both may have changed */ |
| 2371 | device = fu_engine_get_device_by_id (self, device_id, error); |
| 2372 | if (device == NULL) { |
| 2373 | g_prefix_error (error, "failed to get device after update: "); |
| 2374 | return FALSE; |
| 2375 | } |
Richard Hughes | 791c91b | 2019-10-17 13:33:30 +0100 | [diff] [blame] | 2376 | str = fu_device_to_string (device); |
| 2377 | g_debug ("performing attach on %s", str); |
Richard Hughes | 03df0d5 | 2019-02-01 18:31:39 +0000 | [diff] [blame] | 2378 | plugin = fu_plugin_list_find_by_name (self->plugin_list, |
| 2379 | fu_device_get_plugin (device), |
| 2380 | error); |
| 2381 | if (plugin == NULL) |
| 2382 | return FALSE; |
Mario Limonciello | e1b4d8e | 2019-10-12 11:19:10 -0500 | [diff] [blame] | 2383 | |
Richard Hughes | 03df0d5 | 2019-02-01 18:31:39 +0000 | [diff] [blame] | 2384 | if (!fu_plugin_runner_update_attach (plugin, device, error)) |
| 2385 | return FALSE; |
| 2386 | return TRUE; |
| 2387 | } |
| 2388 | |
Mario Limonciello | 96a0dd5 | 2019-02-25 13:50:03 -0600 | [diff] [blame] | 2389 | gboolean |
| 2390 | fu_engine_activate (FuEngine *self, const gchar *device_id, GError **error) |
| 2391 | { |
| 2392 | FuPlugin *plugin; |
Richard Hughes | 791c91b | 2019-10-17 13:33:30 +0100 | [diff] [blame] | 2393 | g_autofree gchar *str = NULL; |
Mario Limonciello | 96a0dd5 | 2019-02-25 13:50:03 -0600 | [diff] [blame] | 2394 | g_autoptr(FuDevice) device = NULL; |
| 2395 | |
| 2396 | g_return_val_if_fail (FU_IS_ENGINE (self), FALSE); |
| 2397 | g_return_val_if_fail (device_id != NULL, FALSE); |
| 2398 | g_return_val_if_fail (error == NULL || *error == NULL, FALSE); |
| 2399 | |
| 2400 | /* check the device exists */ |
| 2401 | device = fu_device_list_get_by_id (self->device_list, device_id, error); |
| 2402 | if (device == NULL) |
| 2403 | return FALSE; |
Richard Hughes | 791c91b | 2019-10-17 13:33:30 +0100 | [diff] [blame] | 2404 | str = fu_device_to_string (device); |
| 2405 | g_debug ("performing activate on %s", str); |
Mario Limonciello | 96a0dd5 | 2019-02-25 13:50:03 -0600 | [diff] [blame] | 2406 | plugin = fu_plugin_list_find_by_name (self->plugin_list, |
| 2407 | fu_device_get_plugin (device), |
| 2408 | error); |
| 2409 | if (plugin == NULL) |
| 2410 | return FALSE; |
| 2411 | g_debug ("Activating %s", fu_device_get_name (device)); |
| 2412 | |
| 2413 | if (!fu_plugin_runner_activate (plugin, device, error)) |
| 2414 | return FALSE; |
| 2415 | |
| 2416 | fu_engine_emit_device_changed (self, device); |
| 2417 | fu_engine_emit_changed (self); |
| 2418 | |
| 2419 | return TRUE; |
| 2420 | } |
| 2421 | |
Richard Hughes | 03df0d5 | 2019-02-01 18:31:39 +0000 | [diff] [blame] | 2422 | static gboolean |
| 2423 | fu_engine_update_reload (FuEngine *self, const gchar *device_id, GError **error) |
| 2424 | { |
| 2425 | FuPlugin *plugin; |
Richard Hughes | 791c91b | 2019-10-17 13:33:30 +0100 | [diff] [blame] | 2426 | g_autofree gchar *str = NULL; |
Richard Hughes | 03df0d5 | 2019-02-01 18:31:39 +0000 | [diff] [blame] | 2427 | g_autoptr(FuDevice) device = NULL; |
| 2428 | |
| 2429 | /* the device and plugin both may have changed */ |
| 2430 | device = fu_engine_get_device_by_id (self, device_id, error); |
| 2431 | if (device == NULL) { |
| 2432 | g_prefix_error (error, "failed to get device after update: "); |
| 2433 | return FALSE; |
| 2434 | } |
Richard Hughes | 791c91b | 2019-10-17 13:33:30 +0100 | [diff] [blame] | 2435 | str = fu_device_to_string (device); |
| 2436 | g_debug ("performing reload on %s", str); |
Richard Hughes | 03df0d5 | 2019-02-01 18:31:39 +0000 | [diff] [blame] | 2437 | plugin = fu_plugin_list_find_by_name (self->plugin_list, |
| 2438 | fu_device_get_plugin (device), |
| 2439 | error); |
| 2440 | if (plugin == NULL) |
| 2441 | return FALSE; |
Mario Limonciello | e1b4d8e | 2019-10-12 11:19:10 -0500 | [diff] [blame] | 2442 | |
| 2443 | if (fu_device_has_flag (device, FWUPD_DEVICE_FLAG_WILL_DISAPPEAR)) { |
| 2444 | g_debug ("skipping reload due to will-disappear flag"); |
| 2445 | return TRUE; |
| 2446 | } |
| 2447 | |
Richard Hughes | 03df0d5 | 2019-02-01 18:31:39 +0000 | [diff] [blame] | 2448 | if (!fu_plugin_runner_update_reload (plugin, device, error)) { |
| 2449 | g_prefix_error (error, "failed to reload device: "); |
| 2450 | return FALSE; |
| 2451 | } |
| 2452 | return TRUE; |
| 2453 | } |
| 2454 | |
| 2455 | static gboolean |
| 2456 | fu_engine_update (FuEngine *self, |
| 2457 | const gchar *device_id, |
| 2458 | GBytes *blob_fw2, |
| 2459 | FwupdInstallFlags flags, |
| 2460 | GError **error) |
| 2461 | { |
| 2462 | FuPlugin *plugin; |
Richard Hughes | 791c91b | 2019-10-17 13:33:30 +0100 | [diff] [blame] | 2463 | g_autofree gchar *str = NULL; |
Richard Hughes | 03df0d5 | 2019-02-01 18:31:39 +0000 | [diff] [blame] | 2464 | g_autoptr(FuDevice) device = NULL; |
Richard Hughes | 019a1bc | 2019-11-26 10:19:33 +0000 | [diff] [blame] | 2465 | g_autoptr(FuDevice) device_pending = NULL; |
| 2466 | |
| 2467 | /* cancel the pending action */ |
| 2468 | if (!fu_engine_offline_invalidate (error)) |
| 2469 | return FALSE; |
Richard Hughes | 03df0d5 | 2019-02-01 18:31:39 +0000 | [diff] [blame] | 2470 | |
| 2471 | /* the device and plugin both may have changed */ |
| 2472 | device = fu_engine_get_device_by_id (self, device_id, error); |
| 2473 | if (device == NULL) { |
| 2474 | g_prefix_error (error, "failed to get device after detach: "); |
| 2475 | return FALSE; |
| 2476 | } |
Richard Hughes | 019a1bc | 2019-11-26 10:19:33 +0000 | [diff] [blame] | 2477 | device_pending = fu_history_get_device_by_id (self->history, device_id, NULL); |
Richard Hughes | 791c91b | 2019-10-17 13:33:30 +0100 | [diff] [blame] | 2478 | str = fu_device_to_string (device); |
| 2479 | g_debug ("performing update on %s", str); |
Richard Hughes | 03df0d5 | 2019-02-01 18:31:39 +0000 | [diff] [blame] | 2480 | plugin = fu_plugin_list_find_by_name (self->plugin_list, |
| 2481 | fu_device_get_plugin (device), |
| 2482 | error); |
| 2483 | if (plugin == NULL) |
| 2484 | return FALSE; |
| 2485 | if (!fu_plugin_runner_update (plugin, device, blob_fw2, flags, error)) { |
| 2486 | g_autoptr(GError) error_attach = NULL; |
| 2487 | g_autoptr(GError) error_cleanup = NULL; |
| 2488 | |
| 2489 | /* attack back into runtime then cleanup */ |
| 2490 | if (!fu_plugin_runner_update_attach (plugin, |
| 2491 | device, |
| 2492 | &error_attach)) { |
| 2493 | g_warning ("failed to attach device after failed update: %s", |
| 2494 | error_attach->message); |
| 2495 | } |
| 2496 | if (!fu_engine_update_cleanup (self, flags, device_id, &error_cleanup)) { |
| 2497 | g_warning ("failed to update-cleanup after failed update: %s", |
| 2498 | error_cleanup->message); |
| 2499 | } |
| 2500 | return FALSE; |
| 2501 | } |
Richard Hughes | 019a1bc | 2019-11-26 10:19:33 +0000 | [diff] [blame] | 2502 | |
| 2503 | /* cleanup */ |
| 2504 | if (device_pending != NULL) { |
| 2505 | const gchar *tmp; |
| 2506 | FwupdRelease *release; |
| 2507 | |
| 2508 | /* update history database */ |
| 2509 | fu_device_set_update_state (device, FWUPD_UPDATE_STATE_SUCCESS); |
| 2510 | if (!fu_history_modify_device (self->history, device, error)) |
| 2511 | return FALSE; |
| 2512 | |
| 2513 | /* delete cab file */ |
| 2514 | release = fu_device_get_release_default (device_pending); |
| 2515 | tmp = fwupd_release_get_filename (release); |
| 2516 | if (tmp != NULL && g_str_has_prefix (tmp, FWUPD_LIBEXECDIR)) { |
| 2517 | g_autoptr(GError) error_delete = NULL; |
| 2518 | g_autoptr(GFile) file = NULL; |
| 2519 | file = g_file_new_for_path (tmp); |
| 2520 | if (!g_file_delete (file, NULL, &error_delete)) { |
| 2521 | g_set_error (error, |
| 2522 | FWUPD_ERROR, |
| 2523 | FWUPD_ERROR_INVALID_FILE, |
| 2524 | "Failed to delete %s: %s", |
| 2525 | tmp, error_delete->message); |
| 2526 | return FALSE; |
| 2527 | } |
| 2528 | } |
| 2529 | } |
Richard Hughes | 03df0d5 | 2019-02-01 18:31:39 +0000 | [diff] [blame] | 2530 | return TRUE; |
| 2531 | } |
| 2532 | |
Richard Hughes | a58510b | 2019-10-30 10:03:12 +0000 | [diff] [blame] | 2533 | GBytes * |
| 2534 | fu_engine_firmware_read (FuEngine *self, |
| 2535 | FuDevice *device, |
| 2536 | FwupdInstallFlags flags, |
| 2537 | GError **error) |
| 2538 | { |
| 2539 | g_autoptr(FuDeviceLocker) locker = NULL; |
| 2540 | g_autoptr(FuFirmware) firmware = NULL; |
| 2541 | |
| 2542 | /* open, detach, read, attach, serialize */ |
| 2543 | locker = fu_device_locker_new (device, error); |
Richard Hughes | 8bb6498 | 2020-04-16 17:03:18 +0100 | [diff] [blame] | 2544 | if (locker == NULL) { |
| 2545 | g_prefix_error (error, "failed to open device for firmware read: "); |
Richard Hughes | a58510b | 2019-10-30 10:03:12 +0000 | [diff] [blame] | 2546 | return NULL; |
Richard Hughes | 8bb6498 | 2020-04-16 17:03:18 +0100 | [diff] [blame] | 2547 | } |
Richard Hughes | a58510b | 2019-10-30 10:03:12 +0000 | [diff] [blame] | 2548 | if (!fu_device_detach (device, error)) |
| 2549 | return NULL; |
| 2550 | firmware = fu_device_read_firmware (device, error); |
| 2551 | if (firmware == NULL) { |
| 2552 | g_autoptr(GError) error_local = NULL; |
| 2553 | if (!fu_device_attach (device, &error_local)) { |
| 2554 | g_warning ("failed to attach after read image failure: %s", |
| 2555 | error_local->message); |
| 2556 | } |
| 2557 | return NULL; |
| 2558 | } |
| 2559 | if (!fu_device_attach (device, error)) |
| 2560 | return NULL; |
| 2561 | return fu_firmware_write (firmware, error); |
| 2562 | } |
| 2563 | |
Richard Hughes | 6e7419d | 2018-05-18 10:11:36 +0100 | [diff] [blame] | 2564 | gboolean |
| 2565 | fu_engine_install_blob (FuEngine *self, |
Richard Hughes | 03df0d5 | 2019-02-01 18:31:39 +0000 | [diff] [blame] | 2566 | FuDevice *device, |
| 2567 | GBytes *blob_fw, |
Richard Hughes | 6e7419d | 2018-05-18 10:11:36 +0100 | [diff] [blame] | 2568 | FwupdInstallFlags flags, |
| 2569 | GError **error) |
| 2570 | { |
Richard Hughes | 5297678 | 2019-02-01 21:23:01 +0000 | [diff] [blame] | 2571 | guint retries = 0; |
Richard Hughes | 03df0d5 | 2019-02-01 18:31:39 +0000 | [diff] [blame] | 2572 | g_autofree gchar *device_id = NULL; |
Mario Limonciello | 4afe7fb | 2018-08-05 23:14:39 -0500 | [diff] [blame] | 2573 | g_autoptr(GTimer) timer = g_timer_new (); |
Richard Hughes | 6e7419d | 2018-05-18 10:11:36 +0100 | [diff] [blame] | 2574 | |
Richard Hughes | adcc16a | 2017-08-21 12:26:46 +0100 | [diff] [blame] | 2575 | /* test the firmware is not an empty blob */ |
Richard Hughes | 03df0d5 | 2019-02-01 18:31:39 +0000 | [diff] [blame] | 2576 | if (g_bytes_get_size (blob_fw) == 0) { |
Richard Hughes | adcc16a | 2017-08-21 12:26:46 +0100 | [diff] [blame] | 2577 | g_set_error (error, |
| 2578 | FWUPD_ERROR, |
| 2579 | FWUPD_ERROR_INVALID_FILE, |
| 2580 | "Firmware is invalid as has zero size"); |
| 2581 | return FALSE; |
| 2582 | } |
| 2583 | |
Richard Hughes | bc3a4e1 | 2018-01-06 22:41:47 +0000 | [diff] [blame] | 2584 | /* mark this as modified even if we actually fail to do the update */ |
| 2585 | fu_device_set_modified (device, (guint64) g_get_real_time () / G_USEC_PER_SEC); |
| 2586 | |
Richard Hughes | 5297678 | 2019-02-01 21:23:01 +0000 | [diff] [blame] | 2587 | /* plugins can set FWUPD_DEVICE_FLAG_ANOTHER_WRITE_REQUIRED to run again, but they |
| 2588 | * must return TRUE rather than an error */ |
Richard Hughes | 03df0d5 | 2019-02-01 18:31:39 +0000 | [diff] [blame] | 2589 | device_id = g_strdup (fu_device_get_id (device)); |
Richard Hughes | 5297678 | 2019-02-01 21:23:01 +0000 | [diff] [blame] | 2590 | do { |
| 2591 | /* check for a loop */ |
| 2592 | if (++retries > 5) { |
| 2593 | g_set_error_literal (error, |
| 2594 | FWUPD_ERROR, |
| 2595 | FWUPD_ERROR_INTERNAL, |
| 2596 | "aborting device write loop, limit 5"); |
| 2597 | return FALSE; |
| 2598 | } |
Aleksander Morgado | 37b985c | 2019-01-20 11:23:32 +0100 | [diff] [blame] | 2599 | |
Richard Hughes | 5297678 | 2019-02-01 21:23:01 +0000 | [diff] [blame] | 2600 | /* don't rely on a plugin clearing this */ |
| 2601 | fu_device_remove_flag (device, FWUPD_DEVICE_FLAG_ANOTHER_WRITE_REQUIRED); |
Richard Hughes | bc3a4e1 | 2018-01-06 22:41:47 +0000 | [diff] [blame] | 2602 | |
Richard Hughes | 5297678 | 2019-02-01 21:23:01 +0000 | [diff] [blame] | 2603 | /* signal to all the plugins the update is about to happen */ |
| 2604 | if (!fu_engine_update_prepare (self, flags, device_id, error)) |
| 2605 | return FALSE; |
Richard Hughes | bc3a4e1 | 2018-01-06 22:41:47 +0000 | [diff] [blame] | 2606 | |
Richard Hughes | 5297678 | 2019-02-01 21:23:01 +0000 | [diff] [blame] | 2607 | /* detach to bootloader mode */ |
| 2608 | if (!fu_engine_update_detach (self, device_id, error)) |
| 2609 | return FALSE; |
| 2610 | |
| 2611 | /* install */ |
| 2612 | if (!fu_engine_update (self, device_id, blob_fw, flags, error)) |
| 2613 | return FALSE; |
| 2614 | |
| 2615 | /* attach into runtime mode */ |
| 2616 | if (!fu_engine_update_attach (self, device_id, error)) |
| 2617 | return FALSE; |
| 2618 | |
| 2619 | } while (fu_device_has_flag (device, FWUPD_DEVICE_FLAG_ANOTHER_WRITE_REQUIRED)); |
Aleksander Morgado | 37b985c | 2019-01-20 11:23:32 +0100 | [diff] [blame] | 2620 | |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 2621 | /* get the new version number */ |
Richard Hughes | 03df0d5 | 2019-02-01 18:31:39 +0000 | [diff] [blame] | 2622 | if (!fu_engine_update_reload (self, device_id, error)) |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 2623 | return FALSE; |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 2624 | |
| 2625 | /* signal to all the plugins the update has happened */ |
Richard Hughes | 03df0d5 | 2019-02-01 18:31:39 +0000 | [diff] [blame] | 2626 | if (!fu_engine_update_cleanup (self, flags, device_id, error)) |
| 2627 | return FALSE; |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 2628 | |
| 2629 | /* make the UI update */ |
Richard Hughes | 7772dcf | 2018-09-10 15:49:59 +0100 | [diff] [blame] | 2630 | fu_engine_set_status (self, FWUPD_STATUS_IDLE); |
Mario Limonciello | 4afe7fb | 2018-08-05 23:14:39 -0500 | [diff] [blame] | 2631 | g_debug ("Updating %s took %f seconds", fu_device_get_name (device), |
| 2632 | g_timer_elapsed (timer, NULL)); |
Richard Hughes | 76e0f94 | 2018-05-14 16:24:00 +0100 | [diff] [blame] | 2633 | return TRUE; |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 2634 | } |
| 2635 | |
Richard Hughes | 0a7e783 | 2017-11-22 11:01:13 +0000 | [diff] [blame] | 2636 | static FuDevice * |
Richard Hughes | bc3a4e1 | 2018-01-06 22:41:47 +0000 | [diff] [blame] | 2637 | fu_engine_get_item_by_id_fallback_history (FuEngine *self, const gchar *id, GError **error) |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 2638 | { |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 2639 | g_autoptr(GPtrArray) devices = NULL; |
| 2640 | |
| 2641 | /* not a wildcard */ |
Richard Hughes | 65e44ca | 2018-01-30 17:26:30 +0000 | [diff] [blame] | 2642 | if (g_strcmp0 (id, FWUPD_DEVICE_ID_ANY) != 0) { |
| 2643 | g_autoptr(FuDevice) dev = NULL; |
| 2644 | g_autoptr(GError) error_local = NULL; |
| 2645 | |
| 2646 | /* get this one device */ |
| 2647 | dev = fu_history_get_device_by_id (self->history, id, &error_local); |
| 2648 | if (dev == NULL) { |
| 2649 | g_set_error (error, |
| 2650 | FWUPD_ERROR, |
| 2651 | FWUPD_ERROR_NOTHING_TO_DO, |
| 2652 | "Failed to find %s in history database: %s", |
| 2653 | id, error_local->message); |
| 2654 | return NULL; |
| 2655 | } |
| 2656 | |
| 2657 | /* only useful */ |
| 2658 | if (fu_device_get_update_state (dev) == FWUPD_UPDATE_STATE_SUCCESS || |
Richard Hughes | cce6a1c | 2019-04-16 17:25:48 +0100 | [diff] [blame] | 2659 | fu_device_get_update_state (dev) == FWUPD_UPDATE_STATE_FAILED_TRANSIENT || |
Richard Hughes | 65e44ca | 2018-01-30 17:26:30 +0000 | [diff] [blame] | 2660 | fu_device_get_update_state (dev) == FWUPD_UPDATE_STATE_FAILED) { |
| 2661 | return g_steal_pointer (&dev); |
| 2662 | } |
| 2663 | |
| 2664 | /* nothing in database */ |
| 2665 | g_set_error (error, |
| 2666 | FWUPD_ERROR, |
| 2667 | FWUPD_ERROR_NOTHING_TO_DO, |
| 2668 | "Device %s has no results to report", |
| 2669 | fu_device_get_id (dev)); |
| 2670 | return NULL; |
| 2671 | } |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 2672 | |
| 2673 | /* allow '*' for any */ |
Richard Hughes | bc3a4e1 | 2018-01-06 22:41:47 +0000 | [diff] [blame] | 2674 | devices = fu_history_get_devices (self->history, error); |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 2675 | if (devices == NULL) |
| 2676 | return NULL; |
| 2677 | for (guint i = 0; i < devices->len; i++) { |
Richard Hughes | 65e44ca | 2018-01-30 17:26:30 +0000 | [diff] [blame] | 2678 | FuDevice *dev = g_ptr_array_index (devices, i); |
| 2679 | if (fu_device_get_update_state (dev) == FWUPD_UPDATE_STATE_SUCCESS || |
Richard Hughes | cce6a1c | 2019-04-16 17:25:48 +0100 | [diff] [blame] | 2680 | fu_device_get_update_state (dev) == FWUPD_UPDATE_STATE_FAILED_TRANSIENT || |
Richard Hughes | 65e44ca | 2018-01-30 17:26:30 +0000 | [diff] [blame] | 2681 | fu_device_get_update_state (dev) == FWUPD_UPDATE_STATE_FAILED) |
| 2682 | return g_object_ref (dev); |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 2683 | } |
Richard Hughes | 65e44ca | 2018-01-30 17:26:30 +0000 | [diff] [blame] | 2684 | g_set_error_literal (error, |
| 2685 | FWUPD_ERROR, |
| 2686 | FWUPD_ERROR_NOTHING_TO_DO, |
| 2687 | "Failed to find any useful results to report"); |
| 2688 | return NULL; |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 2689 | } |
| 2690 | |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 2691 | /* for the self tests */ |
| 2692 | void |
| 2693 | fu_engine_set_silo (FuEngine *self, XbSilo *silo) |
Richard Hughes | bd4d285 | 2017-09-13 14:05:14 +0100 | [diff] [blame] | 2694 | { |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 2695 | g_return_if_fail (FU_IS_ENGINE (self)); |
| 2696 | g_return_if_fail (XB_IS_SILO (silo)); |
| 2697 | g_set_object (&self->silo, silo); |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 2698 | } |
| 2699 | |
| 2700 | static gboolean |
Richard Hughes | 1af48b1 | 2018-12-03 11:51:17 +0000 | [diff] [blame] | 2701 | fu_engine_appstream_upgrade_cb (XbBuilderFixup *self, |
| 2702 | XbBuilderNode *bn, |
| 2703 | gpointer user_data, |
| 2704 | GError **error) |
| 2705 | { |
| 2706 | if (g_strcmp0 (xb_builder_node_get_element (bn), "metadata") == 0) |
| 2707 | xb_builder_node_set_element (bn, "custom"); |
| 2708 | return TRUE; |
| 2709 | } |
| 2710 | |
Mario Limonciello | 4f24d0b | 2019-01-26 01:19:59 -0600 | [diff] [blame] | 2711 | static XbBuilderSource * |
| 2712 | fu_engine_create_metadata_builder_source (FuEngine *self, |
| 2713 | const gchar *fn, |
| 2714 | GError **error) |
| 2715 | { |
| 2716 | g_autoptr(GBytes) blob = NULL; |
| 2717 | g_autoptr(XbSilo) silo = NULL; |
| 2718 | g_autoptr(XbBuilderSource) source = xb_builder_source_new (); |
| 2719 | g_autofree gchar *xml = NULL; |
| 2720 | |
| 2721 | g_debug ("building metadata for %s", fn); |
| 2722 | blob = fu_common_get_contents_bytes (fn, error); |
| 2723 | if (blob == NULL) |
| 2724 | return NULL; |
| 2725 | |
| 2726 | /* convert the silo for the CAB into a XbBuilderSource */ |
| 2727 | silo = fu_engine_get_silo_from_blob (self, blob, error); |
| 2728 | if (silo == NULL) |
| 2729 | return NULL; |
| 2730 | xml = xb_silo_export (silo, XB_NODE_EXPORT_FLAG_NONE, error); |
| 2731 | if (xml == NULL) |
| 2732 | return NULL; |
| 2733 | if (!xb_builder_source_load_xml (source, xml, |
| 2734 | XB_BUILDER_SOURCE_FLAG_NONE, |
| 2735 | error)) |
| 2736 | return NULL; |
| 2737 | return g_steal_pointer (&source); |
| 2738 | } |
| 2739 | |
| 2740 | static gboolean |
| 2741 | fu_engine_create_metadata (FuEngine *self, XbBuilder *builder, |
| 2742 | FwupdRemote *remote, GError **error) |
| 2743 | { |
| 2744 | g_autoptr(GPtrArray) files = NULL; |
| 2745 | const gchar *path; |
| 2746 | |
| 2747 | /* find all files in directory */ |
| 2748 | path = fwupd_remote_get_filename_cache (remote); |
| 2749 | files = fu_common_get_files_recursive (path, error); |
| 2750 | if (files == NULL) |
| 2751 | return FALSE; |
| 2752 | |
| 2753 | /* add each source */ |
| 2754 | for (guint i = 0; i < files->len; i++) { |
| 2755 | g_autoptr(XbBuilderNode) custom = NULL; |
| 2756 | g_autoptr(XbBuilderSource) source = NULL; |
| 2757 | g_autoptr(GError) error_local = NULL; |
| 2758 | const gchar *fn = g_ptr_array_index (files, i); |
Crag Wang | ae42298 | 2020-03-05 23:42:53 +0800 | [diff] [blame] | 2759 | g_autofree gchar *fn_lowercase = g_ascii_strdown (fn, -1); |
Mario Limonciello | 4f24d0b | 2019-01-26 01:19:59 -0600 | [diff] [blame] | 2760 | |
| 2761 | /* check is cab file */ |
Crag Wang | ae42298 | 2020-03-05 23:42:53 +0800 | [diff] [blame] | 2762 | if (!g_str_has_suffix (fn_lowercase, ".cab")) { |
Mario Limonciello | 4f24d0b | 2019-01-26 01:19:59 -0600 | [diff] [blame] | 2763 | g_debug ("ignoring: %s", fn); |
| 2764 | continue; |
| 2765 | } |
| 2766 | |
| 2767 | /* build source for file */ |
| 2768 | source = fu_engine_create_metadata_builder_source (self, fn, &error_local); |
| 2769 | if (source == NULL) { |
| 2770 | g_warning ("%s", error_local->message); |
| 2771 | continue; |
| 2772 | } |
| 2773 | |
| 2774 | /* add metadata */ |
| 2775 | custom = xb_builder_node_new ("custom"); |
| 2776 | xb_builder_node_insert_text (custom, |
| 2777 | "value", fn, |
| 2778 | "key", "fwupd::FilenameCache", |
| 2779 | NULL); |
| 2780 | xb_builder_node_insert_text (custom, |
| 2781 | "value", fwupd_remote_get_id (remote), |
| 2782 | "key", "fwupd::RemoteId", |
| 2783 | NULL); |
| 2784 | xb_builder_source_set_info (source, custom); |
| 2785 | xb_builder_import_source (builder, source); |
| 2786 | } |
| 2787 | return TRUE; |
| 2788 | } |
| 2789 | |
Richard Hughes | f43381f | 2020-02-24 10:11:31 +0000 | [diff] [blame] | 2790 | static void |
Richard Hughes | 1ee1800 | 2020-03-31 21:46:49 +0100 | [diff] [blame] | 2791 | fu_engine_ensure_device_supported (FuEngine *self, FuDevice *device) |
Richard Hughes | f43381f | 2020-02-24 10:11:31 +0000 | [diff] [blame] | 2792 | { |
Richard Hughes | 1ee1800 | 2020-03-31 21:46:49 +0100 | [diff] [blame] | 2793 | gboolean is_supported = FALSE; |
| 2794 | g_autoptr(GError) error = NULL; |
| 2795 | g_autoptr(GPtrArray) releases = NULL; |
| 2796 | |
| 2797 | /* get all releases that pass the requirements */ |
| 2798 | releases = fu_engine_get_releases_for_device (self, |
| 2799 | device, |
| 2800 | &error); |
| 2801 | if (releases == NULL) { |
| 2802 | if (!g_error_matches (error, |
| 2803 | FWUPD_ERROR, |
| 2804 | FWUPD_ERROR_NOTHING_TO_DO) && |
| 2805 | !g_error_matches (error, |
| 2806 | FWUPD_ERROR, |
| 2807 | FWUPD_ERROR_NOT_SUPPORTED)) { |
| 2808 | g_warning ("failed to get releases for %s: %s", |
| 2809 | fu_device_get_name (device), |
| 2810 | error->message); |
| 2811 | } |
| 2812 | } else { |
| 2813 | if (releases->len > 0) |
| 2814 | is_supported = TRUE; |
| 2815 | } |
| 2816 | |
Richard Hughes | f43381f | 2020-02-24 10:11:31 +0000 | [diff] [blame] | 2817 | /* was supported, now unsupported */ |
Richard Hughes | 1ee1800 | 2020-03-31 21:46:49 +0100 | [diff] [blame] | 2818 | if (!is_supported) { |
Richard Hughes | f43381f | 2020-02-24 10:11:31 +0000 | [diff] [blame] | 2819 | if (fu_device_has_flag (device, FWUPD_DEVICE_FLAG_SUPPORTED)) { |
| 2820 | fu_device_remove_flag (device, FWUPD_DEVICE_FLAG_SUPPORTED); |
| 2821 | fu_engine_emit_device_changed (self, device); |
| 2822 | } |
| 2823 | return; |
| 2824 | } |
| 2825 | |
| 2826 | /* was unsupported, now supported */ |
| 2827 | if (!fu_device_has_flag (device, FWUPD_DEVICE_FLAG_SUPPORTED)) { |
| 2828 | fu_device_add_flag (device, FWUPD_DEVICE_FLAG_SUPPORTED); |
| 2829 | fu_engine_emit_device_changed (self, device); |
| 2830 | } |
| 2831 | } |
| 2832 | |
| 2833 | static void |
| 2834 | fu_engine_md_refresh_device_name (FuEngine *self, FuDevice *device, XbNode *component) |
| 2835 | { |
| 2836 | const gchar *name = NULL; |
| 2837 | |
| 2838 | /* require data */ |
| 2839 | if (component == NULL) |
| 2840 | return; |
| 2841 | |
| 2842 | /* copy 1:1 */ |
| 2843 | name = xb_node_query_text (component, "name", NULL); |
| 2844 | if (name != NULL) |
| 2845 | fu_device_set_name (device, name); |
| 2846 | } |
| 2847 | |
| 2848 | static const gchar * |
| 2849 | fu_common_device_category_to_name (const gchar *cat) |
| 2850 | { |
| 2851 | if (g_strcmp0 (cat, "X-EmbeddedController") == 0) |
| 2852 | return "Embedded Controller"; |
| 2853 | if (g_strcmp0 (cat, "X-ManagementEngine") == 0) |
| 2854 | return "Intel Management Engine"; |
| 2855 | if (g_strcmp0 (cat, "X-CorporateManagementEngine") == 0) |
| 2856 | return "Intel Management Engine"; |
| 2857 | if (g_strcmp0 (cat, "X-ConsumerManagementEngine") == 0) |
| 2858 | return "Intel Management Engine"; |
| 2859 | if (g_strcmp0 (cat, "X-ThunderboltController") == 0) |
| 2860 | return "Thunderbolt Controller"; |
| 2861 | if (g_strcmp0 (cat, "X-PlatformSecurityProcessor") == 0) |
| 2862 | return "Platform Security Processor"; |
Mario Limonciello | 7a9bb7e | 2020-04-02 10:28:41 -0500 | [diff] [blame] | 2863 | if (g_strcmp0 (cat, "X-CpuMicrocode") == 0) |
| 2864 | return "CPU Microcode"; |
Richard Hughes | f43381f | 2020-02-24 10:11:31 +0000 | [diff] [blame] | 2865 | return NULL; |
| 2866 | } |
| 2867 | |
| 2868 | static void |
| 2869 | fu_engine_md_refresh_device_name_category (FuEngine *self, FuDevice *device, XbNode *component) |
| 2870 | { |
| 2871 | const gchar *name = NULL; |
| 2872 | g_autoptr(GPtrArray) cats = NULL; |
| 2873 | |
| 2874 | /* require data */ |
| 2875 | if (component == NULL) |
| 2876 | return; |
| 2877 | |
| 2878 | /* get AppStream and safe-compat categories */ |
| 2879 | cats = xb_node_query (component, "categories/category|X-categories/category", 0, NULL); |
| 2880 | if (cats == NULL) |
| 2881 | return; |
| 2882 | for (guint i = 0; i < cats->len; i++) { |
| 2883 | XbNode *n = g_ptr_array_index (cats, i); |
| 2884 | name = fu_common_device_category_to_name (xb_node_get_text (n)); |
| 2885 | if (name != NULL) |
| 2886 | break; |
| 2887 | } |
| 2888 | if (name != NULL) |
| 2889 | fu_device_set_name (device, name); |
| 2890 | } |
| 2891 | |
| 2892 | static void |
Richard Hughes | b097603 | 2020-02-24 14:17:04 +0000 | [diff] [blame] | 2893 | _g_ptr_array_reverse (GPtrArray *array) |
| 2894 | { |
| 2895 | guint last_idx = array->len - 1; |
| 2896 | for (guint i = 0; i < array->len / 2; i++) { |
| 2897 | gpointer tmp = array->pdata[i]; |
| 2898 | array->pdata[i] = array->pdata[last_idx - i]; |
| 2899 | array->pdata[last_idx - i] = tmp; |
| 2900 | } |
| 2901 | } |
| 2902 | |
| 2903 | static void |
| 2904 | fu_engine_md_refresh_device_verfmt (FuEngine *self, FuDevice *device, XbNode *component) |
| 2905 | { |
| 2906 | FwupdVersionFormat verfmt = FWUPD_VERSION_FORMAT_UNKNOWN; |
| 2907 | g_autoptr(GPtrArray) verfmts = NULL; |
| 2908 | |
| 2909 | /* require data */ |
| 2910 | if (component == NULL) |
| 2911 | return; |
| 2912 | |
| 2913 | /* get metadata */ |
| 2914 | verfmts = xb_node_query (component, "custom/value[@key='LVFS::VersionFormat']", 0, NULL); |
| 2915 | if (verfmts == NULL) |
| 2916 | return; |
| 2917 | _g_ptr_array_reverse (verfmts); |
| 2918 | for (guint i = 0; i < verfmts->len; i++) { |
| 2919 | XbNode *value = g_ptr_array_index (verfmts, i); |
| 2920 | verfmt = fwupd_version_format_from_string (xb_node_get_text (value)); |
| 2921 | if (verfmt != FWUPD_VERSION_FORMAT_UNKNOWN) |
| 2922 | break; |
| 2923 | } |
| 2924 | |
| 2925 | /* found and different to existing */ |
| 2926 | if (verfmt != FWUPD_VERSION_FORMAT_UNKNOWN && |
| 2927 | fu_device_get_version_format (device) != verfmt) { |
| 2928 | fu_device_set_version_format (device, verfmt); |
| 2929 | if (fu_device_get_version_raw (device) != 0x0) { |
| 2930 | g_autofree gchar *version = NULL; |
| 2931 | version = fu_common_version_from_uint32 (fu_device_get_version_raw (device), verfmt); |
| 2932 | fu_device_set_version (device, version); |
| 2933 | } |
| 2934 | if (fu_device_get_version_lowest_raw (device) != 0x0) { |
| 2935 | g_autofree gchar *version = NULL; |
| 2936 | version = fu_common_version_from_uint32 (fu_device_get_version_lowest_raw (device), verfmt); |
| 2937 | fu_device_set_version_lowest (device, version); |
| 2938 | } |
| 2939 | if (fu_device_get_version_bootloader_raw (device) != 0x0) { |
| 2940 | g_autofree gchar *version = NULL; |
| 2941 | version = fu_common_version_from_uint32 (fu_device_get_version_bootloader_raw (device), verfmt); |
| 2942 | fu_device_set_version_bootloader (device, version); |
| 2943 | } |
| 2944 | } |
| 2945 | } |
| 2946 | |
Mario Limonciello | 537da0e | 2020-03-09 15:38:17 -0500 | [diff] [blame] | 2947 | void |
Mario Limonciello | f430da0 | 2020-03-09 14:03:03 -0500 | [diff] [blame] | 2948 | fu_engine_md_refresh_device_from_component (FuEngine *self, FuDevice *device, XbNode *component) |
Richard Hughes | f43381f | 2020-02-24 10:11:31 +0000 | [diff] [blame] | 2949 | { |
Richard Hughes | f43381f | 2020-02-24 10:11:31 +0000 | [diff] [blame] | 2950 | /* set the name */ |
| 2951 | if (fu_device_has_flag (device, FWUPD_DEVICE_FLAG_MD_SET_NAME)) |
| 2952 | fu_engine_md_refresh_device_name (self, device, component); |
| 2953 | if (fu_device_has_flag (device, FWUPD_DEVICE_FLAG_MD_SET_NAME_CATEGORY)) |
| 2954 | fu_engine_md_refresh_device_name_category (self, device, component); |
Richard Hughes | b097603 | 2020-02-24 14:17:04 +0000 | [diff] [blame] | 2955 | |
| 2956 | /* fix the version */ |
| 2957 | if (fu_device_has_flag (device, FWUPD_DEVICE_FLAG_MD_SET_VERFMT)) |
| 2958 | fu_engine_md_refresh_device_verfmt (self, device, component); |
Richard Hughes | f43381f | 2020-02-24 10:11:31 +0000 | [diff] [blame] | 2959 | } |
| 2960 | |
| 2961 | static void |
| 2962 | fu_engine_md_refresh_devices (FuEngine *self) |
| 2963 | { |
| 2964 | g_autoptr(GPtrArray) devices = fu_device_list_get_all (self->device_list); |
| 2965 | for (guint i = 0; i < devices->len; i++) { |
| 2966 | FuDevice *device = g_ptr_array_index (devices, i); |
Mario Limonciello | f430da0 | 2020-03-09 14:03:03 -0500 | [diff] [blame] | 2967 | g_autoptr(XbNode) component = fu_engine_get_component_by_guids (self, device); |
Mario Limonciello | 537da0e | 2020-03-09 15:38:17 -0500 | [diff] [blame] | 2968 | |
| 2969 | /* set or clear the SUPPORTED flag */ |
Richard Hughes | 1ee1800 | 2020-03-31 21:46:49 +0100 | [diff] [blame] | 2970 | fu_engine_ensure_device_supported (self, device); |
Mario Limonciello | 537da0e | 2020-03-09 15:38:17 -0500 | [diff] [blame] | 2971 | |
| 2972 | /* fixup the name and format as needed */ |
Mario Limonciello | f430da0 | 2020-03-09 14:03:03 -0500 | [diff] [blame] | 2973 | fu_engine_md_refresh_device_from_component (self, device, component); |
Richard Hughes | f43381f | 2020-02-24 10:11:31 +0000 | [diff] [blame] | 2974 | } |
| 2975 | } |
| 2976 | |
Richard Hughes | 1af48b1 | 2018-12-03 11:51:17 +0000 | [diff] [blame] | 2977 | static gboolean |
Richard Hughes | c8cc77c | 2019-03-07 11:57:24 +0000 | [diff] [blame] | 2978 | fu_engine_load_metadata_store (FuEngine *self, FuEngineLoadFlags flags, GError **error) |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 2979 | { |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 2980 | GPtrArray *remotes; |
Richard Hughes | c8cc77c | 2019-03-07 11:57:24 +0000 | [diff] [blame] | 2981 | XbBuilderCompileFlags compile_flags = XB_BUILDER_COMPILE_FLAG_IGNORE_INVALID; |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 2982 | g_autofree gchar *cachedirpkg = NULL; |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 2983 | g_autofree gchar *xmlbfn = NULL; |
| 2984 | g_autoptr(GFile) xmlb = NULL; |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 2985 | g_autoptr(GPtrArray) components = NULL; |
| 2986 | g_autoptr(XbBuilder) builder = xb_builder_new (); |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 2987 | |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 2988 | /* clear existing silo */ |
| 2989 | g_clear_object (&self->silo); |
| 2990 | |
| 2991 | /* verbose profiling */ |
| 2992 | if (g_getenv ("FWUPD_VERBOSE") != NULL) { |
| 2993 | xb_builder_set_profile_flags (builder, |
| 2994 | XB_SILO_PROFILE_FLAG_XPATH | |
| 2995 | XB_SILO_PROFILE_FLAG_DEBUG); |
| 2996 | } |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 2997 | |
| 2998 | /* load each enabled metadata file */ |
Richard Hughes | d1808aa | 2019-12-10 15:20:30 +0000 | [diff] [blame] | 2999 | remotes = fu_remote_list_get_all (self->remote_list); |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3000 | for (guint i = 0; i < remotes->len; i++) { |
| 3001 | const gchar *path = NULL; |
Richard Hughes | 5f733f2 | 2017-11-26 16:14:20 +0000 | [diff] [blame] | 3002 | g_autoptr(GError) error_local = NULL; |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 3003 | g_autoptr(GFile) file = NULL; |
Richard Hughes | 1af48b1 | 2018-12-03 11:51:17 +0000 | [diff] [blame] | 3004 | g_autoptr(XbBuilderFixup) fixup = NULL; |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 3005 | g_autoptr(XbBuilderNode) custom = NULL; |
| 3006 | g_autoptr(XbBuilderSource) source = xb_builder_source_new (); |
| 3007 | |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3008 | FwupdRemote *remote = g_ptr_array_index (remotes, i); |
| 3009 | if (!fwupd_remote_get_enabled (remote)) { |
| 3010 | g_debug ("remote %s not enabled, so skipping", |
| 3011 | fwupd_remote_get_id (remote)); |
| 3012 | continue; |
| 3013 | } |
| 3014 | path = fwupd_remote_get_filename_cache (remote); |
| 3015 | if (!g_file_test (path, G_FILE_TEST_EXISTS)) { |
| 3016 | g_debug ("no %s, so skipping", path); |
| 3017 | continue; |
| 3018 | } |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 3019 | |
Mario Limonciello | 4f24d0b | 2019-01-26 01:19:59 -0600 | [diff] [blame] | 3020 | /* generate all metadata on demand */ |
| 3021 | if (fwupd_remote_get_kind (remote) == FWUPD_REMOTE_KIND_DIRECTORY) { |
| 3022 | g_debug ("building metadata for remote '%s'", |
| 3023 | fwupd_remote_get_id (remote)); |
| 3024 | if (!fu_engine_create_metadata (self, builder, remote, &error_local)) { |
| 3025 | g_warning ("failed to generate remote %s: %s", |
| 3026 | fwupd_remote_get_id (remote), |
| 3027 | error_local->message); |
| 3028 | } |
| 3029 | continue; |
| 3030 | } |
| 3031 | |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 3032 | /* save the remote-id in the custom metadata space */ |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 3033 | file = g_file_new_for_path (path); |
| 3034 | if (!xb_builder_source_load_file (source, file, |
| 3035 | XB_BUILDER_SOURCE_FLAG_NONE, |
| 3036 | NULL, &error_local)) { |
Richard Hughes | 068d343 | 2017-09-16 08:26:46 +0100 | [diff] [blame] | 3037 | g_warning ("failed to load remote %s: %s", |
| 3038 | fwupd_remote_get_id (remote), |
| 3039 | error_local->message); |
| 3040 | continue; |
| 3041 | } |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 3042 | |
Richard Hughes | 1af48b1 | 2018-12-03 11:51:17 +0000 | [diff] [blame] | 3043 | /* fix up any legacy installed files */ |
| 3044 | fixup = xb_builder_fixup_new ("AppStreamUpgrade", |
| 3045 | fu_engine_appstream_upgrade_cb, |
| 3046 | self, NULL); |
| 3047 | xb_builder_fixup_set_max_depth (fixup, 3); |
| 3048 | xb_builder_source_add_fixup (source, fixup); |
| 3049 | |
Richard Hughes | 33171fd | 2018-11-09 13:29:11 +0000 | [diff] [blame] | 3050 | /* add metadata */ |
| 3051 | custom = xb_builder_node_new ("custom"); |
| 3052 | xb_builder_node_insert_text (custom, |
| 3053 | "value", path, |
| 3054 | "key", "fwupd::FilenameCache", |
| 3055 | NULL); |
| 3056 | xb_builder_node_insert_text (custom, |
| 3057 | "value", fwupd_remote_get_id (remote), |
| 3058 | "key", "fwupd::RemoteId", |
| 3059 | NULL); |
| 3060 | xb_builder_source_set_info (source, custom); |
| 3061 | |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 3062 | /* we need to watch for changes? */ |
| 3063 | xb_builder_import_source (builder, source); |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3064 | } |
| 3065 | |
Richard Hughes | 88dc0f4 | 2019-03-07 11:58:11 +0000 | [diff] [blame] | 3066 | /* on a read-only filesystem don't care about the cache GUID */ |
| 3067 | if (flags & FU_ENGINE_LOAD_FLAG_READONLY_FS) |
| 3068 | compile_flags |= XB_BUILDER_COMPILE_FLAG_IGNORE_GUID; |
Richard Hughes | 88dc0f4 | 2019-03-07 11:58:11 +0000 | [diff] [blame] | 3069 | |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 3070 | /* ensure silo is up to date */ |
| 3071 | cachedirpkg = fu_common_get_path (FU_PATH_KIND_CACHEDIR_PKG); |
| 3072 | xmlbfn = g_build_filename (cachedirpkg, "metadata.xmlb", NULL); |
| 3073 | xmlb = g_file_new_for_path (xmlbfn); |
Richard Hughes | c8cc77c | 2019-03-07 11:57:24 +0000 | [diff] [blame] | 3074 | self->silo = xb_builder_ensure (builder, xmlb, compile_flags, NULL, error); |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 3075 | if (self->silo == NULL) |
| 3076 | return FALSE; |
| 3077 | |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3078 | /* print what we've got */ |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 3079 | components = xb_silo_query (self->silo, "components/component", 0, NULL); |
| 3080 | if (components != NULL) |
| 3081 | g_debug ("%u components now in silo", components->len); |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3082 | |
Richard Hughes | 634da03 | 2018-11-05 11:42:20 +0000 | [diff] [blame] | 3083 | /* build the index */ |
| 3084 | if (!xb_silo_query_build_index (self->silo, |
| 3085 | "components/component/provides/firmware", |
| 3086 | "type", error)) |
| 3087 | return FALSE; |
| 3088 | if (!xb_silo_query_build_index (self->silo, |
| 3089 | "components/component/provides/firmware", |
| 3090 | NULL, error)) |
| 3091 | return FALSE; |
| 3092 | |
Richard Hughes | f43381f | 2020-02-24 10:11:31 +0000 | [diff] [blame] | 3093 | /* success */ |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3094 | return TRUE; |
| 3095 | } |
| 3096 | |
Mario Limonciello | 263cab9 | 2019-08-20 17:16:00 -0500 | [diff] [blame] | 3097 | static void |
| 3098 | fu_engine_config_changed_cb (FuConfig *config, FuEngine *self) |
| 3099 | { |
Richard Hughes | d1808aa | 2019-12-10 15:20:30 +0000 | [diff] [blame] | 3100 | fu_idle_set_timeout (self->idle, fu_config_get_idle_timeout (config)); |
| 3101 | } |
| 3102 | |
| 3103 | static void |
| 3104 | fu_engine_remote_list_changed_cb (FuRemoteList *remote_list, FuEngine *self) |
| 3105 | { |
Mario Limonciello | 263cab9 | 2019-08-20 17:16:00 -0500 | [diff] [blame] | 3106 | g_autoptr(GError) error_local = NULL; |
| 3107 | if (!fu_engine_load_metadata_store (self, FU_ENGINE_LOAD_FLAG_NONE, |
| 3108 | &error_local)) |
| 3109 | g_warning ("Failed to reload metadata store: %s", |
| 3110 | error_local->message); |
Mario Limonciello | d81ea2e | 2020-01-13 14:11:43 -0600 | [diff] [blame] | 3111 | |
Richard Hughes | f43381f | 2020-02-24 10:11:31 +0000 | [diff] [blame] | 3112 | /* set device properties from the metadata */ |
| 3113 | fu_engine_md_refresh_devices (self); |
| 3114 | |
Mario Limonciello | d81ea2e | 2020-01-13 14:11:43 -0600 | [diff] [blame] | 3115 | /* make the UI update */ |
| 3116 | fu_engine_emit_changed (self); |
Mario Limonciello | 263cab9 | 2019-08-20 17:16:00 -0500 | [diff] [blame] | 3117 | } |
| 3118 | |
Richard Hughes | d5aab65 | 2020-02-25 12:47:50 +0000 | [diff] [blame] | 3119 | static gint |
| 3120 | fu_engine_sort_jcat_results_timestamp_cb (gconstpointer a, gconstpointer b) |
| 3121 | { |
| 3122 | JcatResult *ra = *((JcatResult **) a); |
| 3123 | JcatResult *rb = *((JcatResult **) b); |
| 3124 | if (jcat_result_get_timestamp (ra) < jcat_result_get_timestamp (rb)) |
| 3125 | return -1; |
| 3126 | if (jcat_result_get_timestamp (ra) > jcat_result_get_timestamp (rb)) |
| 3127 | return 1; |
| 3128 | return 0; |
| 3129 | } |
| 3130 | |
| 3131 | static JcatResult * |
| 3132 | fu_engine_get_system_jcat_result (FuEngine *self, FwupdRemote *remote, GError **error) |
Richard Hughes | f69a481 | 2017-08-16 12:27:51 +0100 | [diff] [blame] | 3133 | { |
| 3134 | g_autoptr(GBytes) blob = NULL; |
| 3135 | g_autoptr(GBytes) blob_sig = NULL; |
Richard Hughes | d5aab65 | 2020-02-25 12:47:50 +0000 | [diff] [blame] | 3136 | g_autoptr(GInputStream) istream = NULL; |
| 3137 | g_autoptr(GPtrArray) results = NULL; |
| 3138 | g_autoptr(JcatItem) jcat_item = NULL; |
| 3139 | g_autoptr(JcatFile) jcat_file = jcat_file_new (); |
| 3140 | |
Richard Hughes | f69a481 | 2017-08-16 12:27:51 +0100 | [diff] [blame] | 3141 | blob = fu_common_get_contents_bytes (fwupd_remote_get_filename_cache (remote), error); |
| 3142 | if (blob == NULL) |
| 3143 | return NULL; |
| 3144 | blob_sig = fu_common_get_contents_bytes (fwupd_remote_get_filename_cache_sig (remote), error); |
| 3145 | if (blob_sig == NULL) |
| 3146 | return NULL; |
Richard Hughes | d5aab65 | 2020-02-25 12:47:50 +0000 | [diff] [blame] | 3147 | istream = g_memory_input_stream_new_from_bytes (blob_sig); |
| 3148 | if (!jcat_file_import_stream (jcat_file, istream, |
| 3149 | JCAT_IMPORT_FLAG_NONE, |
| 3150 | NULL, error)) |
| 3151 | return NULL; |
| 3152 | jcat_item = jcat_file_get_item_default (jcat_file, error); |
| 3153 | if (jcat_item == NULL) |
| 3154 | return NULL; |
| 3155 | results = jcat_context_verify_item (self->jcat_context, |
| 3156 | blob, jcat_item, |
| 3157 | JCAT_VERIFY_FLAG_REQUIRE_CHECKSUM | |
| 3158 | JCAT_VERIFY_FLAG_REQUIRE_SIGNATURE, |
| 3159 | error); |
| 3160 | if (results == NULL) |
| 3161 | return NULL; |
| 3162 | g_ptr_array_sort (results, fu_engine_sort_jcat_results_timestamp_cb); |
| 3163 | |
| 3164 | /* return the newest one */ |
| 3165 | return g_object_ref (g_ptr_array_index (results, 0)); |
| 3166 | } |
| 3167 | |
| 3168 | static gboolean |
| 3169 | fu_engine_validate_result_timestamp (JcatResult *jcat_result, |
| 3170 | JcatResult *jcat_result_old, |
| 3171 | GError **error) |
| 3172 | { |
| 3173 | gint64 delta = 0; |
| 3174 | |
| 3175 | g_return_val_if_fail (JCAT_IS_RESULT (jcat_result), FALSE); |
| 3176 | g_return_val_if_fail (JCAT_IS_RESULT (jcat_result_old), FALSE); |
| 3177 | |
Richard Hughes | 64ebf91 | 2020-05-29 07:51:38 +0100 | [diff] [blame^] | 3178 | if (jcat_result_get_timestamp (jcat_result) == 0) { |
| 3179 | g_set_error (error, |
| 3180 | FWUPD_ERROR, |
| 3181 | FWUPD_ERROR_INVALID_FILE, |
| 3182 | "no signing timestamp"); |
| 3183 | return FALSE; |
| 3184 | } |
| 3185 | if (jcat_result_get_timestamp (jcat_result_old) > 0) { |
Richard Hughes | d5aab65 | 2020-02-25 12:47:50 +0000 | [diff] [blame] | 3186 | delta = jcat_result_get_timestamp (jcat_result) - |
| 3187 | jcat_result_get_timestamp (jcat_result_old); |
| 3188 | } |
| 3189 | if (delta < 0) { |
| 3190 | g_set_error (error, |
| 3191 | FWUPD_ERROR, |
| 3192 | FWUPD_ERROR_INVALID_FILE, |
| 3193 | "new signing timestamp was %" |
| 3194 | G_GINT64_FORMAT " seconds older", |
| 3195 | -delta); |
| 3196 | return FALSE; |
| 3197 | } |
| 3198 | if (delta > 0) |
| 3199 | g_debug ("timestamp increased, so no rollback"); |
| 3200 | return TRUE; |
Richard Hughes | f69a481 | 2017-08-16 12:27:51 +0100 | [diff] [blame] | 3201 | } |
| 3202 | |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3203 | /** |
Richard Hughes | be5b019 | 2020-01-17 14:32:23 +0000 | [diff] [blame] | 3204 | * fu_engine_update_metadata_bytes: |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3205 | * @self: A #FuEngine |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 3206 | * @remote_id: A remote ID, e.g. `lvfs` |
Richard Hughes | be5b019 | 2020-01-17 14:32:23 +0000 | [diff] [blame] | 3207 | * @bytes_raw: Blob of metadata |
Richard Hughes | d5aab65 | 2020-02-25 12:47:50 +0000 | [diff] [blame] | 3208 | * @bytes_sig: Blob of metadata signature, typically Jcat binary format |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3209 | * @error: A #GError, or %NULL |
| 3210 | * |
| 3211 | * Updates the metadata for a specific remote. |
| 3212 | * |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3213 | * Returns: %TRUE for success |
| 3214 | **/ |
| 3215 | gboolean |
Richard Hughes | be5b019 | 2020-01-17 14:32:23 +0000 | [diff] [blame] | 3216 | fu_engine_update_metadata_bytes (FuEngine *self, const gchar *remote_id, |
| 3217 | GBytes *bytes_raw, GBytes *bytes_sig, GError **error) |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3218 | { |
Richard Hughes | 7403dc5 | 2017-08-10 15:34:10 +0100 | [diff] [blame] | 3219 | FwupdKeyringKind keyring_kind; |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3220 | FwupdRemote *remote; |
Mario Limonciello | cf63aec | 2018-06-11 12:10:54 -0500 | [diff] [blame] | 3221 | g_autofree gchar *pki_dir = NULL; |
| 3222 | g_autofree gchar *sysconfdir = NULL; |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3223 | |
| 3224 | g_return_val_if_fail (FU_IS_ENGINE (self), FALSE); |
| 3225 | g_return_val_if_fail (remote_id != NULL, FALSE); |
Richard Hughes | be5b019 | 2020-01-17 14:32:23 +0000 | [diff] [blame] | 3226 | g_return_val_if_fail (bytes_raw != NULL, FALSE); |
| 3227 | g_return_val_if_fail (bytes_sig != NULL, FALSE); |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3228 | g_return_val_if_fail (error == NULL || *error == NULL, FALSE); |
| 3229 | |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3230 | /* check remote is valid */ |
Richard Hughes | d1808aa | 2019-12-10 15:20:30 +0000 | [diff] [blame] | 3231 | remote = fu_remote_list_get_by_id (self->remote_list, remote_id); |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3232 | if (remote == NULL) { |
| 3233 | g_set_error (error, |
| 3234 | FWUPD_ERROR, |
| 3235 | FWUPD_ERROR_NOT_FOUND, |
| 3236 | "remote %s not found", remote_id); |
| 3237 | return FALSE; |
| 3238 | } |
| 3239 | if (!fwupd_remote_get_enabled (remote)) { |
| 3240 | g_set_error (error, |
| 3241 | FWUPD_ERROR, |
| 3242 | FWUPD_ERROR_NOT_SUPPORTED, |
| 3243 | "remote %s not enabled", remote_id); |
| 3244 | return FALSE; |
| 3245 | } |
| 3246 | |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3247 | /* verify file */ |
Richard Hughes | 7403dc5 | 2017-08-10 15:34:10 +0100 | [diff] [blame] | 3248 | keyring_kind = fwupd_remote_get_keyring_kind (remote); |
| 3249 | if (keyring_kind != FWUPD_KEYRING_KIND_NONE) { |
Richard Hughes | d5aab65 | 2020-02-25 12:47:50 +0000 | [diff] [blame] | 3250 | JcatResult *jcat_result; |
Richard Hughes | f69a481 | 2017-08-16 12:27:51 +0100 | [diff] [blame] | 3251 | g_autoptr(GError) error_local = NULL; |
Richard Hughes | d5aab65 | 2020-02-25 12:47:50 +0000 | [diff] [blame] | 3252 | g_autoptr(GInputStream) istream = NULL; |
| 3253 | g_autoptr(GPtrArray) results = NULL; |
| 3254 | g_autoptr(JcatFile) jcat_file = jcat_file_new (); |
| 3255 | g_autoptr(JcatItem) jcat_item = NULL; |
| 3256 | g_autoptr(JcatResult) jcat_result_old = NULL; |
| 3257 | |
| 3258 | /* load Jcat file */ |
| 3259 | istream = g_memory_input_stream_new_from_bytes (bytes_sig); |
| 3260 | if (!jcat_file_import_stream (jcat_file, istream, |
| 3261 | JCAT_IMPORT_FLAG_NONE, |
| 3262 | NULL, error)) |
Richard Hughes | 7403dc5 | 2017-08-10 15:34:10 +0100 | [diff] [blame] | 3263 | return FALSE; |
Richard Hughes | d5aab65 | 2020-02-25 12:47:50 +0000 | [diff] [blame] | 3264 | |
| 3265 | /* this should only be signing one thing */ |
| 3266 | jcat_item = jcat_file_get_item_default (jcat_file, error); |
| 3267 | if (jcat_item == NULL) |
Richard Hughes | 14047d7 | 2017-08-18 10:58:47 +0100 | [diff] [blame] | 3268 | return FALSE; |
Richard Hughes | d5aab65 | 2020-02-25 12:47:50 +0000 | [diff] [blame] | 3269 | results = jcat_context_verify_item (self->jcat_context, |
| 3270 | bytes_raw, jcat_item, |
| 3271 | JCAT_VERIFY_FLAG_REQUIRE_CHECKSUM | |
| 3272 | JCAT_VERIFY_FLAG_REQUIRE_SIGNATURE, |
Richard Hughes | f28abe7 | 2019-03-07 16:01:02 +0000 | [diff] [blame] | 3273 | error); |
Richard Hughes | d5aab65 | 2020-02-25 12:47:50 +0000 | [diff] [blame] | 3274 | if (results == NULL) |
Richard Hughes | 7403dc5 | 2017-08-10 15:34:10 +0100 | [diff] [blame] | 3275 | return FALSE; |
Richard Hughes | f69a481 | 2017-08-16 12:27:51 +0100 | [diff] [blame] | 3276 | |
Richard Hughes | d5aab65 | 2020-02-25 12:47:50 +0000 | [diff] [blame] | 3277 | /* return the newest one */ |
| 3278 | g_ptr_array_sort (results, fu_engine_sort_jcat_results_timestamp_cb); |
| 3279 | jcat_result = g_ptr_array_index (results, 0); |
| 3280 | |
Richard Hughes | f69a481 | 2017-08-16 12:27:51 +0100 | [diff] [blame] | 3281 | /* verify the metadata was signed later than the existing |
| 3282 | * metadata for this remote to mitigate a rollback attack */ |
Richard Hughes | d5aab65 | 2020-02-25 12:47:50 +0000 | [diff] [blame] | 3283 | jcat_result_old = fu_engine_get_system_jcat_result (self, remote, &error_local); |
| 3284 | if (jcat_result_old == NULL) { |
Richard Hughes | f69a481 | 2017-08-16 12:27:51 +0100 | [diff] [blame] | 3285 | if (g_error_matches (error_local, |
| 3286 | G_FILE_ERROR, |
| 3287 | G_FILE_ERROR_NOENT)) { |
| 3288 | g_debug ("no existing valid keyrings: %s", |
| 3289 | error_local->message); |
| 3290 | } else { |
| 3291 | g_warning ("could not get existing keyring result: %s", |
| 3292 | error_local->message); |
| 3293 | } |
| 3294 | } else { |
Richard Hughes | d5aab65 | 2020-02-25 12:47:50 +0000 | [diff] [blame] | 3295 | if (!fu_engine_validate_result_timestamp (jcat_result, |
| 3296 | jcat_result_old, |
| 3297 | error)) |
Richard Hughes | f69a481 | 2017-08-16 12:27:51 +0100 | [diff] [blame] | 3298 | return FALSE; |
Richard Hughes | f69a481 | 2017-08-16 12:27:51 +0100 | [diff] [blame] | 3299 | } |
Richard Hughes | 7403dc5 | 2017-08-10 15:34:10 +0100 | [diff] [blame] | 3300 | } |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3301 | |
Richard Hughes | 99e621d | 2017-08-16 12:24:18 +0100 | [diff] [blame] | 3302 | /* save XML and signature to remotes.d */ |
Richard Hughes | 943d2c9 | 2017-06-21 09:04:39 +0100 | [diff] [blame] | 3303 | if (!fu_common_set_contents_bytes (fwupd_remote_get_filename_cache (remote), |
| 3304 | bytes_raw, error)) |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3305 | return FALSE; |
Richard Hughes | 99e621d | 2017-08-16 12:24:18 +0100 | [diff] [blame] | 3306 | if (keyring_kind != FWUPD_KEYRING_KIND_NONE) { |
| 3307 | if (!fu_common_set_contents_bytes (fwupd_remote_get_filename_cache_sig (remote), |
| 3308 | bytes_sig, error)) |
| 3309 | return FALSE; |
| 3310 | } |
Mario Limonciello | d81ea2e | 2020-01-13 14:11:43 -0600 | [diff] [blame] | 3311 | if (!fu_engine_load_metadata_store (self, FU_ENGINE_LOAD_FLAG_NONE, error)) |
| 3312 | return FALSE; |
Richard Hughes | f43381f | 2020-02-24 10:11:31 +0000 | [diff] [blame] | 3313 | fu_engine_md_refresh_devices (self); |
Mario Limonciello | d81ea2e | 2020-01-13 14:11:43 -0600 | [diff] [blame] | 3314 | fu_engine_emit_changed (self); |
| 3315 | return TRUE; |
Richard Hughes | be5b019 | 2020-01-17 14:32:23 +0000 | [diff] [blame] | 3316 | } |
Mario Limonciello | d81ea2e | 2020-01-13 14:11:43 -0600 | [diff] [blame] | 3317 | |
Richard Hughes | be5b019 | 2020-01-17 14:32:23 +0000 | [diff] [blame] | 3318 | /** |
| 3319 | * fu_engine_update_metadata: |
| 3320 | * @self: A #FuEngine |
| 3321 | * @remote_id: A remote ID, e.g. `lvfs` |
| 3322 | * @fd: file descriptor of the metadata |
| 3323 | * @fd_sig: file descriptor of the metadata signature |
| 3324 | * @error: A #GError, or %NULL |
| 3325 | * |
| 3326 | * Updates the metadata for a specific remote. |
| 3327 | * |
| 3328 | * Note: this will close the fds when done |
| 3329 | * |
| 3330 | * Returns: %TRUE for success |
| 3331 | **/ |
| 3332 | gboolean |
| 3333 | fu_engine_update_metadata (FuEngine *self, const gchar *remote_id, |
| 3334 | gint fd, gint fd_sig, GError **error) |
| 3335 | { |
| 3336 | #ifdef HAVE_GIO_UNIX |
| 3337 | g_autoptr(GBytes) bytes_raw = NULL; |
| 3338 | g_autoptr(GBytes) bytes_sig = NULL; |
| 3339 | g_autoptr(GInputStream) stream_fd = NULL; |
| 3340 | g_autoptr(GInputStream) stream_sig = NULL; |
| 3341 | |
| 3342 | g_return_val_if_fail (FU_IS_ENGINE (self), FALSE); |
| 3343 | g_return_val_if_fail (remote_id != NULL, FALSE); |
| 3344 | g_return_val_if_fail (fd > 0, FALSE); |
| 3345 | g_return_val_if_fail (fd_sig > 0, FALSE); |
| 3346 | g_return_val_if_fail (error == NULL || *error == NULL, FALSE); |
| 3347 | |
| 3348 | /* ensures the fd's are closed on error */ |
| 3349 | stream_fd = g_unix_input_stream_new (fd, TRUE); |
| 3350 | stream_sig = g_unix_input_stream_new (fd_sig, TRUE); |
| 3351 | |
| 3352 | /* read the entire file into memory */ |
| 3353 | bytes_raw = g_input_stream_read_bytes (stream_fd, 0x100000, NULL, error); |
| 3354 | if (bytes_raw == NULL) |
| 3355 | return FALSE; |
| 3356 | |
| 3357 | /* read signature */ |
Richard Hughes | 64d868a | 2020-01-17 17:40:00 +0000 | [diff] [blame] | 3358 | bytes_sig = g_input_stream_read_bytes (stream_sig, 0x100000, NULL, error); |
Richard Hughes | be5b019 | 2020-01-17 14:32:23 +0000 | [diff] [blame] | 3359 | if (bytes_sig == NULL) |
| 3360 | return FALSE; |
| 3361 | |
| 3362 | /* update with blobs */ |
| 3363 | return fu_engine_update_metadata_bytes (self, remote_id, |
| 3364 | bytes_raw, bytes_sig, |
| 3365 | error); |
Richard Hughes | 9e5675e | 2019-11-22 09:35:03 +0000 | [diff] [blame] | 3366 | #else |
| 3367 | g_set_error (error, |
| 3368 | FWUPD_ERROR, |
| 3369 | FWUPD_ERROR_NOT_SUPPORTED, |
| 3370 | "Not supported as <glib-unix.h> is unavailable"); |
| 3371 | return FALSE; |
| 3372 | #endif |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3373 | } |
| 3374 | |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3375 | /** |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 3376 | * fu_engine_get_silo_from_blob: |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3377 | * @self: A #FuEngine |
| 3378 | * @blob_cab: A #GBytes |
| 3379 | * @error: A #GError, or %NULL |
| 3380 | * |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 3381 | * Creates a silo from a .cab file blob. |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3382 | * |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 3383 | * Returns: (transfer container): a #XbSilo, or %NULL |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3384 | **/ |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 3385 | XbSilo * |
| 3386 | fu_engine_get_silo_from_blob (FuEngine *self, GBytes *blob_cab, GError **error) |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3387 | { |
Richard Hughes | c6eb416 | 2020-02-27 10:02:36 +0000 | [diff] [blame] | 3388 | g_autoptr(FuCabinet) cabinet = fu_cabinet_new (); |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 3389 | g_autoptr(XbSilo) silo = NULL; |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3390 | |
| 3391 | g_return_val_if_fail (FU_IS_ENGINE (self), NULL); |
| 3392 | g_return_val_if_fail (blob_cab != NULL, NULL); |
| 3393 | g_return_val_if_fail (error == NULL || *error == NULL, NULL); |
| 3394 | |
| 3395 | /* load file */ |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3396 | fu_engine_set_status (self, FWUPD_STATUS_DECOMPRESSING); |
Richard Hughes | c6eb416 | 2020-02-27 10:02:36 +0000 | [diff] [blame] | 3397 | fu_cabinet_set_size_max (cabinet, fu_engine_get_archive_size_max (self)); |
Richard Hughes | d5aab65 | 2020-02-25 12:47:50 +0000 | [diff] [blame] | 3398 | fu_cabinet_set_jcat_context (cabinet, self->jcat_context); |
Richard Hughes | c6eb416 | 2020-02-27 10:02:36 +0000 | [diff] [blame] | 3399 | if (!fu_cabinet_parse (cabinet, blob_cab, FU_CABINET_PARSE_FLAG_NONE, error)) |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3400 | return NULL; |
Richard Hughes | c6eb416 | 2020-02-27 10:02:36 +0000 | [diff] [blame] | 3401 | silo = fu_cabinet_get_silo (cabinet); |
Mario Limonciello | 5735fd6 | 2017-07-13 15:47:52 -0500 | [diff] [blame] | 3402 | fu_engine_set_status (self, FWUPD_STATUS_IDLE); |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 3403 | return g_steal_pointer (&silo); |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3404 | } |
| 3405 | |
Richard Hughes | 75449d9 | 2019-04-17 13:36:31 +0100 | [diff] [blame] | 3406 | static FuDevice * |
Richard Hughes | 6e0c8f8 | 2018-11-11 21:46:41 +0000 | [diff] [blame] | 3407 | fu_engine_get_result_from_component (FuEngine *self, XbNode *component, GError **error) |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3408 | { |
Richard Hughes | 245885c | 2019-03-04 08:46:02 +0000 | [diff] [blame] | 3409 | FwupdReleaseFlags release_flags = FWUPD_RELEASE_FLAG_NONE; |
Richard Hughes | 1d1f5cf | 2018-05-19 23:06:03 +0100 | [diff] [blame] | 3410 | g_autoptr(FuInstallTask) task = NULL; |
Richard Hughes | 75449d9 | 2019-04-17 13:36:31 +0100 | [diff] [blame] | 3411 | g_autoptr(FuDevice) dev = NULL; |
Richard Hughes | 93b1576 | 2017-09-15 11:05:23 +0100 | [diff] [blame] | 3412 | g_autoptr(FwupdRelease) rel = NULL; |
Salud Lemus | 980f2d9 | 2018-08-28 09:25:40 -0700 | [diff] [blame] | 3413 | g_autoptr(GError) error_local = NULL; |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 3414 | g_autoptr(GPtrArray) provides = NULL; |
| 3415 | g_autoptr(XbNode) description = NULL; |
| 3416 | g_autoptr(XbNode) release = NULL; |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3417 | |
Richard Hughes | 75449d9 | 2019-04-17 13:36:31 +0100 | [diff] [blame] | 3418 | dev = fu_device_new (); |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 3419 | provides = xb_node_query (component, |
Richard Hughes | 634da03 | 2018-11-05 11:42:20 +0000 | [diff] [blame] | 3420 | "provides/firmware[@type=$'flashed']", |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 3421 | 0, &error_local); |
| 3422 | if (provides == NULL) { |
| 3423 | g_set_error (error, |
| 3424 | FWUPD_ERROR, |
| 3425 | FWUPD_ERROR_INTERNAL, |
| 3426 | "failed to get release: %s", |
| 3427 | error_local->message); |
| 3428 | return NULL; |
| 3429 | } |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3430 | for (guint i = 0; i < provides->len; i++) { |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 3431 | XbNode *prov = XB_NODE (g_ptr_array_index (provides, i)); |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3432 | const gchar *guid; |
Richard Hughes | 5a9a6bd | 2018-09-10 10:02:20 +0100 | [diff] [blame] | 3433 | g_autoptr(FuDevice) device = NULL; |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3434 | |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3435 | /* is a online or offline update appropriate */ |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 3436 | guid = xb_node_get_text (prov); |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3437 | if (guid == NULL) |
| 3438 | continue; |
Richard Hughes | 4012754 | 2018-01-12 20:25:55 +0000 | [diff] [blame] | 3439 | device = fu_device_list_get_by_guid (self->device_list, guid, NULL); |
Richard Hughes | 0a7e783 | 2017-11-22 11:01:13 +0000 | [diff] [blame] | 3440 | if (device != NULL) { |
Richard Hughes | 75449d9 | 2019-04-17 13:36:31 +0100 | [diff] [blame] | 3441 | fu_device_set_name (dev, fu_device_get_name (device)); |
| 3442 | fu_device_set_flags (dev, fu_device_get_flags (device)); |
| 3443 | fu_device_set_id (dev, fu_device_get_id (device)); |
Mario Limonciello | f430da0 | 2020-03-09 14:03:03 -0500 | [diff] [blame] | 3444 | fu_device_set_version_raw (dev, fu_device_get_version_raw (device)); |
Mario Limonciello | 8bcdfaa | 2020-02-25 11:18:15 -0600 | [diff] [blame] | 3445 | fu_device_set_version_format (dev, fu_device_get_version_format (device)); |
| 3446 | fu_device_set_version (dev, fu_device_get_version (device)); |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3447 | } |
| 3448 | |
| 3449 | /* add GUID */ |
Richard Hughes | 75449d9 | 2019-04-17 13:36:31 +0100 | [diff] [blame] | 3450 | fu_device_add_guid (dev, guid); |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3451 | } |
Richard Hughes | 75449d9 | 2019-04-17 13:36:31 +0100 | [diff] [blame] | 3452 | if (fu_device_get_guids(dev)->len == 0) { |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3453 | g_set_error_literal (error, |
| 3454 | FWUPD_ERROR, |
| 3455 | FWUPD_ERROR_INTERNAL, |
| 3456 | "component has no GUIDs"); |
| 3457 | return NULL; |
| 3458 | } |
| 3459 | |
| 3460 | /* check we can install it */ |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 3461 | task = fu_install_task_new (NULL, component); |
Richard Hughes | 1d1f5cf | 2018-05-19 23:06:03 +0100 | [diff] [blame] | 3462 | if (!fu_engine_check_requirements (self, task, |
| 3463 | FWUPD_INSTALL_FLAG_NONE, |
| 3464 | error)) |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3465 | return NULL; |
| 3466 | |
| 3467 | /* verify trust */ |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 3468 | release = xb_node_query_first (component, |
| 3469 | "releases/release", |
| 3470 | &error_local); |
| 3471 | if (release == NULL) { |
| 3472 | g_set_error (error, |
| 3473 | FWUPD_ERROR, |
| 3474 | FWUPD_ERROR_INTERNAL, |
| 3475 | "failed to get release: %s", |
| 3476 | error_local->message); |
| 3477 | return NULL; |
| 3478 | } |
Richard Hughes | 245885c | 2019-03-04 08:46:02 +0000 | [diff] [blame] | 3479 | if (!fu_keyring_get_release_flags (release, |
| 3480 | &release_flags, |
| 3481 | &error_local)) { |
Salud Lemus | 980f2d9 | 2018-08-28 09:25:40 -0700 | [diff] [blame] | 3482 | if (g_error_matches (error_local, |
| 3483 | FWUPD_ERROR, |
| 3484 | FWUPD_ERROR_NOT_SUPPORTED)) { |
| 3485 | g_warning ("Ignoring verification: %s", |
| 3486 | error_local->message); |
| 3487 | } else { |
| 3488 | g_propagate_error (error, g_steal_pointer (&error_local)); |
| 3489 | return NULL; |
| 3490 | } |
| 3491 | } |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3492 | |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3493 | /* create a result with all the metadata in */ |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 3494 | description = xb_node_query_first (component, "description", NULL); |
| 3495 | if (description != NULL) { |
| 3496 | g_autofree gchar *xml = NULL; |
| 3497 | xml = xb_node_export (description, |
| 3498 | XB_NODE_EXPORT_FLAG_ONLY_CHILDREN, |
| 3499 | NULL); |
| 3500 | if (xml != NULL) |
Richard Hughes | 75449d9 | 2019-04-17 13:36:31 +0100 | [diff] [blame] | 3501 | fu_device_set_description (dev, xml); |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 3502 | } |
Richard Hughes | 93b1576 | 2017-09-15 11:05:23 +0100 | [diff] [blame] | 3503 | rel = fwupd_release_new (); |
Richard Hughes | 245885c | 2019-03-04 08:46:02 +0000 | [diff] [blame] | 3504 | fwupd_release_set_flags (rel, release_flags); |
Richard Hughes | 75449d9 | 2019-04-17 13:36:31 +0100 | [diff] [blame] | 3505 | if (!fu_engine_set_release_from_appstream (self, dev, rel, component, release, error)) |
Richard Hughes | 0b3e9fd | 2019-04-08 11:13:20 +0100 | [diff] [blame] | 3506 | return NULL; |
Richard Hughes | 75449d9 | 2019-04-17 13:36:31 +0100 | [diff] [blame] | 3507 | fu_device_add_release (dev, rel); |
Richard Hughes | 93b1576 | 2017-09-15 11:05:23 +0100 | [diff] [blame] | 3508 | return g_steal_pointer (&dev); |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3509 | } |
| 3510 | |
Richard Hughes | b3d3f21 | 2020-05-21 21:14:49 +0100 | [diff] [blame] | 3511 | static gint |
| 3512 | fu_engine_get_details_sort_cb (gconstpointer a, gconstpointer b) |
| 3513 | { |
| 3514 | FuDevice *device1 = *((FuDevice **) a); |
| 3515 | FuDevice *device2 = *((FuDevice **) b); |
| 3516 | if (!fu_device_has_flag (device1, FWUPD_DEVICE_FLAG_UPDATABLE) && |
| 3517 | fu_device_has_flag (device2, FWUPD_DEVICE_FLAG_UPDATABLE)) |
| 3518 | return 1; |
| 3519 | if (fu_device_has_flag (device1, FWUPD_DEVICE_FLAG_UPDATABLE) && |
| 3520 | !fu_device_has_flag (device2, FWUPD_DEVICE_FLAG_UPDATABLE)) |
| 3521 | return -1; |
| 3522 | return 0; |
| 3523 | } |
| 3524 | |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3525 | /** |
Richard Hughes | 07f963a | 2017-09-15 14:28:47 +0100 | [diff] [blame] | 3526 | * fu_engine_get_details: |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3527 | * @self: A #FuEngine |
| 3528 | * @fd: A file descriptor |
| 3529 | * @error: A #GError, or %NULL |
| 3530 | * |
| 3531 | * Gets the details about a local file. |
| 3532 | * |
| 3533 | * Note: this will close the fd when done |
| 3534 | * |
Richard Hughes | 75449d9 | 2019-04-17 13:36:31 +0100 | [diff] [blame] | 3535 | * Returns: (transfer container) (element-type FuDevice): results |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3536 | **/ |
| 3537 | GPtrArray * |
Richard Hughes | 07f963a | 2017-09-15 14:28:47 +0100 | [diff] [blame] | 3538 | fu_engine_get_details (FuEngine *self, gint fd, GError **error) |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3539 | { |
Richard Hughes | 534255c | 2018-01-28 19:51:56 +0000 | [diff] [blame] | 3540 | const gchar *remote_id; |
| 3541 | g_autofree gchar *csum = NULL; |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3542 | g_autoptr(GBytes) blob = NULL; |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 3543 | g_autoptr(GError) error_local = NULL; |
| 3544 | g_autoptr(GPtrArray) components = NULL; |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3545 | g_autoptr(GPtrArray) details = NULL; |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 3546 | g_autoptr(XbSilo) silo = NULL; |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3547 | |
| 3548 | g_return_val_if_fail (FU_IS_ENGINE (self), NULL); |
| 3549 | g_return_val_if_fail (fd > 0, NULL); |
| 3550 | g_return_val_if_fail (error == NULL || *error == NULL, NULL); |
| 3551 | |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 3552 | /* get all components */ |
Richard Hughes | c7bbbc2 | 2018-01-02 22:22:25 +0000 | [diff] [blame] | 3553 | blob = fu_common_get_contents_fd (fd, |
| 3554 | fu_engine_get_archive_size_max (self), |
| 3555 | error); |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3556 | if (blob == NULL) |
| 3557 | return NULL; |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 3558 | silo = fu_engine_get_silo_from_blob (self, blob, error); |
| 3559 | if (silo == NULL) |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3560 | return NULL; |
Mario Limonciello | 51ddf18 | 2019-01-26 00:31:58 -0600 | [diff] [blame] | 3561 | components = xb_silo_query (silo, "components/component", 0, &error_local); |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 3562 | if (components == NULL) { |
| 3563 | g_set_error (error, |
| 3564 | FWUPD_ERROR, |
| 3565 | FWUPD_ERROR_INVALID_FILE, |
| 3566 | "no components: %s", |
| 3567 | error_local->message); |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3568 | return NULL; |
| 3569 | } |
| 3570 | |
Richard Hughes | ec6190c | 2018-11-25 12:19:33 +0000 | [diff] [blame] | 3571 | /* build the index */ |
Mario Limonciello | 51ddf18 | 2019-01-26 00:31:58 -0600 | [diff] [blame] | 3572 | if (!xb_silo_query_build_index (silo, "components/component/provides/firmware", |
Richard Hughes | ec6190c | 2018-11-25 12:19:33 +0000 | [diff] [blame] | 3573 | "type", error)) |
Richard Hughes | 2eee258 | 2019-03-11 13:17:39 +0000 | [diff] [blame] | 3574 | return NULL; |
Mario Limonciello | 51ddf18 | 2019-01-26 00:31:58 -0600 | [diff] [blame] | 3575 | if (!xb_silo_query_build_index (silo, "components/component/provides/firmware", |
Richard Hughes | ec6190c | 2018-11-25 12:19:33 +0000 | [diff] [blame] | 3576 | NULL, error)) |
Richard Hughes | 2eee258 | 2019-03-11 13:17:39 +0000 | [diff] [blame] | 3577 | return NULL; |
Richard Hughes | ec6190c | 2018-11-25 12:19:33 +0000 | [diff] [blame] | 3578 | |
Richard Hughes | 534255c | 2018-01-28 19:51:56 +0000 | [diff] [blame] | 3579 | /* does this exist in any enabled remote */ |
| 3580 | csum = g_compute_checksum_for_bytes (G_CHECKSUM_SHA1, blob); |
| 3581 | remote_id = fu_engine_get_remote_id_for_checksum (self, csum); |
| 3582 | |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3583 | /* create results with all the metadata in */ |
| 3584 | details = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref); |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 3585 | for (guint i = 0; i < components->len; i++) { |
| 3586 | XbNode *component = g_ptr_array_index (components, i); |
Richard Hughes | 75449d9 | 2019-04-17 13:36:31 +0100 | [diff] [blame] | 3587 | FuDevice *dev; |
Richard Hughes | 6e0c8f8 | 2018-11-11 21:46:41 +0000 | [diff] [blame] | 3588 | dev = fu_engine_get_result_from_component (self, component, error); |
Richard Hughes | 534255c | 2018-01-28 19:51:56 +0000 | [diff] [blame] | 3589 | if (dev == NULL) |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3590 | return NULL; |
Richard Hughes | 534255c | 2018-01-28 19:51:56 +0000 | [diff] [blame] | 3591 | if (remote_id != NULL) { |
Richard Hughes | 75449d9 | 2019-04-17 13:36:31 +0100 | [diff] [blame] | 3592 | FwupdRelease *rel = fu_device_get_release_default (dev); |
Richard Hughes | 534255c | 2018-01-28 19:51:56 +0000 | [diff] [blame] | 3593 | fwupd_release_set_remote_id (rel, remote_id); |
Richard Hughes | 75449d9 | 2019-04-17 13:36:31 +0100 | [diff] [blame] | 3594 | fu_device_add_flag (dev, FWUPD_DEVICE_FLAG_SUPPORTED); |
Richard Hughes | 534255c | 2018-01-28 19:51:56 +0000 | [diff] [blame] | 3595 | } |
Richard Hughes | 137649d | 2020-05-28 13:36:24 +0100 | [diff] [blame] | 3596 | if (fu_device_has_flag (dev, FWUPD_DEVICE_FLAG_MD_SET_VERFMT)) |
| 3597 | fu_engine_md_refresh_device_verfmt (self, dev, component); |
Richard Hughes | b3d3f21 | 2020-05-21 21:14:49 +0100 | [diff] [blame] | 3598 | |
| 3599 | /* if this matched a device on the system, ensure all the |
| 3600 | * requirements passed before setting UPDATABLE */ |
| 3601 | if (fu_device_has_flag (dev, FWUPD_DEVICE_FLAG_UPDATABLE)) { |
| 3602 | g_autoptr(FuInstallTask) task = fu_install_task_new (dev, component); |
| 3603 | g_autoptr(GError) error_req = NULL; |
| 3604 | if (!fu_engine_check_requirements (self, task, |
| 3605 | FWUPD_INSTALL_FLAG_OFFLINE | |
| 3606 | FWUPD_INSTALL_FLAG_ALLOW_REINSTALL | |
| 3607 | FWUPD_INSTALL_FLAG_ALLOW_OLDER, |
| 3608 | &error_req)) { |
| 3609 | g_debug ("%s failed requirement checks: %s", |
| 3610 | fu_device_get_id (dev), |
| 3611 | error_req->message); |
| 3612 | fu_device_remove_flag (dev, FWUPD_DEVICE_FLAG_UPDATABLE); |
| 3613 | } else { |
| 3614 | g_debug ("%s passed requirement checks", |
| 3615 | fu_device_get_id (dev)); |
| 3616 | } |
| 3617 | } |
| 3618 | |
Richard Hughes | 534255c | 2018-01-28 19:51:56 +0000 | [diff] [blame] | 3619 | g_ptr_array_add (details, dev); |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3620 | } |
Richard Hughes | b3d3f21 | 2020-05-21 21:14:49 +0100 | [diff] [blame] | 3621 | |
| 3622 | /* order multiple devices so that the one that passes the requirement |
| 3623 | * is listed first */ |
| 3624 | g_ptr_array_sort (details, fu_engine_get_details_sort_cb); |
| 3625 | |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3626 | return g_steal_pointer (&details); |
| 3627 | } |
| 3628 | |
Mario Limonciello | 343095d | 2018-10-23 17:21:13 -0500 | [diff] [blame] | 3629 | static gint |
Mario Limonciello | 6ff8a16 | 2019-08-23 12:55:10 -0500 | [diff] [blame] | 3630 | fu_engine_sort_devices_by_priority_name (gconstpointer a, gconstpointer b) |
Mario Limonciello | 343095d | 2018-10-23 17:21:13 -0500 | [diff] [blame] | 3631 | { |
| 3632 | FuDevice *dev_a = *((FuDevice **) a); |
| 3633 | FuDevice *dev_b = *((FuDevice **) b); |
| 3634 | gint prio_a = fu_device_get_priority (dev_a); |
| 3635 | gint prio_b = fu_device_get_priority (dev_b); |
Mario Limonciello | 6ff8a16 | 2019-08-23 12:55:10 -0500 | [diff] [blame] | 3636 | const gchar *name_a = fu_device_get_name (dev_a); |
| 3637 | const gchar *name_b = fu_device_get_name (dev_b); |
Mario Limonciello | 343095d | 2018-10-23 17:21:13 -0500 | [diff] [blame] | 3638 | |
| 3639 | if (prio_a > prio_b) |
| 3640 | return -1; |
| 3641 | if (prio_a < prio_b) |
| 3642 | return 1; |
Mario Limonciello | 6ff8a16 | 2019-08-23 12:55:10 -0500 | [diff] [blame] | 3643 | if (g_strcmp0 (name_a, name_b) > 0) |
| 3644 | return 1; |
| 3645 | if (g_strcmp0 (name_a, name_b) < 0) |
| 3646 | return -1; |
Mario Limonciello | 343095d | 2018-10-23 17:21:13 -0500 | [diff] [blame] | 3647 | return 0; |
| 3648 | } |
| 3649 | |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3650 | /** |
| 3651 | * fu_engine_get_devices: |
| 3652 | * @self: A #FuEngine |
| 3653 | * @error: A #GError, or %NULL |
| 3654 | * |
| 3655 | * Gets the list of devices. |
| 3656 | * |
| 3657 | * Returns: (transfer container) (element-type FwupdDevice): results |
| 3658 | **/ |
| 3659 | GPtrArray * |
| 3660 | fu_engine_get_devices (FuEngine *self, GError **error) |
| 3661 | { |
Richard Hughes | f2eccde | 2017-09-20 11:18:03 +0100 | [diff] [blame] | 3662 | g_autoptr(GPtrArray) devices = NULL; |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3663 | |
| 3664 | g_return_val_if_fail (FU_IS_ENGINE (self), NULL); |
| 3665 | g_return_val_if_fail (error == NULL || *error == NULL, NULL); |
| 3666 | |
Richard Hughes | 70425fe | 2017-11-22 12:33:27 +0000 | [diff] [blame] | 3667 | devices = fu_device_list_get_active (self->device_list); |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3668 | if (devices->len == 0) { |
| 3669 | g_set_error_literal (error, |
| 3670 | FWUPD_ERROR, |
| 3671 | FWUPD_ERROR_NOTHING_TO_DO, |
| 3672 | "No detected devices"); |
| 3673 | return NULL; |
| 3674 | } |
Mario Limonciello | 6ff8a16 | 2019-08-23 12:55:10 -0500 | [diff] [blame] | 3675 | g_ptr_array_sort (devices, fu_engine_sort_devices_by_priority_name); |
Richard Hughes | f2eccde | 2017-09-20 11:18:03 +0100 | [diff] [blame] | 3676 | return g_steal_pointer (&devices); |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3677 | } |
| 3678 | |
Richard Hughes | 12040b5 | 2018-05-14 13:32:10 +0100 | [diff] [blame] | 3679 | /** |
| 3680 | * fu_engine_get_device: |
| 3681 | * @self: A #FuEngine |
| 3682 | * @device_id: A device ID |
| 3683 | * @error: A #GError, or %NULL |
| 3684 | * |
| 3685 | * Gets a specific device. |
| 3686 | * |
| 3687 | * Returns: (transfer full): a device, or %NULL if not found |
| 3688 | **/ |
Richard Hughes | 4ad41f0 | 2018-05-08 14:35:36 +0100 | [diff] [blame] | 3689 | FuDevice * |
| 3690 | fu_engine_get_device (FuEngine *self, const gchar *device_id, GError **error) |
| 3691 | { |
Richard Hughes | 12040b5 | 2018-05-14 13:32:10 +0100 | [diff] [blame] | 3692 | FuDevice *device; |
Richard Hughes | 37d0943 | 2018-09-09 10:39:45 +0100 | [diff] [blame] | 3693 | |
Richard Hughes | 12040b5 | 2018-05-14 13:32:10 +0100 | [diff] [blame] | 3694 | device = fu_device_list_get_by_id (self->device_list, device_id, error); |
| 3695 | if (device == NULL) |
| 3696 | return NULL; |
Richard Hughes | 5a9a6bd | 2018-09-10 10:02:20 +0100 | [diff] [blame] | 3697 | return device; |
Richard Hughes | 4ad41f0 | 2018-05-08 14:35:36 +0100 | [diff] [blame] | 3698 | } |
| 3699 | |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3700 | /** |
Richard Hughes | 3aaf53c | 2020-04-20 09:39:46 +0100 | [diff] [blame] | 3701 | * fu_engine_get_devices_by_guid: |
| 3702 | * @self: A #FuEngine |
| 3703 | * @guid: A GUID |
| 3704 | * @error: A #GError, or %NULL |
| 3705 | * |
| 3706 | * Gets a specific device. |
| 3707 | * |
| 3708 | * Returns: (transfer full): a device, or %NULL if not found |
| 3709 | **/ |
| 3710 | GPtrArray * |
| 3711 | fu_engine_get_devices_by_guid (FuEngine *self, const gchar *guid, GError **error) |
| 3712 | { |
| 3713 | g_autoptr(GPtrArray) devices = NULL; |
| 3714 | g_autoptr(GPtrArray) devices_tmp = NULL; |
| 3715 | |
| 3716 | /* find the devices by GUID */ |
| 3717 | devices_tmp = fu_device_list_get_all (self->device_list); |
| 3718 | devices = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref); |
| 3719 | for (guint i = 0; i < devices_tmp->len; i++) { |
| 3720 | FuDevice *dev_tmp = g_ptr_array_index (devices_tmp, i); |
| 3721 | if (fu_device_has_guid (dev_tmp, guid)) |
| 3722 | g_ptr_array_add (devices, g_object_ref (dev_tmp)); |
| 3723 | } |
| 3724 | |
| 3725 | /* nothing */ |
| 3726 | if (devices->len == 0) { |
| 3727 | g_set_error (error, |
| 3728 | FWUPD_ERROR, |
| 3729 | FWUPD_ERROR_NOT_FOUND, |
| 3730 | "failed to find any device providing %s", guid); |
| 3731 | return NULL; |
| 3732 | } |
| 3733 | |
| 3734 | /* success */ |
| 3735 | return g_steal_pointer (&devices); |
| 3736 | } |
| 3737 | |
Richard Hughes | cef874f | 2020-05-17 21:03:13 +0100 | [diff] [blame] | 3738 | static void |
| 3739 | fu_engine_get_history_set_hsi_attrs (FuEngine *self, FuDevice *device) |
| 3740 | { |
| 3741 | g_autofree gchar *host_security_id = NULL; |
| 3742 | g_autoptr(FuSecurityAttrs) attrs = NULL; |
| 3743 | g_autoptr(GPtrArray) vals = NULL; |
| 3744 | |
| 3745 | /* add attributes */ |
| 3746 | attrs = fu_engine_get_host_security_attrs (self); |
| 3747 | vals = fu_security_attrs_get_all (attrs); |
| 3748 | for (guint i = 0; i < vals->len; i++) { |
| 3749 | FwupdSecurityAttr *attr = g_ptr_array_index (vals, i); |
Richard Hughes | b246bca | 2020-05-18 14:31:35 +0100 | [diff] [blame] | 3750 | const gchar *tmp; |
| 3751 | tmp = fwupd_security_attr_result_to_string (fwupd_security_attr_get_result (attr)); |
| 3752 | fu_device_set_metadata (device, fwupd_security_attr_get_appstream_id (attr), tmp); |
Richard Hughes | cef874f | 2020-05-17 21:03:13 +0100 | [diff] [blame] | 3753 | } |
| 3754 | |
| 3755 | /* computed value */ |
Mario Limonciello | b0e1e5e | 2020-05-18 13:50:29 -0500 | [diff] [blame] | 3756 | host_security_id = fu_security_attrs_calculate_hsi (attrs, FU_SECURITY_ATTRS_FLAG_ADD_VERSION); |
Richard Hughes | cef874f | 2020-05-17 21:03:13 +0100 | [diff] [blame] | 3757 | fu_device_set_metadata (device, "HSI", host_security_id); |
| 3758 | } |
| 3759 | |
Richard Hughes | 3aaf53c | 2020-04-20 09:39:46 +0100 | [diff] [blame] | 3760 | /** |
Richard Hughes | 476363a | 2018-01-11 10:08:58 +0000 | [diff] [blame] | 3761 | * fu_engine_get_history: |
| 3762 | * @self: A #FuEngine |
| 3763 | * @error: A #GError, or %NULL |
| 3764 | * |
| 3765 | * Gets the list of history. |
| 3766 | * |
| 3767 | * Returns: (transfer container) (element-type FwupdDevice): results |
| 3768 | **/ |
| 3769 | GPtrArray * |
| 3770 | fu_engine_get_history (FuEngine *self, GError **error) |
| 3771 | { |
| 3772 | g_autoptr(GPtrArray) devices = NULL; |
| 3773 | |
| 3774 | g_return_val_if_fail (FU_IS_ENGINE (self), NULL); |
| 3775 | g_return_val_if_fail (error == NULL || *error == NULL, NULL); |
| 3776 | |
| 3777 | devices = fu_history_get_devices (self->history, error); |
| 3778 | if (devices == NULL) |
| 3779 | return NULL; |
| 3780 | if (devices->len == 0) { |
| 3781 | g_set_error_literal (error, |
| 3782 | FWUPD_ERROR, |
| 3783 | FWUPD_ERROR_NOTHING_TO_DO, |
| 3784 | "No history"); |
| 3785 | return NULL; |
| 3786 | } |
Richard Hughes | 611f1a9 | 2018-01-11 11:54:28 +0000 | [diff] [blame] | 3787 | |
Richard Hughes | cef874f | 2020-05-17 21:03:13 +0100 | [diff] [blame] | 3788 | /* if this is the system firmware device, add the HSI attrs */ |
| 3789 | for (guint i = 0; i < devices->len; i++) { |
| 3790 | FuDevice *dev = g_ptr_array_index (devices, i); |
| 3791 | if (fu_device_has_instance_id (dev, "main-system-firmware")) |
| 3792 | fu_engine_get_history_set_hsi_attrs (self, dev); |
| 3793 | } |
| 3794 | |
Richard Hughes | 611f1a9 | 2018-01-11 11:54:28 +0000 | [diff] [blame] | 3795 | /* try to set the remote ID for each device */ |
| 3796 | for (guint i = 0; i < devices->len; i++) { |
| 3797 | FuDevice *dev = g_ptr_array_index (devices, i); |
| 3798 | FwupdRelease *rel; |
| 3799 | GPtrArray *csums; |
| 3800 | |
| 3801 | /* get the checksums */ |
| 3802 | rel = fu_device_get_release_default (dev); |
| 3803 | if (rel == NULL) |
| 3804 | continue; |
| 3805 | |
| 3806 | /* find the checksum that matches */ |
| 3807 | csums = fwupd_release_get_checksums (rel); |
| 3808 | for (guint j = 0; j < csums->len; j++) { |
| 3809 | const gchar *csum = g_ptr_array_index (csums, j); |
| 3810 | const gchar *remote_id = fu_engine_get_remote_id_for_checksum (self, csum); |
| 3811 | if (remote_id != NULL) { |
| 3812 | fu_device_add_flag (dev, FWUPD_DEVICE_FLAG_SUPPORTED); |
| 3813 | fwupd_release_set_remote_id (rel, remote_id); |
| 3814 | break; |
| 3815 | } |
| 3816 | } |
| 3817 | } |
| 3818 | |
Richard Hughes | 476363a | 2018-01-11 10:08:58 +0000 | [diff] [blame] | 3819 | return g_steal_pointer (&devices); |
| 3820 | } |
| 3821 | |
| 3822 | /** |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3823 | * fu_engine_get_remotes: |
| 3824 | * @self: A #FuEngine |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3825 | * @error: A #GError, or %NULL |
| 3826 | * |
| 3827 | * Gets the list of remotes in use by the engine. |
| 3828 | * |
| 3829 | * Returns: (transfer container) (element-type FwupdRemote): results |
| 3830 | **/ |
| 3831 | GPtrArray * |
| 3832 | fu_engine_get_remotes (FuEngine *self, GError **error) |
| 3833 | { |
| 3834 | GPtrArray *remotes; |
| 3835 | |
| 3836 | g_return_val_if_fail (FU_IS_ENGINE (self), NULL); |
| 3837 | g_return_val_if_fail (error == NULL || *error == NULL, NULL); |
| 3838 | |
Richard Hughes | d1808aa | 2019-12-10 15:20:30 +0000 | [diff] [blame] | 3839 | remotes = fu_remote_list_get_all (self->remote_list); |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 3840 | if (remotes->len == 0) { |
| 3841 | g_set_error (error, |
| 3842 | FWUPD_ERROR, |
| 3843 | FWUPD_ERROR_INTERNAL, |
| 3844 | "No remotes configured"); |
| 3845 | return NULL; |
| 3846 | } |
| 3847 | return g_ptr_array_ref (remotes); |
| 3848 | } |
| 3849 | |
Mario Limonciello | 46aaee8 | 2019-01-10 12:58:00 -0600 | [diff] [blame] | 3850 | /** |
| 3851 | * fu_engine_get_remote_by_id: |
| 3852 | * @self: A #FuEngine |
| 3853 | * @remote_id: A string representation of a remote |
| 3854 | * @error: A #GError, or %NULL |
| 3855 | * |
| 3856 | * Gets the FwupdRemote object. |
| 3857 | * |
| 3858 | * Returns: FwupdRemote |
| 3859 | **/ |
| 3860 | FwupdRemote * |
| 3861 | fu_engine_get_remote_by_id (FuEngine *self, const gchar *remote_id, GError **error) |
| 3862 | { |
| 3863 | g_autoptr(GPtrArray) remotes = NULL; |
| 3864 | |
| 3865 | remotes = fu_engine_get_remotes (self, error); |
| 3866 | if (remotes == NULL) |
| 3867 | return NULL; |
| 3868 | |
| 3869 | for (guint i = 0; i < remotes->len; i++) { |
| 3870 | FwupdRemote *remote = g_ptr_array_index (remotes, i); |
| 3871 | if (g_strcmp0 (remote_id, fwupd_remote_get_id (remote)) == 0) |
| 3872 | return remote; |
| 3873 | } |
| 3874 | |
| 3875 | g_set_error (error, FWUPD_ERROR, FWUPD_ERROR_INTERNAL, |
| 3876 | "Couldn't find remote %s", remote_id); |
| 3877 | |
| 3878 | return NULL; |
| 3879 | } |
| 3880 | |
| 3881 | |
Richard Hughes | 225f3a9 | 2017-09-13 19:38:51 +0100 | [diff] [blame] | 3882 | static gint |
Richard Hughes | 9a68084 | 2020-02-20 11:11:13 +0000 | [diff] [blame] | 3883 | fu_engine_sort_releases_cb (gconstpointer a, gconstpointer b, gpointer user_data) |
Richard Hughes | 225f3a9 | 2017-09-13 19:38:51 +0100 | [diff] [blame] | 3884 | { |
Richard Hughes | 9a68084 | 2020-02-20 11:11:13 +0000 | [diff] [blame] | 3885 | FuDevice *device = FU_DEVICE (user_data); |
Richard Hughes | 225f3a9 | 2017-09-13 19:38:51 +0100 | [diff] [blame] | 3886 | FwupdRelease *rel_a = FWUPD_RELEASE (*((FwupdRelease **) a)); |
| 3887 | FwupdRelease *rel_b = FWUPD_RELEASE (*((FwupdRelease **) b)); |
Richard Hughes | 9a68084 | 2020-02-20 11:11:13 +0000 | [diff] [blame] | 3888 | return fu_common_vercmp_full (fwupd_release_get_version (rel_b), |
| 3889 | fwupd_release_get_version (rel_a), |
| 3890 | fu_device_get_version_format (device)); |
Richard Hughes | 225f3a9 | 2017-09-13 19:38:51 +0100 | [diff] [blame] | 3891 | } |
| 3892 | |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 3893 | static gboolean |
Richard Hughes | 8dd4c1c | 2019-03-03 18:27:57 +0000 | [diff] [blame] | 3894 | fu_engine_check_release_is_approved (FuEngine *self, FwupdRelease *rel) |
| 3895 | { |
| 3896 | GPtrArray *csums = fwupd_release_get_checksums (rel); |
| 3897 | for (guint i = 0; i < csums->len; i++) { |
| 3898 | const gchar *csum = g_ptr_array_index (csums, i); |
| 3899 | g_debug ("checking %s against approved list", csum); |
| 3900 | if (g_hash_table_lookup (self->approved_firmware, csum) != NULL) |
| 3901 | return TRUE; |
| 3902 | } |
| 3903 | return FALSE; |
| 3904 | } |
| 3905 | |
| 3906 | static gboolean |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 3907 | fu_engine_add_releases_for_device_component (FuEngine *self, |
| 3908 | FuDevice *device, |
| 3909 | XbNode *component, |
| 3910 | GPtrArray *releases, |
| 3911 | GError **error) |
Richard Hughes | 650dade | 2017-12-14 14:43:11 +0000 | [diff] [blame] | 3912 | { |
Richard Hughes | 9a68084 | 2020-02-20 11:11:13 +0000 | [diff] [blame] | 3913 | FwupdVersionFormat fmt = fu_device_get_version_format (device); |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 3914 | g_autoptr(GError) error_local = NULL; |
| 3915 | g_autoptr(FuInstallTask) task = fu_install_task_new (device, component); |
| 3916 | g_autoptr(GPtrArray) releases_tmp = NULL; |
Richard Hughes | 650dade | 2017-12-14 14:43:11 +0000 | [diff] [blame] | 3917 | |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 3918 | if (!fu_engine_check_requirements (self, task, |
Richard Hughes | ce75627 | 2019-03-24 12:21:34 +0000 | [diff] [blame] | 3919 | FWUPD_INSTALL_FLAG_OFFLINE | |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 3920 | FWUPD_INSTALL_FLAG_ALLOW_REINSTALL | |
| 3921 | FWUPD_INSTALL_FLAG_ALLOW_OLDER, |
| 3922 | error)) |
| 3923 | return FALSE; |
| 3924 | |
| 3925 | /* get all releases */ |
| 3926 | releases_tmp = xb_node_query (component, "releases/release", 0, &error_local); |
| 3927 | if (releases_tmp == NULL) { |
| 3928 | if (g_error_matches (error_local, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) |
| 3929 | return TRUE; |
| 3930 | if (g_error_matches (error_local, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT)) |
| 3931 | return TRUE; |
| 3932 | g_propagate_error (error, g_steal_pointer (&error_local)); |
| 3933 | return FALSE; |
| 3934 | } |
| 3935 | for (guint i = 0; i < releases_tmp->len; i++) { |
| 3936 | XbNode *release = g_ptr_array_index (releases_tmp, i); |
Richard Hughes | 8dd4c1c | 2019-03-03 18:27:57 +0000 | [diff] [blame] | 3937 | const gchar *remote_id; |
Mario Limonciello | 32241f4 | 2019-01-24 10:12:41 -0600 | [diff] [blame] | 3938 | const gchar *update_message; |
Richard Hughes | 8e0cc80 | 2019-03-04 14:10:17 +0000 | [diff] [blame] | 3939 | gint vercmp; |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 3940 | GPtrArray *checksums; |
| 3941 | g_autoptr(FwupdRelease) rel = fwupd_release_new (); |
Richard Hughes | 0b3e9fd | 2019-04-08 11:13:20 +0100 | [diff] [blame] | 3942 | g_autoptr(GError) error_loop = NULL; |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 3943 | |
| 3944 | /* create new FwupdRelease for the XbNode */ |
Richard Hughes | 0b3e9fd | 2019-04-08 11:13:20 +0100 | [diff] [blame] | 3945 | if (!fu_engine_set_release_from_appstream (self, |
Richard Hughes | 2c40b37 | 2019-04-17 13:41:47 +0100 | [diff] [blame] | 3946 | device, |
Richard Hughes | 0b3e9fd | 2019-04-08 11:13:20 +0100 | [diff] [blame] | 3947 | rel, |
| 3948 | component, |
| 3949 | release, |
| 3950 | &error_loop)) { |
| 3951 | g_warning ("failed to set release for component: %s", |
| 3952 | error_loop->message); |
| 3953 | continue; |
| 3954 | } |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 3955 | |
Richard Hughes | 6e0c8f8 | 2018-11-11 21:46:41 +0000 | [diff] [blame] | 3956 | /* fall back to quirk-provided value */ |
| 3957 | if (fwupd_release_get_install_duration (rel) == 0) |
| 3958 | fwupd_release_set_install_duration (rel, fu_device_get_install_duration (device)); |
| 3959 | |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 3960 | /* invalid */ |
| 3961 | if (fwupd_release_get_uri (rel) == NULL) |
Richard Hughes | 650dade | 2017-12-14 14:43:11 +0000 | [diff] [blame] | 3962 | continue; |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 3963 | checksums = fwupd_release_get_checksums (rel); |
| 3964 | if (checksums->len == 0) |
| 3965 | continue; |
| 3966 | |
Richard Hughes | 8e0cc80 | 2019-03-04 14:10:17 +0000 | [diff] [blame] | 3967 | /* test for upgrade or downgrade */ |
Richard Hughes | 9a68084 | 2020-02-20 11:11:13 +0000 | [diff] [blame] | 3968 | vercmp = fu_common_vercmp_full (fwupd_release_get_version (rel), |
| 3969 | fu_device_get_version (device), |
| 3970 | fmt); |
Richard Hughes | 8e0cc80 | 2019-03-04 14:10:17 +0000 | [diff] [blame] | 3971 | if (vercmp > 0) |
| 3972 | fwupd_release_add_flag (rel, FWUPD_RELEASE_FLAG_IS_UPGRADE); |
| 3973 | else if (vercmp < 0) |
| 3974 | fwupd_release_add_flag (rel, FWUPD_RELEASE_FLAG_IS_DOWNGRADE); |
| 3975 | |
| 3976 | /* lower than allowed to downgrade to */ |
| 3977 | if (fu_device_get_version_lowest (device) != NULL && |
Richard Hughes | 9a68084 | 2020-02-20 11:11:13 +0000 | [diff] [blame] | 3978 | fu_common_vercmp_full (fwupd_release_get_version (rel), |
| 3979 | fu_device_get_version_lowest (device), |
| 3980 | fmt) < 0) { |
Richard Hughes | 8e0cc80 | 2019-03-04 14:10:17 +0000 | [diff] [blame] | 3981 | fwupd_release_add_flag (rel, FWUPD_RELEASE_FLAG_BLOCKED_VERSION); |
| 3982 | } |
| 3983 | |
Richard Hughes | 8dd4c1c | 2019-03-03 18:27:57 +0000 | [diff] [blame] | 3984 | /* check if remote is whitelisting firmware */ |
| 3985 | remote_id = fwupd_release_get_remote_id (rel); |
| 3986 | if (remote_id != NULL) { |
| 3987 | FwupdRemote *remote = fu_engine_get_remote_by_id (self, remote_id, NULL); |
| 3988 | if (remote != NULL && |
| 3989 | fwupd_remote_get_approval_required (remote) && |
| 3990 | !fu_engine_check_release_is_approved (self, rel)) { |
| 3991 | fwupd_release_add_flag (rel, FWUPD_RELEASE_FLAG_BLOCKED_APPROVAL); |
| 3992 | } |
| 3993 | } |
| 3994 | |
Mario Limonciello | 32241f4 | 2019-01-24 10:12:41 -0600 | [diff] [blame] | 3995 | /* add update message if exists but device doesn't already have one */ |
| 3996 | update_message = fwupd_release_get_update_message (rel); |
| 3997 | if (fwupd_device_get_update_message (FWUPD_DEVICE (device)) == NULL && |
| 3998 | update_message != NULL) { |
| 3999 | fwupd_device_set_update_message (FWUPD_DEVICE (device), update_message); |
| 4000 | } |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 4001 | /* success */ |
| 4002 | g_ptr_array_add (releases, g_steal_pointer (&rel)); |
Richard Hughes | 650dade | 2017-12-14 14:43:11 +0000 | [diff] [blame] | 4003 | } |
| 4004 | |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 4005 | /* success */ |
| 4006 | return TRUE; |
Richard Hughes | 650dade | 2017-12-14 14:43:11 +0000 | [diff] [blame] | 4007 | } |
| 4008 | |
Filipe LaÃns | d3a4fd3 | 2020-03-30 21:05:14 +0100 | [diff] [blame] | 4009 | GPtrArray * |
Richard Hughes | 97284b1 | 2017-09-13 17:07:58 +0100 | [diff] [blame] | 4010 | fu_engine_get_releases_for_device (FuEngine *self, FuDevice *device, GError **error) |
| 4011 | { |
| 4012 | GPtrArray *device_guids; |
| 4013 | GPtrArray *releases; |
| 4014 | const gchar *version; |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 4015 | g_autoptr(GError) error_all = NULL; |
| 4016 | g_autoptr(GError) error_local = NULL; |
| 4017 | g_autoptr(GPtrArray) components = NULL; |
| 4018 | g_autoptr(GString) xpath = g_string_new (NULL); |
Richard Hughes | 97284b1 | 2017-09-13 17:07:58 +0100 | [diff] [blame] | 4019 | |
| 4020 | /* get device version */ |
| 4021 | version = fu_device_get_version (device); |
| 4022 | if (version == NULL) { |
| 4023 | g_set_error (error, |
| 4024 | FWUPD_ERROR, |
| 4025 | FWUPD_ERROR_NOT_SUPPORTED, |
| 4026 | "no version set"); |
| 4027 | return NULL; |
| 4028 | } |
| 4029 | |
| 4030 | /* only show devices that can be updated */ |
| 4031 | if (!fu_device_has_flag (device, FWUPD_DEVICE_FLAG_UPDATABLE)) { |
Mario Limonciello | 7e4949c | 2019-12-09 10:21:20 -0600 | [diff] [blame] | 4032 | g_set_error_literal (error, |
| 4033 | FWUPD_ERROR, |
| 4034 | FWUPD_ERROR_NOT_SUPPORTED, |
| 4035 | "is not updatable"); |
Richard Hughes | 97284b1 | 2017-09-13 17:07:58 +0100 | [diff] [blame] | 4036 | return NULL; |
| 4037 | } |
| 4038 | |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 4039 | /* get all the components that provide any of these GUIDs */ |
Richard Hughes | 97284b1 | 2017-09-13 17:07:58 +0100 | [diff] [blame] | 4040 | device_guids = fu_device_get_guids (device); |
| 4041 | for (guint i = 0; i < device_guids->len; i++) { |
Richard Hughes | 97284b1 | 2017-09-13 17:07:58 +0100 | [diff] [blame] | 4042 | const gchar *guid = g_ptr_array_index (device_guids, i); |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 4043 | xb_string_append_union (xpath, |
| 4044 | "components/component/" |
Richard Hughes | 634da03 | 2018-11-05 11:42:20 +0000 | [diff] [blame] | 4045 | "provides/firmware[@type=$'flashed'][text()=$'%s']/" |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 4046 | "../..", guid); |
| 4047 | } |
| 4048 | components = xb_silo_query (self->silo, xpath->str, 0, &error_local); |
| 4049 | if (components == NULL) { |
Richard Hughes | a07a80f | 2018-12-03 14:57:33 +0000 | [diff] [blame] | 4050 | if (g_error_matches (error_local, G_IO_ERROR, G_IO_ERROR_NOT_FOUND) || |
| 4051 | g_error_matches (error_local, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT)) { |
Mario Limonciello | 7e4949c | 2019-12-09 10:21:20 -0600 | [diff] [blame] | 4052 | g_set_error_literal (error, |
| 4053 | FWUPD_ERROR, |
| 4054 | FWUPD_ERROR_NOTHING_TO_DO, |
| 4055 | "No releases found"); |
Richard Hughes | b095df6 | 2018-11-05 11:41:36 +0000 | [diff] [blame] | 4056 | return NULL; |
Richard Hughes | 97284b1 | 2017-09-13 17:07:58 +0100 | [diff] [blame] | 4057 | } |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 4058 | g_propagate_error (error, g_steal_pointer (&error_local)); |
Richard Hughes | b095df6 | 2018-11-05 11:41:36 +0000 | [diff] [blame] | 4059 | return NULL; |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 4060 | } |
| 4061 | |
| 4062 | /* find all the releases that pass all the requirements */ |
| 4063 | releases = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref); |
| 4064 | for (guint i = 0; i < components->len; i++) { |
| 4065 | XbNode *component = XB_NODE (g_ptr_array_index (components, i)); |
| 4066 | g_autoptr(GError) error_tmp = NULL; |
| 4067 | if (!fu_engine_add_releases_for_device_component (self, |
| 4068 | device, |
| 4069 | component, |
| 4070 | releases, |
| 4071 | &error_tmp)) { |
| 4072 | if (error_all == NULL) { |
| 4073 | error_all = g_steal_pointer (&error_tmp); |
| 4074 | continue; |
| 4075 | } |
| 4076 | |
| 4077 | /* assume the domain and code is the same */ |
| 4078 | g_prefix_error (&error_all, "%s, ", error_tmp->message); |
| 4079 | } |
| 4080 | } |
| 4081 | |
| 4082 | /* return the compound error */ |
| 4083 | if (releases->len == 0) { |
Richard Hughes | d56ad5b | 2018-11-12 10:48:06 +0000 | [diff] [blame] | 4084 | if (error_all != NULL) { |
Richard Hughes | 5b715e1 | 2019-04-08 13:33:59 +0100 | [diff] [blame] | 4085 | g_propagate_prefixed_error (error, g_steal_pointer (&error_all), |
Mario Limonciello | 7e4949c | 2019-12-09 10:21:20 -0600 | [diff] [blame] | 4086 | "No releases found: "); |
Richard Hughes | d56ad5b | 2018-11-12 10:48:06 +0000 | [diff] [blame] | 4087 | return NULL; |
| 4088 | } |
| 4089 | g_set_error (error, |
| 4090 | FWUPD_ERROR, |
| 4091 | FWUPD_ERROR_NOTHING_TO_DO, |
Mario Limonciello | 7e4949c | 2019-12-09 10:21:20 -0600 | [diff] [blame] | 4092 | "No releases found"); |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 4093 | return NULL; |
Richard Hughes | 97284b1 | 2017-09-13 17:07:58 +0100 | [diff] [blame] | 4094 | } |
| 4095 | return releases; |
| 4096 | } |
| 4097 | |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 4098 | /** |
| 4099 | * fu_engine_get_releases: |
| 4100 | * @self: A #FuEngine |
| 4101 | * @device_id: A device ID |
| 4102 | * @error: A #GError, or %NULL |
| 4103 | * |
| 4104 | * Gets the releases available for a specific device. |
| 4105 | * |
Richard Hughes | 93b1576 | 2017-09-15 11:05:23 +0100 | [diff] [blame] | 4106 | * Returns: (transfer container) (element-type FwupdDevice): results |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 4107 | **/ |
| 4108 | GPtrArray * |
| 4109 | fu_engine_get_releases (FuEngine *self, const gchar *device_id, GError **error) |
| 4110 | { |
Richard Hughes | 5a9a6bd | 2018-09-10 10:02:20 +0100 | [diff] [blame] | 4111 | g_autoptr(FuDevice) device = NULL; |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 4112 | g_autoptr(GPtrArray) releases = NULL; |
| 4113 | |
| 4114 | g_return_val_if_fail (FU_IS_ENGINE (self), NULL); |
| 4115 | g_return_val_if_fail (device_id != NULL, NULL); |
| 4116 | g_return_val_if_fail (error == NULL || *error == NULL, NULL); |
| 4117 | |
| 4118 | /* find the device */ |
Richard Hughes | 4012754 | 2018-01-12 20:25:55 +0000 | [diff] [blame] | 4119 | device = fu_device_list_get_by_id (self->device_list, device_id, error); |
Richard Hughes | 0a7e783 | 2017-11-22 11:01:13 +0000 | [diff] [blame] | 4120 | if (device == NULL) |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 4121 | return NULL; |
| 4122 | |
| 4123 | /* get all the releases for the device */ |
Richard Hughes | 0a7e783 | 2017-11-22 11:01:13 +0000 | [diff] [blame] | 4124 | releases = fu_engine_get_releases_for_device (self, device, error); |
Richard Hughes | 97284b1 | 2017-09-13 17:07:58 +0100 | [diff] [blame] | 4125 | if (releases == NULL) |
| 4126 | return NULL; |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 4127 | if (releases->len == 0) { |
| 4128 | g_set_error_literal (error, |
| 4129 | FWUPD_ERROR, |
| 4130 | FWUPD_ERROR_NOTHING_TO_DO, |
| 4131 | "No releases for device"); |
| 4132 | return NULL; |
| 4133 | } |
Richard Hughes | 9a68084 | 2020-02-20 11:11:13 +0000 | [diff] [blame] | 4134 | g_ptr_array_sort_with_data (releases, fu_engine_sort_releases_cb, device); |
Richard Hughes | 97284b1 | 2017-09-13 17:07:58 +0100 | [diff] [blame] | 4135 | return g_steal_pointer (&releases); |
| 4136 | } |
| 4137 | |
| 4138 | /** |
| 4139 | * fu_engine_get_downgrades: |
| 4140 | * @self: A #FuEngine |
| 4141 | * @device_id: A device ID |
| 4142 | * @error: A #GError, or %NULL |
| 4143 | * |
| 4144 | * Gets the downgrades available for a specific device. |
| 4145 | * |
Richard Hughes | 93b1576 | 2017-09-15 11:05:23 +0100 | [diff] [blame] | 4146 | * Returns: (transfer container) (element-type FwupdDevice): results |
Richard Hughes | 97284b1 | 2017-09-13 17:07:58 +0100 | [diff] [blame] | 4147 | **/ |
| 4148 | GPtrArray * |
| 4149 | fu_engine_get_downgrades (FuEngine *self, const gchar *device_id, GError **error) |
| 4150 | { |
Richard Hughes | 5a9a6bd | 2018-09-10 10:02:20 +0100 | [diff] [blame] | 4151 | g_autoptr(FuDevice) device = NULL; |
Richard Hughes | 97284b1 | 2017-09-13 17:07:58 +0100 | [diff] [blame] | 4152 | g_autoptr(GPtrArray) releases = NULL; |
| 4153 | g_autoptr(GPtrArray) releases_tmp = NULL; |
| 4154 | g_autoptr(GString) error_str = g_string_new (NULL); |
| 4155 | |
| 4156 | g_return_val_if_fail (FU_IS_ENGINE (self), NULL); |
| 4157 | g_return_val_if_fail (device_id != NULL, NULL); |
| 4158 | g_return_val_if_fail (error == NULL || *error == NULL, NULL); |
| 4159 | |
| 4160 | /* find the device */ |
Richard Hughes | 4012754 | 2018-01-12 20:25:55 +0000 | [diff] [blame] | 4161 | device = fu_device_list_get_by_id (self->device_list, device_id, error); |
Richard Hughes | 0a7e783 | 2017-11-22 11:01:13 +0000 | [diff] [blame] | 4162 | if (device == NULL) |
Richard Hughes | 97284b1 | 2017-09-13 17:07:58 +0100 | [diff] [blame] | 4163 | return NULL; |
| 4164 | |
| 4165 | /* get all the releases for the device */ |
Richard Hughes | 0a7e783 | 2017-11-22 11:01:13 +0000 | [diff] [blame] | 4166 | releases_tmp = fu_engine_get_releases_for_device (self, device, error); |
Richard Hughes | 97284b1 | 2017-09-13 17:07:58 +0100 | [diff] [blame] | 4167 | if (releases_tmp == NULL) |
| 4168 | return NULL; |
| 4169 | releases = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref); |
| 4170 | for (guint i = 0; i < releases_tmp->len; i++) { |
| 4171 | FwupdRelease *rel_tmp = g_ptr_array_index (releases_tmp, i); |
Richard Hughes | 97284b1 | 2017-09-13 17:07:58 +0100 | [diff] [blame] | 4172 | |
Richard Hughes | 8e0cc80 | 2019-03-04 14:10:17 +0000 | [diff] [blame] | 4173 | /* same as installed */ |
| 4174 | if (!fwupd_release_has_flag (rel_tmp, FWUPD_RELEASE_FLAG_IS_UPGRADE) && |
| 4175 | !fwupd_release_has_flag (rel_tmp, FWUPD_RELEASE_FLAG_IS_DOWNGRADE)) { |
Richard Hughes | 97284b1 | 2017-09-13 17:07:58 +0100 | [diff] [blame] | 4176 | g_string_append_printf (error_str, "%s=same, ", |
| 4177 | fwupd_release_get_version (rel_tmp)); |
| 4178 | g_debug ("ignoring %s as the same as %s", |
| 4179 | fwupd_release_get_version (rel_tmp), |
Richard Hughes | 0a7e783 | 2017-11-22 11:01:13 +0000 | [diff] [blame] | 4180 | fu_device_get_version (device)); |
Richard Hughes | 97284b1 | 2017-09-13 17:07:58 +0100 | [diff] [blame] | 4181 | continue; |
| 4182 | } |
Richard Hughes | 8e0cc80 | 2019-03-04 14:10:17 +0000 | [diff] [blame] | 4183 | |
| 4184 | /* newer than current */ |
| 4185 | if (fwupd_release_has_flag (rel_tmp, FWUPD_RELEASE_FLAG_IS_UPGRADE)) { |
Richard Hughes | 97284b1 | 2017-09-13 17:07:58 +0100 | [diff] [blame] | 4186 | g_string_append_printf (error_str, "%s=newer, ", |
| 4187 | fwupd_release_get_version (rel_tmp)); |
| 4188 | g_debug ("ignoring %s as newer than %s", |
| 4189 | fwupd_release_get_version (rel_tmp), |
Richard Hughes | 0a7e783 | 2017-11-22 11:01:13 +0000 | [diff] [blame] | 4190 | fu_device_get_version (device)); |
Richard Hughes | 97284b1 | 2017-09-13 17:07:58 +0100 | [diff] [blame] | 4191 | continue; |
| 4192 | } |
| 4193 | |
Richard Hughes | dce9120 | 2019-04-08 12:47:45 +0100 | [diff] [blame] | 4194 | /* don't show releases we are not allowed to downgrade to */ |
Richard Hughes | 8e0cc80 | 2019-03-04 14:10:17 +0000 | [diff] [blame] | 4195 | if (fwupd_release_has_flag (rel_tmp, FWUPD_RELEASE_FLAG_BLOCKED_VERSION)) { |
| 4196 | g_string_append_printf (error_str, "%s=lowest, ", |
| 4197 | fwupd_release_get_version (rel_tmp)); |
| 4198 | g_debug ("ignoring %s as older than lowest %s", |
| 4199 | fwupd_release_get_version (rel_tmp), |
| 4200 | fu_device_get_version_lowest (device)); |
| 4201 | continue; |
Richard Hughes | 97284b1 | 2017-09-13 17:07:58 +0100 | [diff] [blame] | 4202 | } |
| 4203 | g_ptr_array_add (releases, g_object_ref (rel_tmp)); |
| 4204 | } |
| 4205 | if (error_str->len > 2) |
| 4206 | g_string_truncate (error_str, error_str->len - 2); |
| 4207 | if (releases->len == 0) { |
| 4208 | if (error_str->len > 0) { |
| 4209 | g_set_error (error, |
| 4210 | FWUPD_ERROR, |
| 4211 | FWUPD_ERROR_NOTHING_TO_DO, |
Mario Limonciello | 7e4949c | 2019-12-09 10:21:20 -0600 | [diff] [blame] | 4212 | "current version is %s: %s", |
Richard Hughes | 0a7e783 | 2017-11-22 11:01:13 +0000 | [diff] [blame] | 4213 | fu_device_get_version (device), |
Richard Hughes | 97284b1 | 2017-09-13 17:07:58 +0100 | [diff] [blame] | 4214 | error_str->str); |
| 4215 | } else { |
| 4216 | g_set_error (error, |
| 4217 | FWUPD_ERROR, |
| 4218 | FWUPD_ERROR_NOTHING_TO_DO, |
Mario Limonciello | 7e4949c | 2019-12-09 10:21:20 -0600 | [diff] [blame] | 4219 | "current version is %s", |
Richard Hughes | 0a7e783 | 2017-11-22 11:01:13 +0000 | [diff] [blame] | 4220 | fu_device_get_version (device)); |
Richard Hughes | 97284b1 | 2017-09-13 17:07:58 +0100 | [diff] [blame] | 4221 | } |
| 4222 | return NULL; |
| 4223 | } |
Richard Hughes | 9a68084 | 2020-02-20 11:11:13 +0000 | [diff] [blame] | 4224 | g_ptr_array_sort_with_data (releases, fu_engine_sort_releases_cb, device); |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 4225 | return g_steal_pointer (&releases); |
| 4226 | } |
| 4227 | |
Richard Hughes | 8dd4c1c | 2019-03-03 18:27:57 +0000 | [diff] [blame] | 4228 | GPtrArray * |
| 4229 | fu_engine_get_approved_firmware (FuEngine *self) |
| 4230 | { |
| 4231 | GPtrArray *checksums = g_ptr_array_new_with_free_func (g_free); |
| 4232 | g_autoptr(GList) keys = g_hash_table_get_keys (self->approved_firmware); |
| 4233 | for (GList *l = keys; l != NULL; l = l->next) { |
| 4234 | const gchar *csum = l->data; |
| 4235 | g_ptr_array_add (checksums, g_strdup (csum)); |
| 4236 | } |
| 4237 | return checksums; |
| 4238 | } |
| 4239 | |
| 4240 | void |
| 4241 | fu_engine_add_approved_firmware (FuEngine *self, const gchar *checksum) |
| 4242 | { |
| 4243 | g_hash_table_add (self->approved_firmware, g_strdup (checksum)); |
| 4244 | } |
| 4245 | |
Richard Hughes | 3d60762 | 2019-03-07 16:59:27 +0000 | [diff] [blame] | 4246 | gchar * |
| 4247 | fu_engine_self_sign (FuEngine *self, |
| 4248 | const gchar *value, |
Richard Hughes | d5aab65 | 2020-02-25 12:47:50 +0000 | [diff] [blame] | 4249 | JcatSignFlags flags, |
Richard Hughes | 3d60762 | 2019-03-07 16:59:27 +0000 | [diff] [blame] | 4250 | GError **error) |
| 4251 | { |
Richard Hughes | d5aab65 | 2020-02-25 12:47:50 +0000 | [diff] [blame] | 4252 | g_autoptr(JcatBlob) jcat_signature = NULL; |
| 4253 | g_autoptr(JcatEngine) jcat_engine = NULL; |
| 4254 | g_autoptr(JcatResult) jcat_result = NULL; |
Richard Hughes | 3d60762 | 2019-03-07 16:59:27 +0000 | [diff] [blame] | 4255 | g_autoptr(GBytes) payload = NULL; |
Richard Hughes | 3d60762 | 2019-03-07 16:59:27 +0000 | [diff] [blame] | 4256 | |
| 4257 | /* create detached signature and verify */ |
Richard Hughes | d5aab65 | 2020-02-25 12:47:50 +0000 | [diff] [blame] | 4258 | jcat_engine = jcat_context_get_engine (self->jcat_context, |
| 4259 | JCAT_BLOB_KIND_PKCS7, |
| 4260 | error); |
| 4261 | if (jcat_engine == NULL) |
Richard Hughes | 3d60762 | 2019-03-07 16:59:27 +0000 | [diff] [blame] | 4262 | return NULL; |
| 4263 | payload = g_bytes_new (value, strlen (value)); |
Richard Hughes | d5aab65 | 2020-02-25 12:47:50 +0000 | [diff] [blame] | 4264 | jcat_signature = jcat_engine_self_sign (jcat_engine, payload, flags, error); |
| 4265 | if (jcat_signature == NULL) |
Richard Hughes | 3d60762 | 2019-03-07 16:59:27 +0000 | [diff] [blame] | 4266 | return NULL; |
Richard Hughes | d5aab65 | 2020-02-25 12:47:50 +0000 | [diff] [blame] | 4267 | jcat_result = jcat_engine_self_verify (jcat_engine, payload, |
| 4268 | jcat_blob_get_data (jcat_signature), |
| 4269 | JCAT_VERIFY_FLAG_NONE, error); |
| 4270 | if (jcat_result == NULL) |
Richard Hughes | 3d60762 | 2019-03-07 16:59:27 +0000 | [diff] [blame] | 4271 | return NULL; |
Richard Hughes | d5aab65 | 2020-02-25 12:47:50 +0000 | [diff] [blame] | 4272 | return jcat_blob_get_data_as_string (jcat_signature); |
Richard Hughes | 3d60762 | 2019-03-07 16:59:27 +0000 | [diff] [blame] | 4273 | } |
| 4274 | |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 4275 | /** |
Richard Hughes | a96413a | 2017-09-13 17:19:59 +0100 | [diff] [blame] | 4276 | * fu_engine_get_upgrades: |
| 4277 | * @self: A #FuEngine |
| 4278 | * @device_id: A device ID |
| 4279 | * @error: A #GError, or %NULL |
| 4280 | * |
| 4281 | * Gets the upgrades available for a specific device. |
| 4282 | * |
Richard Hughes | 93b1576 | 2017-09-15 11:05:23 +0100 | [diff] [blame] | 4283 | * Returns: (transfer container) (element-type FwupdDevice): results |
Richard Hughes | a96413a | 2017-09-13 17:19:59 +0100 | [diff] [blame] | 4284 | **/ |
| 4285 | GPtrArray * |
| 4286 | fu_engine_get_upgrades (FuEngine *self, const gchar *device_id, GError **error) |
| 4287 | { |
Richard Hughes | 5a9a6bd | 2018-09-10 10:02:20 +0100 | [diff] [blame] | 4288 | g_autoptr(FuDevice) device = NULL; |
Richard Hughes | a96413a | 2017-09-13 17:19:59 +0100 | [diff] [blame] | 4289 | g_autoptr(GPtrArray) releases = NULL; |
| 4290 | g_autoptr(GPtrArray) releases_tmp = NULL; |
| 4291 | g_autoptr(GString) error_str = g_string_new (NULL); |
| 4292 | |
| 4293 | g_return_val_if_fail (FU_IS_ENGINE (self), NULL); |
| 4294 | g_return_val_if_fail (device_id != NULL, NULL); |
| 4295 | g_return_val_if_fail (error == NULL || *error == NULL, NULL); |
| 4296 | |
| 4297 | /* find the device */ |
Richard Hughes | 4012754 | 2018-01-12 20:25:55 +0000 | [diff] [blame] | 4298 | device = fu_device_list_get_by_id (self->device_list, device_id, error); |
Richard Hughes | 0a7e783 | 2017-11-22 11:01:13 +0000 | [diff] [blame] | 4299 | if (device == NULL) |
Richard Hughes | a96413a | 2017-09-13 17:19:59 +0100 | [diff] [blame] | 4300 | return NULL; |
| 4301 | |
Mario Limonciello | fc13935 | 2018-09-13 10:06:39 -0500 | [diff] [blame] | 4302 | /* don't show upgrades again until we reboot */ |
| 4303 | if (fu_device_get_update_state (device) == FWUPD_UPDATE_STATE_NEEDS_REBOOT) { |
Mario Limonciello | 7e4949c | 2019-12-09 10:21:20 -0600 | [diff] [blame] | 4304 | g_set_error_literal (error, |
| 4305 | FWUPD_ERROR, |
| 4306 | FWUPD_ERROR_NOTHING_TO_DO, |
| 4307 | "A reboot is pending"); |
Mario Limonciello | fc13935 | 2018-09-13 10:06:39 -0500 | [diff] [blame] | 4308 | return NULL; |
| 4309 | } |
| 4310 | |
Richard Hughes | a96413a | 2017-09-13 17:19:59 +0100 | [diff] [blame] | 4311 | /* get all the releases for the device */ |
Richard Hughes | 0a7e783 | 2017-11-22 11:01:13 +0000 | [diff] [blame] | 4312 | releases_tmp = fu_engine_get_releases_for_device (self, device, error); |
Richard Hughes | a96413a | 2017-09-13 17:19:59 +0100 | [diff] [blame] | 4313 | if (releases_tmp == NULL) |
| 4314 | return NULL; |
| 4315 | releases = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref); |
| 4316 | for (guint i = 0; i < releases_tmp->len; i++) { |
| 4317 | FwupdRelease *rel_tmp = g_ptr_array_index (releases_tmp, i); |
Richard Hughes | a96413a | 2017-09-13 17:19:59 +0100 | [diff] [blame] | 4318 | |
Richard Hughes | 8e0cc80 | 2019-03-04 14:10:17 +0000 | [diff] [blame] | 4319 | /* same as installed */ |
| 4320 | if (!fwupd_release_has_flag (rel_tmp, FWUPD_RELEASE_FLAG_IS_UPGRADE) && |
| 4321 | !fwupd_release_has_flag (rel_tmp, FWUPD_RELEASE_FLAG_IS_DOWNGRADE)) { |
Richard Hughes | a96413a | 2017-09-13 17:19:59 +0100 | [diff] [blame] | 4322 | g_string_append_printf (error_str, "%s=same, ", |
| 4323 | fwupd_release_get_version (rel_tmp)); |
| 4324 | g_debug ("ignoring %s as the same as %s", |
| 4325 | fwupd_release_get_version (rel_tmp), |
Richard Hughes | 0a7e783 | 2017-11-22 11:01:13 +0000 | [diff] [blame] | 4326 | fu_device_get_version (device)); |
Richard Hughes | a96413a | 2017-09-13 17:19:59 +0100 | [diff] [blame] | 4327 | continue; |
| 4328 | } |
Richard Hughes | 8e0cc80 | 2019-03-04 14:10:17 +0000 | [diff] [blame] | 4329 | |
| 4330 | /* older than current */ |
| 4331 | if (fwupd_release_has_flag (rel_tmp, FWUPD_RELEASE_FLAG_IS_DOWNGRADE)) { |
Richard Hughes | a96413a | 2017-09-13 17:19:59 +0100 | [diff] [blame] | 4332 | g_string_append_printf (error_str, "%s=older, ", |
| 4333 | fwupd_release_get_version (rel_tmp)); |
| 4334 | g_debug ("ignoring %s as older than %s", |
| 4335 | fwupd_release_get_version (rel_tmp), |
Richard Hughes | 0a7e783 | 2017-11-22 11:01:13 +0000 | [diff] [blame] | 4336 | fu_device_get_version (device)); |
Richard Hughes | a96413a | 2017-09-13 17:19:59 +0100 | [diff] [blame] | 4337 | continue; |
| 4338 | } |
Richard Hughes | 8dd4c1c | 2019-03-03 18:27:57 +0000 | [diff] [blame] | 4339 | |
| 4340 | /* not approved */ |
| 4341 | if (fwupd_release_has_flag (rel_tmp, FWUPD_RELEASE_FLAG_BLOCKED_APPROVAL)) { |
| 4342 | g_string_append_printf (error_str, "%s=not-approved, ", |
| 4343 | fwupd_release_get_version (rel_tmp)); |
| 4344 | g_debug ("ignoring %s as not approved as required by %s", |
| 4345 | fwupd_release_get_version (rel_tmp), |
| 4346 | fwupd_release_get_remote_id (rel_tmp)); |
| 4347 | continue; |
| 4348 | } |
| 4349 | |
Richard Hughes | a96413a | 2017-09-13 17:19:59 +0100 | [diff] [blame] | 4350 | g_ptr_array_add (releases, g_object_ref (rel_tmp)); |
| 4351 | } |
| 4352 | if (error_str->len > 2) |
| 4353 | g_string_truncate (error_str, error_str->len - 2); |
| 4354 | if (releases->len == 0) { |
| 4355 | if (error_str->len > 0) { |
| 4356 | g_set_error (error, |
| 4357 | FWUPD_ERROR, |
| 4358 | FWUPD_ERROR_NOTHING_TO_DO, |
Mario Limonciello | 7e4949c | 2019-12-09 10:21:20 -0600 | [diff] [blame] | 4359 | "current version is %s: %s", |
Richard Hughes | 0a7e783 | 2017-11-22 11:01:13 +0000 | [diff] [blame] | 4360 | fu_device_get_version (device), |
Richard Hughes | a96413a | 2017-09-13 17:19:59 +0100 | [diff] [blame] | 4361 | error_str->str); |
| 4362 | } else { |
| 4363 | g_set_error (error, |
| 4364 | FWUPD_ERROR, |
| 4365 | FWUPD_ERROR_NOTHING_TO_DO, |
Mario Limonciello | 7e4949c | 2019-12-09 10:21:20 -0600 | [diff] [blame] | 4366 | "current version is %s", |
Richard Hughes | 0a7e783 | 2017-11-22 11:01:13 +0000 | [diff] [blame] | 4367 | fu_device_get_version (device)); |
Richard Hughes | a96413a | 2017-09-13 17:19:59 +0100 | [diff] [blame] | 4368 | } |
| 4369 | return NULL; |
| 4370 | } |
Richard Hughes | 9a68084 | 2020-02-20 11:11:13 +0000 | [diff] [blame] | 4371 | g_ptr_array_sort_with_data (releases, fu_engine_sort_releases_cb, device); |
Richard Hughes | a96413a | 2017-09-13 17:19:59 +0100 | [diff] [blame] | 4372 | return g_steal_pointer (&releases); |
| 4373 | } |
| 4374 | |
| 4375 | /** |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 4376 | * fu_engine_clear_results: |
| 4377 | * @self: A #FuEngine |
| 4378 | * @device_id: A device ID |
| 4379 | * @error: A #GError, or %NULL |
| 4380 | * |
| 4381 | * Clear the historical state of a specific device operation. |
| 4382 | * |
| 4383 | * Returns: %TRUE for success |
| 4384 | **/ |
| 4385 | gboolean |
| 4386 | fu_engine_clear_results (FuEngine *self, const gchar *device_id, GError **error) |
| 4387 | { |
Richard Hughes | 65e44ca | 2018-01-30 17:26:30 +0000 | [diff] [blame] | 4388 | g_autoptr(FuDevice) device = NULL; |
Richard Hughes | 3483410 | 2017-11-21 21:55:00 +0000 | [diff] [blame] | 4389 | FuPlugin *plugin; |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 4390 | |
| 4391 | g_return_val_if_fail (FU_IS_ENGINE (self), FALSE); |
| 4392 | g_return_val_if_fail (device_id != NULL, FALSE); |
| 4393 | g_return_val_if_fail (error == NULL || *error == NULL, FALSE); |
| 4394 | |
| 4395 | /* find the device */ |
Richard Hughes | bc3a4e1 | 2018-01-06 22:41:47 +0000 | [diff] [blame] | 4396 | device = fu_engine_get_item_by_id_fallback_history (self, device_id, error); |
Richard Hughes | 0a7e783 | 2017-11-22 11:01:13 +0000 | [diff] [blame] | 4397 | if (device == NULL) |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 4398 | return FALSE; |
| 4399 | |
Richard Hughes | 65e44ca | 2018-01-30 17:26:30 +0000 | [diff] [blame] | 4400 | /* already set on the database */ |
| 4401 | if (fu_device_has_flag (device, FWUPD_DEVICE_FLAG_NOTIFIED)) { |
| 4402 | g_set_error_literal (error, |
| 4403 | FWUPD_ERROR, |
| 4404 | FWUPD_ERROR_NOT_SUPPORTED, |
| 4405 | "device already has notified flag"); |
| 4406 | return FALSE; |
| 4407 | } |
| 4408 | |
| 4409 | /* call into the plugin if it still exists */ |
Richard Hughes | e7e9545 | 2017-11-22 09:05:53 +0000 | [diff] [blame] | 4410 | plugin = fu_plugin_list_find_by_name (self->plugin_list, |
Richard Hughes | 0a7e783 | 2017-11-22 11:01:13 +0000 | [diff] [blame] | 4411 | fu_device_get_plugin (device), |
Richard Hughes | e7e9545 | 2017-11-22 09:05:53 +0000 | [diff] [blame] | 4412 | error); |
Richard Hughes | 65e44ca | 2018-01-30 17:26:30 +0000 | [diff] [blame] | 4413 | if (plugin != NULL) { |
| 4414 | if (!fu_plugin_runner_clear_results (plugin, device, error)) |
| 4415 | return FALSE; |
| 4416 | } |
Richard Hughes | 3483410 | 2017-11-21 21:55:00 +0000 | [diff] [blame] | 4417 | |
Richard Hughes | 65e44ca | 2018-01-30 17:26:30 +0000 | [diff] [blame] | 4418 | /* override */ |
Richard Hughes | c0cd023 | 2018-01-31 15:02:00 +0000 | [diff] [blame] | 4419 | fu_device_add_flag (device, FWUPD_DEVICE_FLAG_NOTIFIED); |
Richard Hughes | 0bbef29 | 2019-11-01 12:15:15 +0000 | [diff] [blame] | 4420 | return fu_history_modify_device (self->history, device, error); |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 4421 | } |
| 4422 | |
| 4423 | /** |
| 4424 | * fu_engine_get_results: |
| 4425 | * @self: A #FuEngine |
| 4426 | * @device_id: A device ID |
| 4427 | * @error: A #GError, or %NULL |
| 4428 | * |
| 4429 | * Gets the historical state of a specific device operation. |
| 4430 | * |
Richard Hughes | 93b1576 | 2017-09-15 11:05:23 +0100 | [diff] [blame] | 4431 | * Returns: (transfer container): a #FwupdDevice, or %NULL |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 4432 | **/ |
Richard Hughes | 93b1576 | 2017-09-15 11:05:23 +0100 | [diff] [blame] | 4433 | FwupdDevice * |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 4434 | fu_engine_get_results (FuEngine *self, const gchar *device_id, GError **error) |
| 4435 | { |
Richard Hughes | 65e44ca | 2018-01-30 17:26:30 +0000 | [diff] [blame] | 4436 | g_autoptr(FuDevice) device = NULL; |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 4437 | |
| 4438 | g_return_val_if_fail (FU_IS_ENGINE (self), NULL); |
| 4439 | g_return_val_if_fail (device_id != NULL, NULL); |
| 4440 | g_return_val_if_fail (error == NULL || *error == NULL, NULL); |
| 4441 | |
| 4442 | /* find the device */ |
Richard Hughes | bc3a4e1 | 2018-01-06 22:41:47 +0000 | [diff] [blame] | 4443 | device = fu_engine_get_item_by_id_fallback_history (self, device_id, error); |
Richard Hughes | 0a7e783 | 2017-11-22 11:01:13 +0000 | [diff] [blame] | 4444 | if (device == NULL) |
Richard Hughes | fe221dc | 2018-05-29 09:33:44 +0100 | [diff] [blame] | 4445 | return NULL; |
Richard Hughes | 3483410 | 2017-11-21 21:55:00 +0000 | [diff] [blame] | 4446 | |
Richard Hughes | 65e44ca | 2018-01-30 17:26:30 +0000 | [diff] [blame] | 4447 | /* the notification has already been shown to the user */ |
| 4448 | if (fu_device_has_flag (device, FWUPD_DEVICE_FLAG_NOTIFIED)) { |
| 4449 | g_set_error (error, |
| 4450 | FWUPD_ERROR, |
| 4451 | FWUPD_ERROR_NOTHING_TO_DO, |
Richard Hughes | 7e77bf3 | 2018-05-08 14:56:46 +0100 | [diff] [blame] | 4452 | "User has already been notified about %s [%s]", |
| 4453 | fu_device_get_name (device), |
Richard Hughes | 65e44ca | 2018-01-30 17:26:30 +0000 | [diff] [blame] | 4454 | fu_device_get_id (device)); |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 4455 | return NULL; |
Richard Hughes | 65e44ca | 2018-01-30 17:26:30 +0000 | [diff] [blame] | 4456 | } |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 4457 | |
Richard Hughes | 65e44ca | 2018-01-30 17:26:30 +0000 | [diff] [blame] | 4458 | /* success */ |
Richard Hughes | eec8a3c | 2018-01-02 20:37:31 +0000 | [diff] [blame] | 4459 | return g_object_ref (FWUPD_DEVICE (device)); |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 4460 | } |
| 4461 | |
| 4462 | static void |
| 4463 | fu_engine_plugins_setup (FuEngine *self) |
| 4464 | { |
Richard Hughes | e671c05 | 2018-09-18 10:17:15 +0100 | [diff] [blame] | 4465 | GPtrArray *plugins = fu_plugin_list_get_all (self->plugin_list); |
Richard Hughes | e7e9545 | 2017-11-22 09:05:53 +0000 | [diff] [blame] | 4466 | for (guint i = 0; i < plugins->len; i++) { |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 4467 | g_autoptr(GError) error = NULL; |
Richard Hughes | e7e9545 | 2017-11-22 09:05:53 +0000 | [diff] [blame] | 4468 | FuPlugin *plugin = g_ptr_array_index (plugins, i); |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 4469 | if (!fu_plugin_runner_startup (plugin, &error)) { |
| 4470 | fu_plugin_set_enabled (plugin, FALSE); |
| 4471 | g_message ("disabling plugin because: %s", error->message); |
| 4472 | } |
| 4473 | } |
| 4474 | } |
| 4475 | |
| 4476 | static void |
Richard Hughes | 2de8f13 | 2018-01-17 09:12:02 +0000 | [diff] [blame] | 4477 | fu_engine_plugins_coldplug (FuEngine *self, gboolean is_recoldplug) |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 4478 | { |
Richard Hughes | e7e9545 | 2017-11-22 09:05:53 +0000 | [diff] [blame] | 4479 | GPtrArray *plugins; |
Richard Hughes | 535664c | 2017-07-24 10:30:09 +0100 | [diff] [blame] | 4480 | g_autoptr(GString) str = g_string_new (NULL); |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 4481 | |
| 4482 | /* don't allow coldplug to be scheduled when in coldplug */ |
| 4483 | self->coldplug_running = TRUE; |
| 4484 | |
| 4485 | /* prepare */ |
Richard Hughes | e7e9545 | 2017-11-22 09:05:53 +0000 | [diff] [blame] | 4486 | plugins = fu_plugin_list_get_all (self->plugin_list); |
| 4487 | for (guint i = 0; i < plugins->len; i++) { |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 4488 | g_autoptr(GError) error = NULL; |
Richard Hughes | e7e9545 | 2017-11-22 09:05:53 +0000 | [diff] [blame] | 4489 | FuPlugin *plugin = g_ptr_array_index (plugins, i); |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 4490 | if (!fu_plugin_runner_coldplug_prepare (plugin, &error)) |
| 4491 | g_warning ("failed to prepare coldplug: %s", error->message); |
| 4492 | } |
| 4493 | |
| 4494 | /* do this in one place */ |
| 4495 | if (self->coldplug_delay > 0) { |
| 4496 | g_debug ("sleeping for %ums", self->coldplug_delay); |
| 4497 | g_usleep (self->coldplug_delay * 1000); |
| 4498 | } |
| 4499 | |
| 4500 | /* exec */ |
Richard Hughes | e7e9545 | 2017-11-22 09:05:53 +0000 | [diff] [blame] | 4501 | for (guint i = 0; i < plugins->len; i++) { |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 4502 | g_autoptr(GError) error = NULL; |
Richard Hughes | e7e9545 | 2017-11-22 09:05:53 +0000 | [diff] [blame] | 4503 | FuPlugin *plugin = g_ptr_array_index (plugins, i); |
Richard Hughes | 2de8f13 | 2018-01-17 09:12:02 +0000 | [diff] [blame] | 4504 | if (is_recoldplug) { |
| 4505 | if (!fu_plugin_runner_recoldplug (plugin, &error)) |
| 4506 | g_message ("failed recoldplug: %s", error->message); |
| 4507 | } else { |
| 4508 | if (!fu_plugin_runner_coldplug (plugin, &error)) { |
| 4509 | fu_plugin_set_enabled (plugin, FALSE); |
| 4510 | g_message ("disabling plugin because: %s", |
| 4511 | error->message); |
| 4512 | } |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 4513 | } |
| 4514 | } |
| 4515 | |
| 4516 | /* cleanup */ |
Richard Hughes | e7e9545 | 2017-11-22 09:05:53 +0000 | [diff] [blame] | 4517 | for (guint i = 0; i < plugins->len; i++) { |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 4518 | g_autoptr(GError) error = NULL; |
Richard Hughes | e7e9545 | 2017-11-22 09:05:53 +0000 | [diff] [blame] | 4519 | FuPlugin *plugin = g_ptr_array_index (plugins, i); |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 4520 | if (!fu_plugin_runner_coldplug_cleanup (plugin, &error)) |
| 4521 | g_warning ("failed to cleanup coldplug: %s", error->message); |
| 4522 | } |
| 4523 | |
Richard Hughes | 535664c | 2017-07-24 10:30:09 +0100 | [diff] [blame] | 4524 | /* print what we do have */ |
Richard Hughes | e7e9545 | 2017-11-22 09:05:53 +0000 | [diff] [blame] | 4525 | for (guint i = 0; i < plugins->len; i++) { |
| 4526 | FuPlugin *plugin = g_ptr_array_index (plugins, i); |
Richard Hughes | 535664c | 2017-07-24 10:30:09 +0100 | [diff] [blame] | 4527 | if (!fu_plugin_get_enabled (plugin)) |
| 4528 | continue; |
| 4529 | g_string_append_printf (str, "%s, ", fu_plugin_get_name (plugin)); |
| 4530 | } |
| 4531 | if (str->len > 2) { |
| 4532 | g_string_truncate (str, str->len - 2); |
Mario Limonciello | 59cd470 | 2018-08-09 12:43:47 -0500 | [diff] [blame] | 4533 | g_debug ("using plugins: %s", str->str); |
Richard Hughes | 535664c | 2017-07-24 10:30:09 +0100 | [diff] [blame] | 4534 | } |
| 4535 | |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 4536 | /* we can recoldplug from this point on */ |
| 4537 | self->coldplug_running = FALSE; |
| 4538 | } |
| 4539 | |
| 4540 | static void |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 4541 | fu_engine_plugin_device_register (FuEngine *self, FuDevice *device) |
| 4542 | { |
Richard Hughes | e7e9545 | 2017-11-22 09:05:53 +0000 | [diff] [blame] | 4543 | GPtrArray *plugins; |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 4544 | if (fu_device_has_flag (device, FWUPD_DEVICE_FLAG_REGISTERED)) { |
| 4545 | g_warning ("already registered %s, ignoring", |
| 4546 | fu_device_get_id (device)); |
| 4547 | return; |
| 4548 | } |
Richard Hughes | e7e9545 | 2017-11-22 09:05:53 +0000 | [diff] [blame] | 4549 | plugins = fu_plugin_list_get_all (self->plugin_list); |
| 4550 | for (guint i = 0; i < plugins->len; i++) { |
| 4551 | FuPlugin *plugin = g_ptr_array_index (plugins, i); |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 4552 | fu_plugin_runner_device_register (plugin, device); |
| 4553 | } |
| 4554 | fu_device_add_flag (device, FWUPD_DEVICE_FLAG_REGISTERED); |
| 4555 | } |
| 4556 | |
| 4557 | static void |
| 4558 | fu_engine_plugin_device_register_cb (FuPlugin *plugin, |
| 4559 | FuDevice *device, |
| 4560 | gpointer user_data) |
| 4561 | { |
| 4562 | FuEngine *self = FU_ENGINE (user_data); |
| 4563 | fu_engine_plugin_device_register (self, device); |
| 4564 | } |
| 4565 | |
| 4566 | static void |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 4567 | fu_engine_plugin_device_added_cb (FuPlugin *plugin, |
| 4568 | FuDevice *device, |
| 4569 | gpointer user_data) |
| 4570 | { |
Richard Hughes | 4299ba0 | 2020-04-14 15:40:56 +0100 | [diff] [blame] | 4571 | FuEngine *self = FU_ENGINE (user_data); |
Richard Hughes | fecc438 | 2020-04-15 11:24:34 +0100 | [diff] [blame] | 4572 | |
| 4573 | /* plugin has prio and device not already set from quirk */ |
| 4574 | if (fu_plugin_get_priority (plugin) > 0 && |
| 4575 | fu_device_get_priority (device) == 0) { |
| 4576 | g_debug ("auto-setting %s priority to %u", |
| 4577 | fu_device_get_id (device), |
| 4578 | fu_plugin_get_priority (plugin)); |
| 4579 | fu_device_set_priority (device, fu_plugin_get_priority (plugin)); |
| 4580 | } |
| 4581 | |
Richard Hughes | 0a7e783 | 2017-11-22 11:01:13 +0000 | [diff] [blame] | 4582 | fu_engine_add_device (self, device); |
| 4583 | } |
| 4584 | |
Richard Hughes | 5e44729 | 2018-04-27 14:25:54 +0100 | [diff] [blame] | 4585 | static void |
| 4586 | fu_engine_adopt_children (FuEngine *self, FuDevice *device) |
| 4587 | { |
| 4588 | GPtrArray *guids; |
| 4589 | g_autoptr(GPtrArray) devices = fu_device_list_get_active (self->device_list); |
| 4590 | |
| 4591 | /* find the parent GUID in any existing device */ |
| 4592 | guids = fu_device_get_parent_guids (device); |
| 4593 | for (guint j = 0; j < guids->len; j++) { |
| 4594 | const gchar *guid = g_ptr_array_index (guids, j); |
| 4595 | for (guint i = 0; i < devices->len; i++) { |
| 4596 | FuDevice *device_tmp = g_ptr_array_index (devices, i); |
| 4597 | if (fu_device_get_parent (device) != NULL) |
| 4598 | continue; |
| 4599 | if (fu_device_has_guid (device_tmp, guid)) { |
Richard Hughes | 7e77bf3 | 2018-05-08 14:56:46 +0100 | [diff] [blame] | 4600 | g_debug ("setting parent of %s [%s] to be %s [%s]", |
| 4601 | fu_device_get_name (device), |
Richard Hughes | 5e44729 | 2018-04-27 14:25:54 +0100 | [diff] [blame] | 4602 | fu_device_get_id (device), |
Richard Hughes | 7e77bf3 | 2018-05-08 14:56:46 +0100 | [diff] [blame] | 4603 | fu_device_get_name (device_tmp), |
Richard Hughes | 5e44729 | 2018-04-27 14:25:54 +0100 | [diff] [blame] | 4604 | fu_device_get_id (device_tmp)); |
Richard Hughes | 2ab379e | 2020-04-09 16:03:36 +0100 | [diff] [blame] | 4605 | fu_device_set_parent (device, device_tmp); |
Richard Hughes | 5e44729 | 2018-04-27 14:25:54 +0100 | [diff] [blame] | 4606 | break; |
| 4607 | } |
| 4608 | } |
| 4609 | } |
| 4610 | |
| 4611 | /* the new device is the parent to an existing child */ |
| 4612 | guids = fu_device_get_guids (device); |
| 4613 | for (guint j = 0; j < guids->len; j++) { |
| 4614 | const gchar *guid = g_ptr_array_index (guids, j); |
| 4615 | for (guint i = 0; i < devices->len; i++) { |
| 4616 | FuDevice *device_tmp = g_ptr_array_index (devices, i); |
| 4617 | if (fu_device_get_parent (device_tmp) != NULL) |
| 4618 | continue; |
| 4619 | if (fu_device_has_parent_guid (device_tmp, guid)) { |
Richard Hughes | 7e77bf3 | 2018-05-08 14:56:46 +0100 | [diff] [blame] | 4620 | g_debug ("setting parent of %s [%s] to be %s [%s]", |
| 4621 | fu_device_get_name (device_tmp), |
Richard Hughes | 5e44729 | 2018-04-27 14:25:54 +0100 | [diff] [blame] | 4622 | fu_device_get_id (device_tmp), |
Richard Hughes | 7e77bf3 | 2018-05-08 14:56:46 +0100 | [diff] [blame] | 4623 | fu_device_get_name (device), |
Richard Hughes | 5e44729 | 2018-04-27 14:25:54 +0100 | [diff] [blame] | 4624 | fu_device_get_id (device)); |
Richard Hughes | 2ab379e | 2020-04-09 16:03:36 +0100 | [diff] [blame] | 4625 | fu_device_set_parent (device_tmp, device); |
Richard Hughes | 5e44729 | 2018-04-27 14:25:54 +0100 | [diff] [blame] | 4626 | } |
| 4627 | } |
| 4628 | } |
| 4629 | } |
| 4630 | |
Mario Limonciello | 96a0dd5 | 2019-02-25 13:50:03 -0600 | [diff] [blame] | 4631 | static void |
Richard Hughes | 35ca4cb | 2020-04-14 17:09:01 +0100 | [diff] [blame] | 4632 | fu_engine_set_proxy_device (FuEngine *self, FuDevice *device) |
| 4633 | { |
| 4634 | GPtrArray *guids; |
| 4635 | g_autoptr(FuDevice) proxy = NULL; |
| 4636 | g_autoptr(GPtrArray) devices = NULL; |
| 4637 | |
| 4638 | if (fu_device_get_proxy (device) != NULL) |
| 4639 | return; |
| 4640 | if (fu_device_get_proxy_guid (device) == NULL) |
| 4641 | return; |
| 4642 | |
| 4643 | /* find the proxy GUID in any existing device */ |
| 4644 | proxy = fu_device_list_get_by_guid (self->device_list, |
| 4645 | fu_device_get_proxy_guid (device), |
| 4646 | NULL); |
| 4647 | if (proxy != NULL) { |
| 4648 | g_debug ("setting proxy of %s to %s for %s", |
| 4649 | fu_device_get_id (proxy), |
| 4650 | fu_device_get_id (device), |
| 4651 | fu_device_get_proxy_guid (device)); |
| 4652 | fu_device_set_proxy (device, proxy); |
| 4653 | return; |
| 4654 | } |
| 4655 | |
| 4656 | /* are we the parent of an existing device */ |
| 4657 | guids = fu_device_get_guids (device); |
| 4658 | for (guint j = 0; j < guids->len; j++) { |
| 4659 | const gchar *guid = g_ptr_array_index (guids, j); |
| 4660 | devices = fu_device_list_get_active (self->device_list); |
| 4661 | for (guint i = 0; i < devices->len; i++) { |
| 4662 | FuDevice *device_tmp = g_ptr_array_index (devices, i); |
| 4663 | if (g_strcmp0 (fu_device_get_proxy_guid (device_tmp), guid) == 0) { |
| 4664 | g_debug ("adding proxy of %s to %s for %s", |
| 4665 | fu_device_get_id (device), |
| 4666 | fu_device_get_id (device_tmp), |
| 4667 | guid); |
| 4668 | fu_device_set_proxy (device_tmp, device); |
| 4669 | return; |
| 4670 | } |
| 4671 | } |
| 4672 | } |
| 4673 | |
| 4674 | /* nothing found */ |
| 4675 | g_warning ("did not find proxy device %s", |
| 4676 | fu_device_get_proxy_guid (device)); |
| 4677 | } |
| 4678 | |
| 4679 | static void |
Mario Limonciello | 96a0dd5 | 2019-02-25 13:50:03 -0600 | [diff] [blame] | 4680 | fu_engine_device_inherit_history (FuEngine *self, FuDevice *device) |
| 4681 | { |
| 4682 | g_autoptr(FuDevice) device_history = NULL; |
| 4683 | |
| 4684 | /* any success or failed update? */ |
| 4685 | device_history = fu_history_get_device_by_id (self->history, |
| 4686 | fu_device_get_id (device), |
| 4687 | NULL); |
| 4688 | if (device_history == NULL) |
| 4689 | return; |
| 4690 | |
| 4691 | /* the device is still running the old firmware version and so if it |
| 4692 | * required activation before, it still requires it now -- note: |
| 4693 | * we can't just check for version_new=version to allow for re-installs */ |
| 4694 | if (fu_device_has_flag (device_history, FWUPD_DEVICE_FLAG_NEEDS_ACTIVATION)) { |
| 4695 | FwupdRelease *release = fu_device_get_release_default (device_history); |
Richard Hughes | 9a68084 | 2020-02-20 11:11:13 +0000 | [diff] [blame] | 4696 | if (fu_common_vercmp_full (fu_device_get_version (device), |
| 4697 | fwupd_release_get_version (release), |
| 4698 | fu_device_get_version_format (device)) != 0) { |
Mario Limonciello | 96a0dd5 | 2019-02-25 13:50:03 -0600 | [diff] [blame] | 4699 | g_debug ("inheriting needs-activation for %s as version %s != %s", |
| 4700 | fu_device_get_name (device), |
| 4701 | fu_device_get_version (device), |
| 4702 | fwupd_release_get_version (release)); |
| 4703 | fu_device_add_flag (device, FWUPD_DEVICE_FLAG_NEEDS_ACTIVATION); |
| 4704 | } |
| 4705 | } |
| 4706 | } |
| 4707 | |
Richard Hughes | 0a7e783 | 2017-11-22 11:01:13 +0000 | [diff] [blame] | 4708 | void |
| 4709 | fu_engine_add_device (FuEngine *self, FuDevice *device) |
| 4710 | { |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 4711 | GPtrArray *blacklisted_devices; |
Richard Hughes | 32684f2 | 2017-07-13 09:32:21 +0100 | [diff] [blame] | 4712 | GPtrArray *device_guids; |
Mario Limonciello | e038419 | 2020-04-16 14:36:49 -0500 | [diff] [blame] | 4713 | g_autoptr(XbNode) component = NULL; |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 4714 | |
| 4715 | /* device has no GUIDs set! */ |
Richard Hughes | 32684f2 | 2017-07-13 09:32:21 +0100 | [diff] [blame] | 4716 | device_guids = fu_device_get_guids (device); |
| 4717 | if (device_guids->len == 0) { |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 4718 | g_warning ("no GUIDs for device %s [%s]", |
Richard Hughes | 7e77bf3 | 2018-05-08 14:56:46 +0100 | [diff] [blame] | 4719 | fu_device_get_name (device), |
| 4720 | fu_device_get_id (device)); |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 4721 | return; |
| 4722 | } |
| 4723 | |
| 4724 | /* is this GUID blacklisted */ |
| 4725 | blacklisted_devices = fu_config_get_blacklist_devices (self->config); |
| 4726 | for (guint i = 0; i < blacklisted_devices->len; i++) { |
Richard Hughes | 32684f2 | 2017-07-13 09:32:21 +0100 | [diff] [blame] | 4727 | const gchar *blacklisted_guid = g_ptr_array_index (blacklisted_devices, i); |
| 4728 | for (guint j = 0; j < device_guids->len; j++) { |
| 4729 | const gchar *device_guid = g_ptr_array_index (device_guids, j); |
| 4730 | if (g_strcmp0 (blacklisted_guid, device_guid) == 0) { |
Richard Hughes | 7e77bf3 | 2018-05-08 14:56:46 +0100 | [diff] [blame] | 4731 | g_debug ("%s [%s] is blacklisted [%s], ignoring from %s", |
| 4732 | fu_device_get_name (device), |
| 4733 | fu_device_get_id (device), |
| 4734 | device_guid, |
Richard Hughes | 0a7e783 | 2017-11-22 11:01:13 +0000 | [diff] [blame] | 4735 | fu_device_get_plugin (device)); |
Richard Hughes | 32684f2 | 2017-07-13 09:32:21 +0100 | [diff] [blame] | 4736 | return; |
| 4737 | } |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 4738 | } |
| 4739 | } |
| 4740 | |
Richard Hughes | 7f76500 | 2019-12-20 09:41:29 +0000 | [diff] [blame] | 4741 | /* does the device not have an assigned protocol */ |
| 4742 | if (fu_device_has_flag (device, FWUPD_DEVICE_FLAG_UPDATABLE) && |
| 4743 | fu_device_get_protocol (device) == NULL) { |
Mario Limonciello | 33b40ed | 2020-01-08 15:11:34 -0600 | [diff] [blame] | 4744 | g_warning ("device %s [%s] does not define an update protocol", |
Richard Hughes | 7f76500 | 2019-12-20 09:41:29 +0000 | [diff] [blame] | 4745 | fu_device_get_id (device), |
| 4746 | fu_device_get_name (device)); |
| 4747 | } |
| 4748 | |
Richard Hughes | f307775 | 2018-06-27 12:45:06 +0100 | [diff] [blame] | 4749 | /* if this device is locked get some metadata from AppStream */ |
Mario Limonciello | e038419 | 2020-04-16 14:36:49 -0500 | [diff] [blame] | 4750 | component = fu_engine_get_component_by_guids (self, device); |
Richard Hughes | f307775 | 2018-06-27 12:45:06 +0100 | [diff] [blame] | 4751 | if (fu_device_has_flag (device, FWUPD_DEVICE_FLAG_LOCKED)) { |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 4752 | if (component != NULL) { |
| 4753 | g_autoptr(XbNode) release = NULL; |
| 4754 | release = xb_node_query_first (component, |
| 4755 | "releases/release", |
| 4756 | NULL); |
Richard Hughes | f307775 | 2018-06-27 12:45:06 +0100 | [diff] [blame] | 4757 | if (release != NULL) { |
| 4758 | g_autoptr(FwupdRelease) rel = fwupd_release_new (); |
Richard Hughes | 0b3e9fd | 2019-04-08 11:13:20 +0100 | [diff] [blame] | 4759 | g_autoptr(GError) error_local = NULL; |
| 4760 | if (!fu_engine_set_release_from_appstream (self, |
Richard Hughes | 2c40b37 | 2019-04-17 13:41:47 +0100 | [diff] [blame] | 4761 | device, |
Richard Hughes | 0b3e9fd | 2019-04-08 11:13:20 +0100 | [diff] [blame] | 4762 | rel, |
| 4763 | component, |
| 4764 | release, |
| 4765 | &error_local)) { |
| 4766 | g_warning ("failed to set AppStream release: %s", |
| 4767 | error_local->message); |
| 4768 | } else { |
| 4769 | fu_device_add_release (device, rel); |
| 4770 | } |
Richard Hughes | f307775 | 2018-06-27 12:45:06 +0100 | [diff] [blame] | 4771 | } |
| 4772 | } |
| 4773 | } |
| 4774 | |
Richard Hughes | 5e44729 | 2018-04-27 14:25:54 +0100 | [diff] [blame] | 4775 | /* adopt any required children, which may or may not already exist */ |
| 4776 | fu_engine_adopt_children (self, device); |
| 4777 | |
Richard Hughes | 35ca4cb | 2020-04-14 17:09:01 +0100 | [diff] [blame] | 4778 | /* set the proxy device if specified by GUID */ |
| 4779 | fu_engine_set_proxy_device (self, device); |
| 4780 | |
Richard Hughes | e48351e | 2018-06-22 12:32:39 +0100 | [diff] [blame] | 4781 | /* set any alternate objects on the device from the ID */ |
| 4782 | if (fu_device_get_alternate_id (device) != NULL) { |
Richard Hughes | 5a9a6bd | 2018-09-10 10:02:20 +0100 | [diff] [blame] | 4783 | g_autoptr(FuDevice) device_alt = NULL; |
Richard Hughes | e48351e | 2018-06-22 12:32:39 +0100 | [diff] [blame] | 4784 | device_alt = fu_device_list_get_by_id (self->device_list, |
| 4785 | fu_device_get_alternate_id (device), |
| 4786 | NULL); |
| 4787 | if (device_alt != NULL) |
| 4788 | fu_device_set_alternate (device, device_alt); |
| 4789 | } |
| 4790 | |
Richard Hughes | 5079f26 | 2019-04-29 09:34:27 +0100 | [diff] [blame] | 4791 | if (fu_device_get_version_format (device) == FWUPD_VERSION_FORMAT_UNKNOWN && |
| 4792 | fu_common_version_guess_format (fu_device_get_version (device)) == FWUPD_VERSION_FORMAT_NUMBER) { |
Mario Limonciello | 253b825 | 2019-04-25 10:48:17 -0400 | [diff] [blame] | 4793 | fu_device_remove_flag (device, FWUPD_DEVICE_FLAG_UPDATABLE); |
| 4794 | fu_device_set_update_error (device, "VersionFormat is ambiguous for this device"); |
| 4795 | } |
| 4796 | |
Richard Hughes | d8ea8da | 2020-02-19 15:04:49 +0000 | [diff] [blame] | 4797 | /* no vendor-id, and so no way to lock it down! */ |
| 4798 | if (fu_device_has_flag (device, FWUPD_DEVICE_FLAG_UPDATABLE) && |
| 4799 | fu_device_get_vendor_id (device) == NULL) { |
| 4800 | fu_device_remove_flag (device, FWUPD_DEVICE_FLAG_UPDATABLE); |
| 4801 | fu_device_set_update_error (device, "No vendor ID set"); |
| 4802 | } |
| 4803 | |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 4804 | /* notify all plugins about this new device */ |
| 4805 | if (!fu_device_has_flag (device, FWUPD_DEVICE_FLAG_REGISTERED)) |
| 4806 | fu_engine_plugin_device_register (self, device); |
| 4807 | |
Richard Hughes | 7f76500 | 2019-12-20 09:41:29 +0000 | [diff] [blame] | 4808 | /* does the device *still* not have a vendor ID? */ |
| 4809 | if (fu_device_has_flag (device, FWUPD_DEVICE_FLAG_UPDATABLE) && |
| 4810 | fu_device_get_vendor_id (device) == NULL) { |
| 4811 | g_warning ("device %s [%s] does not define a vendor-id!", |
| 4812 | fu_device_get_id (device), |
| 4813 | fu_device_get_name (device)); |
| 4814 | } |
| 4815 | |
Richard Hughes | d76ed3d | 2018-11-15 15:05:36 +0000 | [diff] [blame] | 4816 | /* create new device */ |
| 4817 | fu_device_list_add (self->device_list, device); |
| 4818 | |
Mario Limonciello | e038419 | 2020-04-16 14:36:49 -0500 | [diff] [blame] | 4819 | /* fixup the name and format as needed from cached metadata */ |
| 4820 | if (component != NULL) |
| 4821 | fu_engine_md_refresh_device_from_component (self, device, component); |
| 4822 | |
Richard Hughes | 1ee1800 | 2020-03-31 21:46:49 +0100 | [diff] [blame] | 4823 | /* match the metadata so clients can tell if the device is worthy */ |
| 4824 | fu_engine_ensure_device_supported (self, device); |
Mario Limonciello | 96a0dd5 | 2019-02-25 13:50:03 -0600 | [diff] [blame] | 4825 | |
| 4826 | /* sometimes inherit flags from recent history */ |
| 4827 | fu_engine_device_inherit_history (self, device); |
Mario Limonciello | d81ea2e | 2020-01-13 14:11:43 -0600 | [diff] [blame] | 4828 | |
| 4829 | fu_engine_emit_changed (self); |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 4830 | } |
| 4831 | |
| 4832 | static void |
Richard Hughes | 95c98a9 | 2019-10-22 16:03:15 +0100 | [diff] [blame] | 4833 | fu_engine_plugin_add_firmware_gtype_cb (FuPlugin *plugin, |
| 4834 | const gchar *id, |
| 4835 | GType gtype, |
| 4836 | gpointer user_data) |
| 4837 | { |
| 4838 | FuEngine *self = FU_ENGINE (user_data); |
| 4839 | fu_engine_add_firmware_gtype (self, id, gtype); |
| 4840 | } |
| 4841 | |
| 4842 | static void |
Richard Hughes | 75b965d | 2018-11-15 13:51:21 +0000 | [diff] [blame] | 4843 | fu_engine_plugin_rules_changed_cb (FuPlugin *plugin, gpointer user_data) |
| 4844 | { |
| 4845 | FuEngine *self = FU_ENGINE (user_data); |
| 4846 | GPtrArray *rules = fu_plugin_get_rules (plugin, FU_PLUGIN_RULE_INHIBITS_IDLE); |
| 4847 | for (guint j = 0; j < rules->len; j++) { |
| 4848 | const gchar *tmp = g_ptr_array_index (rules, j); |
| 4849 | fu_idle_inhibit (self->idle, tmp); |
| 4850 | } |
| 4851 | } |
| 4852 | |
| 4853 | static void |
Richard Hughes | 399859e | 2020-05-11 19:44:03 +0100 | [diff] [blame] | 4854 | fu_engine_plugin_security_changed_cb (FuPlugin *plugin, gpointer user_data) |
| 4855 | { |
| 4856 | FuEngine *self = FU_ENGINE (user_data); |
| 4857 | fu_engine_emit_changed (self); |
| 4858 | } |
| 4859 | |
| 4860 | static void |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 4861 | fu_engine_plugin_device_removed_cb (FuPlugin *plugin, |
| 4862 | FuDevice *device, |
| 4863 | gpointer user_data) |
| 4864 | { |
| 4865 | FuEngine *self = (FuEngine *) user_data; |
Richard Hughes | 3483410 | 2017-11-21 21:55:00 +0000 | [diff] [blame] | 4866 | FuPlugin *plugin_old; |
Richard Hughes | 5a9a6bd | 2018-09-10 10:02:20 +0100 | [diff] [blame] | 4867 | g_autoptr(FuDevice) device_tmp = NULL; |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 4868 | g_autoptr(GError) error = NULL; |
| 4869 | |
Richard Hughes | 4012754 | 2018-01-12 20:25:55 +0000 | [diff] [blame] | 4870 | device_tmp = fu_device_list_get_by_id (self->device_list, |
| 4871 | fu_device_get_id (device), |
| 4872 | &error); |
Richard Hughes | 0a7e783 | 2017-11-22 11:01:13 +0000 | [diff] [blame] | 4873 | if (device_tmp == NULL) { |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 4874 | g_debug ("%s", error->message); |
| 4875 | return; |
| 4876 | } |
| 4877 | |
Richard Hughes | 3483410 | 2017-11-21 21:55:00 +0000 | [diff] [blame] | 4878 | /* get the plugin */ |
Richard Hughes | e7e9545 | 2017-11-22 09:05:53 +0000 | [diff] [blame] | 4879 | plugin_old = fu_plugin_list_find_by_name (self->plugin_list, |
Richard Hughes | 0a7e783 | 2017-11-22 11:01:13 +0000 | [diff] [blame] | 4880 | fu_device_get_plugin (device), |
Richard Hughes | e7e9545 | 2017-11-22 09:05:53 +0000 | [diff] [blame] | 4881 | &error); |
Richard Hughes | 3483410 | 2017-11-21 21:55:00 +0000 | [diff] [blame] | 4882 | if (plugin_old == NULL) { |
| 4883 | g_debug ("%s", error->message); |
| 4884 | return; |
| 4885 | } |
| 4886 | |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 4887 | /* check this came from the same plugin */ |
| 4888 | if (g_strcmp0 (fu_plugin_get_name (plugin), |
Richard Hughes | 3483410 | 2017-11-21 21:55:00 +0000 | [diff] [blame] | 4889 | fu_plugin_get_name (plugin_old)) != 0) { |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 4890 | g_debug ("ignoring duplicate removal from %s", |
| 4891 | fu_plugin_get_name (plugin)); |
| 4892 | return; |
| 4893 | } |
| 4894 | |
| 4895 | /* make the UI update */ |
Richard Hughes | 0a7e783 | 2017-11-22 11:01:13 +0000 | [diff] [blame] | 4896 | fu_device_list_remove (self->device_list, device); |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 4897 | fu_engine_emit_changed (self); |
| 4898 | } |
| 4899 | |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 4900 | static gboolean |
| 4901 | fu_engine_recoldplug_delay_cb (gpointer user_data) |
| 4902 | { |
| 4903 | FuEngine *self = (FuEngine *) user_data; |
| 4904 | g_debug ("performing a recoldplug"); |
Richard Hughes | 2de8f13 | 2018-01-17 09:12:02 +0000 | [diff] [blame] | 4905 | fu_engine_plugins_coldplug (self, TRUE); |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 4906 | self->coldplug_id = 0; |
| 4907 | return FALSE; |
| 4908 | } |
| 4909 | |
Richard Hughes | 1665837 | 2019-11-22 09:23:59 +0000 | [diff] [blame] | 4910 | #ifdef HAVE_GUDEV |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 4911 | static void |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 4912 | fu_engine_udev_device_add (FuEngine *self, GUdevDevice *udev_device) |
| 4913 | { |
Richard Hughes | ff70441 | 2018-09-04 11:28:32 +0100 | [diff] [blame] | 4914 | g_autoptr(FuUdevDevice) device = fu_udev_device_new (udev_device); |
Richard Hughes | 6dec401 | 2018-08-27 19:13:00 +0100 | [diff] [blame] | 4915 | g_autoptr(GError) error_local = NULL; |
Richard Hughes | 51a869a | 2019-10-07 11:23:42 +0100 | [diff] [blame] | 4916 | g_autoptr(GPtrArray) possible_plugins = NULL; |
Richard Hughes | 6dec401 | 2018-08-27 19:13:00 +0100 | [diff] [blame] | 4917 | |
Richard Hughes | f3880bc | 2019-11-26 12:02:30 +0000 | [diff] [blame] | 4918 | /* debug */ |
| 4919 | if (g_getenv ("FWUPD_PROBE_VERBOSE") != NULL) { |
| 4920 | g_debug ("UDEV %s added", |
| 4921 | g_udev_device_get_sysfs_path (udev_device)); |
| 4922 | } |
| 4923 | |
Richard Hughes | 6dec401 | 2018-08-27 19:13:00 +0100 | [diff] [blame] | 4924 | /* add any extra quirks */ |
Richard Hughes | ff70441 | 2018-09-04 11:28:32 +0100 | [diff] [blame] | 4925 | fu_device_set_quirks (FU_DEVICE (device), self->quirks); |
| 4926 | if (!fu_device_probe (FU_DEVICE (device), &error_local)) { |
Richard Hughes | 6dec401 | 2018-08-27 19:13:00 +0100 | [diff] [blame] | 4927 | g_warning ("failed to probe device %s: %s", |
| 4928 | g_udev_device_get_sysfs_path (udev_device), |
| 4929 | error_local->message); |
| 4930 | return; |
| 4931 | } |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 4932 | |
Richard Hughes | 23170a8 | 2018-08-29 09:11:52 +0100 | [diff] [blame] | 4933 | /* can be specified using a quirk */ |
Richard Hughes | 51a869a | 2019-10-07 11:23:42 +0100 | [diff] [blame] | 4934 | possible_plugins = fu_device_get_possible_plugins (FU_DEVICE (device)); |
| 4935 | for (guint i = 0; i < possible_plugins->len; i++) { |
| 4936 | FuPlugin *plugin; |
| 4937 | const gchar *plugin_name = g_ptr_array_index (possible_plugins, i); |
| 4938 | g_autoptr(GError) error = NULL; |
Mario Limonciello | 0e50032 | 2019-10-17 18:41:04 -0500 | [diff] [blame] | 4939 | |
Richard Hughes | 51a869a | 2019-10-07 11:23:42 +0100 | [diff] [blame] | 4940 | plugin = fu_plugin_list_find_by_name (self->plugin_list, |
| 4941 | plugin_name, &error); |
| 4942 | if (plugin == NULL) { |
Richard Hughes | a1f9535 | 2020-02-21 08:14:54 +0000 | [diff] [blame] | 4943 | g_debug ("failed to find specified plugin %s: %s", |
| 4944 | plugin_name, error->message); |
Richard Hughes | 51a869a | 2019-10-07 11:23:42 +0100 | [diff] [blame] | 4945 | continue; |
| 4946 | } |
| 4947 | if (!fu_plugin_runner_udev_device_added (plugin, device, &error)) { |
| 4948 | if (g_error_matches (error, FWUPD_ERROR, FWUPD_ERROR_NOT_SUPPORTED)) { |
| 4949 | if (g_getenv ("FWUPD_PROBE_VERBOSE") != NULL) { |
| 4950 | g_debug ("%s ignoring: %s", |
| 4951 | fu_plugin_get_name (plugin), |
| 4952 | error->message); |
Mario Limonciello | 0e50032 | 2019-10-17 18:41:04 -0500 | [diff] [blame] | 4953 | } |
Mario Limonciello | 0e50032 | 2019-10-17 18:41:04 -0500 | [diff] [blame] | 4954 | continue; |
| 4955 | } |
Richard Hughes | 51a869a | 2019-10-07 11:23:42 +0100 | [diff] [blame] | 4956 | g_warning ("failed to add udev device %s: %s", |
| 4957 | g_udev_device_get_sysfs_path (udev_device), |
| 4958 | error->message); |
| 4959 | continue; |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 4960 | } |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 4961 | } |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 4962 | } |
| 4963 | |
| 4964 | static void |
| 4965 | fu_engine_udev_device_remove (FuEngine *self, GUdevDevice *udev_device) |
| 4966 | { |
| 4967 | g_autoptr(GPtrArray) devices = NULL; |
| 4968 | |
Richard Hughes | f3880bc | 2019-11-26 12:02:30 +0000 | [diff] [blame] | 4969 | /* debug */ |
| 4970 | if (g_getenv ("FWUPD_PROBE_VERBOSE") != NULL) { |
| 4971 | g_debug ("UDEV %s removed", |
| 4972 | g_udev_device_get_sysfs_path (udev_device)); |
| 4973 | } |
| 4974 | |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 4975 | /* go through each device and remove any that match */ |
Richard Hughes | c125ec0 | 2018-09-05 19:35:17 +0100 | [diff] [blame] | 4976 | devices = fu_device_list_get_all (self->device_list); |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 4977 | for (guint i = 0; i < devices->len; i++) { |
| 4978 | FuDevice *device = g_ptr_array_index (devices, i); |
Richard Hughes | c125ec0 | 2018-09-05 19:35:17 +0100 | [diff] [blame] | 4979 | if (!FU_IS_UDEV_DEVICE (device)) |
| 4980 | continue; |
| 4981 | if (g_strcmp0 (fu_udev_device_get_sysfs_path (FU_UDEV_DEVICE (device)), |
| 4982 | g_udev_device_get_sysfs_path (udev_device)) == 0) { |
| 4983 | g_debug ("auto-removing GUdevDevice"); |
| 4984 | fu_device_list_remove (self->device_list, device); |
| 4985 | } |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 4986 | } |
| 4987 | } |
| 4988 | |
Richard Hughes | 5e952ce | 2019-08-26 11:09:46 +0100 | [diff] [blame] | 4989 | typedef struct { |
| 4990 | FuEngine *self; |
| 4991 | GUdevDevice *udev_device; |
| 4992 | guint idle_id; |
| 4993 | } FuEngineUdevChangedHelper; |
| 4994 | |
| 4995 | static void |
| 4996 | fu_engine_udev_changed_helper_free (FuEngineUdevChangedHelper *helper) |
| 4997 | { |
| 4998 | if (helper->idle_id != 0) |
| 4999 | g_source_remove (helper->idle_id); |
| 5000 | g_object_unref (helper->self); |
| 5001 | g_object_unref (helper->udev_device); |
| 5002 | g_free (helper); |
| 5003 | } |
| 5004 | |
| 5005 | static FuEngineUdevChangedHelper * |
| 5006 | fu_engine_udev_changed_helper_new (FuEngine *self, GUdevDevice *udev_device) |
| 5007 | { |
| 5008 | FuEngineUdevChangedHelper *helper = g_new0 (FuEngineUdevChangedHelper, 1); |
| 5009 | helper->self = g_object_ref (self); |
| 5010 | helper->udev_device = g_object_ref (udev_device); |
| 5011 | return helper; |
| 5012 | } |
| 5013 | |
| 5014 | static gboolean |
| 5015 | fu_engine_udev_changed_cb (gpointer user_data) |
| 5016 | { |
| 5017 | FuEngineUdevChangedHelper *helper = (FuEngineUdevChangedHelper *) user_data; |
| 5018 | GPtrArray *plugins = fu_plugin_list_get_all (helper->self->plugin_list); |
| 5019 | g_autoptr(FuUdevDevice) device = fu_udev_device_new (helper->udev_device); |
| 5020 | |
| 5021 | /* run all plugins */ |
| 5022 | for (guint j = 0; j < plugins->len; j++) { |
| 5023 | FuPlugin *plugin_tmp = g_ptr_array_index (plugins, j); |
| 5024 | g_autoptr(GError) error = NULL; |
| 5025 | if (!fu_plugin_runner_udev_device_changed (plugin_tmp, device, &error)) { |
| 5026 | if (g_error_matches (error, FWUPD_ERROR, FWUPD_ERROR_NOT_SUPPORTED)) { |
| 5027 | g_debug ("%s ignoring: %s", |
| 5028 | fu_plugin_get_name (plugin_tmp), |
| 5029 | error->message); |
| 5030 | continue; |
| 5031 | } |
| 5032 | g_warning ("%s failed to change udev device %s: %s", |
| 5033 | fu_plugin_get_name (plugin_tmp), |
| 5034 | g_udev_device_get_sysfs_path (helper->udev_device), |
| 5035 | error->message); |
| 5036 | } |
| 5037 | } |
| 5038 | |
| 5039 | /* device done, so remove ref */ |
| 5040 | helper->idle_id = 0; |
| 5041 | g_hash_table_remove (helper->self->udev_changed_ids, |
| 5042 | g_udev_device_get_sysfs_path (helper->udev_device)); |
| 5043 | return FALSE; |
| 5044 | } |
| 5045 | |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 5046 | static void |
| 5047 | fu_engine_udev_device_changed (FuEngine *self, GUdevDevice *udev_device) |
| 5048 | { |
Richard Hughes | 5e952ce | 2019-08-26 11:09:46 +0100 | [diff] [blame] | 5049 | const gchar *sysfs_path = g_udev_device_get_sysfs_path (udev_device); |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 5050 | g_autoptr(GPtrArray) devices = NULL; |
Richard Hughes | 5e952ce | 2019-08-26 11:09:46 +0100 | [diff] [blame] | 5051 | FuEngineUdevChangedHelper *helper; |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 5052 | |
| 5053 | /* emit changed on any that match */ |
Richard Hughes | c125ec0 | 2018-09-05 19:35:17 +0100 | [diff] [blame] | 5054 | devices = fu_device_list_get_all (self->device_list); |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 5055 | for (guint i = 0; i < devices->len; i++) { |
| 5056 | FuDevice *device = g_ptr_array_index (devices, i); |
Richard Hughes | c125ec0 | 2018-09-05 19:35:17 +0100 | [diff] [blame] | 5057 | if (!FU_IS_UDEV_DEVICE (device)) |
| 5058 | continue; |
| 5059 | if (g_strcmp0 (fu_udev_device_get_sysfs_path (FU_UDEV_DEVICE (device)), |
Richard Hughes | 5e952ce | 2019-08-26 11:09:46 +0100 | [diff] [blame] | 5060 | sysfs_path) == 0) { |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 5061 | fu_udev_device_emit_changed (FU_UDEV_DEVICE (device)); |
Richard Hughes | c125ec0 | 2018-09-05 19:35:17 +0100 | [diff] [blame] | 5062 | } |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 5063 | } |
Richard Hughes | 5e952ce | 2019-08-26 11:09:46 +0100 | [diff] [blame] | 5064 | |
| 5065 | /* run all plugins, with per-device rate limiting */ |
| 5066 | if (g_hash_table_remove (self->udev_changed_ids, sysfs_path)) { |
| 5067 | g_debug ("re-adding rate-limited timeout for %s", sysfs_path); |
| 5068 | } else { |
| 5069 | g_debug ("adding rate-limited timeout for %s", sysfs_path); |
| 5070 | } |
| 5071 | helper = fu_engine_udev_changed_helper_new (self, udev_device); |
| 5072 | helper->idle_id = g_timeout_add (500, fu_engine_udev_changed_cb, helper); |
| 5073 | g_hash_table_insert (self->udev_changed_ids, g_strdup (sysfs_path), helper); |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 5074 | } |
| 5075 | |
| 5076 | static void |
| 5077 | fu_engine_enumerate_udev (FuEngine *self) |
| 5078 | { |
| 5079 | /* get all devices of class */ |
| 5080 | for (guint i = 0; i < self->udev_subsystems->len; i++) { |
| 5081 | const gchar *subsystem = g_ptr_array_index (self->udev_subsystems, i); |
| 5082 | GList *devices = g_udev_client_query_by_subsystem (self->gudev_client, |
| 5083 | subsystem); |
| 5084 | g_debug ("%u devices with subsystem %s", |
| 5085 | g_list_length (devices), subsystem); |
| 5086 | for (GList *l = devices; l != NULL; l = l->next) { |
| 5087 | GUdevDevice *udev_device = l->data; |
| 5088 | fu_engine_udev_device_add (self, udev_device); |
| 5089 | } |
| 5090 | g_list_foreach (devices, (GFunc) g_object_unref, NULL); |
| 5091 | g_list_free (devices); |
| 5092 | } |
| 5093 | } |
Richard Hughes | 1665837 | 2019-11-22 09:23:59 +0000 | [diff] [blame] | 5094 | #endif |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 5095 | |
| 5096 | static void |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 5097 | fu_engine_plugin_recoldplug_cb (FuPlugin *plugin, FuEngine *self) |
| 5098 | { |
| 5099 | if (self->coldplug_running) { |
| 5100 | g_warning ("coldplug already running, cannot recoldplug"); |
| 5101 | return; |
| 5102 | } |
Richard Hughes | 5b5f655 | 2018-05-18 10:22:39 +0100 | [diff] [blame] | 5103 | if (self->app_flags & FU_APP_FLAGS_NO_IDLE_SOURCES) { |
| 5104 | g_debug ("doing direct recoldplug"); |
| 5105 | fu_engine_plugins_coldplug (self, TRUE); |
Richard Hughes | 1665837 | 2019-11-22 09:23:59 +0000 | [diff] [blame] | 5106 | #ifdef HAVE_GUDEV |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 5107 | fu_engine_enumerate_udev (self); |
Richard Hughes | 1665837 | 2019-11-22 09:23:59 +0000 | [diff] [blame] | 5108 | #endif |
Richard Hughes | 5b5f655 | 2018-05-18 10:22:39 +0100 | [diff] [blame] | 5109 | return; |
| 5110 | } |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 5111 | g_debug ("scheduling a recoldplug"); |
| 5112 | if (self->coldplug_id != 0) |
| 5113 | g_source_remove (self->coldplug_id); |
| 5114 | self->coldplug_id = g_timeout_add (1500, fu_engine_recoldplug_delay_cb, self); |
| 5115 | } |
| 5116 | |
| 5117 | static void |
| 5118 | fu_engine_plugin_set_coldplug_delay_cb (FuPlugin *plugin, guint duration, FuEngine *self) |
| 5119 | { |
| 5120 | self->coldplug_delay = MAX (self->coldplug_delay, duration); |
| 5121 | g_debug ("got coldplug delay of %ums, global maximum is now %ums", |
| 5122 | duration, self->coldplug_delay); |
| 5123 | } |
| 5124 | |
Richard Hughes | f425d29 | 2019-01-18 17:57:39 +0000 | [diff] [blame] | 5125 | /* this is called by the self tests as well */ |
Richard Hughes | 3483410 | 2017-11-21 21:55:00 +0000 | [diff] [blame] | 5126 | void |
| 5127 | fu_engine_add_plugin (FuEngine *self, FuPlugin *plugin) |
| 5128 | { |
Mario Limonciello | 52e75ba | 2019-11-22 13:21:19 -0600 | [diff] [blame] | 5129 | if (fu_plugin_is_open (plugin)) { |
| 5130 | /* plugin does not match built version */ |
| 5131 | if (fu_plugin_get_build_hash (plugin) == NULL) { |
| 5132 | const gchar *name = fu_plugin_get_name (plugin); |
| 5133 | g_warning ("%s should call fu_plugin_set_build_hash()", |
| 5134 | name); |
| 5135 | self->tainted = TRUE; |
| 5136 | } else if (g_strcmp0 (fu_plugin_get_build_hash (plugin), |
| 5137 | FU_BUILD_HASH) != 0) { |
| 5138 | const gchar *name = fu_plugin_get_name (plugin); |
| 5139 | g_warning ("%s has incorrect built version %s", |
| 5140 | name, fu_plugin_get_build_hash (plugin)); |
| 5141 | self->tainted = TRUE; |
| 5142 | } |
Richard Hughes | f425d29 | 2019-01-18 17:57:39 +0000 | [diff] [blame] | 5143 | } |
| 5144 | |
Richard Hughes | e7e9545 | 2017-11-22 09:05:53 +0000 | [diff] [blame] | 5145 | fu_plugin_list_add (self->plugin_list, plugin); |
Richard Hughes | 3483410 | 2017-11-21 21:55:00 +0000 | [diff] [blame] | 5146 | } |
| 5147 | |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 5148 | static gboolean |
Richard Hughes | 1e456bc | 2018-05-10 20:16:16 +0100 | [diff] [blame] | 5149 | fu_engine_is_plugin_name_blacklisted (FuEngine *self, const gchar *name) |
| 5150 | { |
| 5151 | GPtrArray *blacklist = fu_config_get_blacklist_plugins (self->config); |
| 5152 | for (guint i = 0; i < blacklist->len; i++) { |
| 5153 | const gchar *name_tmp = g_ptr_array_index (blacklist, i); |
| 5154 | if (g_strcmp0 (name_tmp, name) == 0) |
| 5155 | return TRUE; |
| 5156 | } |
| 5157 | return FALSE; |
| 5158 | } |
| 5159 | |
Richard Hughes | c02ee4d | 2018-05-22 15:46:03 +0100 | [diff] [blame] | 5160 | static gboolean |
| 5161 | fu_engine_is_plugin_name_whitelisted (FuEngine *self, const gchar *name) |
| 5162 | { |
| 5163 | if (self->plugin_filter->len == 0) |
| 5164 | return TRUE; |
| 5165 | for (guint i = 0; i < self->plugin_filter->len; i++) { |
| 5166 | const gchar *name_tmp = g_ptr_array_index (self->plugin_filter, i); |
Richard Hughes | 5c508de | 2019-11-22 09:57:34 +0000 | [diff] [blame] | 5167 | if (fu_common_fnmatch (name_tmp, name)) |
Richard Hughes | c02ee4d | 2018-05-22 15:46:03 +0100 | [diff] [blame] | 5168 | return TRUE; |
| 5169 | } |
| 5170 | return FALSE; |
| 5171 | } |
| 5172 | |
| 5173 | void |
| 5174 | fu_engine_add_plugin_filter (FuEngine *self, const gchar *plugin_glob) |
| 5175 | { |
Mario Limonciello | 1a52051 | 2020-05-26 10:44:53 -0500 | [diff] [blame] | 5176 | GString *str; |
Richard Hughes | c02ee4d | 2018-05-22 15:46:03 +0100 | [diff] [blame] | 5177 | g_return_if_fail (FU_IS_ENGINE (self)); |
| 5178 | g_return_if_fail (plugin_glob != NULL); |
Mario Limonciello | 1a52051 | 2020-05-26 10:44:53 -0500 | [diff] [blame] | 5179 | str = g_string_new (plugin_glob); |
| 5180 | fu_common_string_replace (str, "-", "_"); |
| 5181 | g_ptr_array_add (self->plugin_filter, g_string_free (str, FALSE)); |
Richard Hughes | c02ee4d | 2018-05-22 15:46:03 +0100 | [diff] [blame] | 5182 | } |
| 5183 | |
Richard Hughes | aabdc37 | 2018-11-14 10:11:08 +0000 | [diff] [blame] | 5184 | static gboolean |
| 5185 | fu_engine_plugin_check_supported_cb (FuPlugin *plugin, const gchar *guid, FuEngine *self) |
| 5186 | { |
| 5187 | g_autoptr(XbNode) n = NULL; |
| 5188 | g_autofree gchar *xpath = NULL; |
Mario Limonciello | 4fa95a7 | 2020-03-28 10:50:57 -0500 | [diff] [blame] | 5189 | |
| 5190 | if (fu_config_get_enumerate_all_devices (self->config)) |
| 5191 | return TRUE; |
| 5192 | |
Richard Hughes | aabdc37 | 2018-11-14 10:11:08 +0000 | [diff] [blame] | 5193 | xpath = g_strdup_printf ("components/component/" |
| 5194 | "provides/firmware[@type='flashed'][text()='%s']", |
| 5195 | guid); |
| 5196 | n = xb_silo_query_first (self->silo, xpath, NULL); |
| 5197 | return n != NULL; |
| 5198 | } |
| 5199 | |
Richard Hughes | 8c71a3f | 2018-05-22 19:19:52 +0100 | [diff] [blame] | 5200 | gboolean |
Richard Hughes | f425d29 | 2019-01-18 17:57:39 +0000 | [diff] [blame] | 5201 | fu_engine_get_tainted (FuEngine *self) |
| 5202 | { |
| 5203 | return self->tainted; |
| 5204 | } |
| 5205 | |
Mario Limonciello | 20cc9ee | 2019-09-05 07:27:26 -0500 | [diff] [blame] | 5206 | const gchar * |
| 5207 | fu_engine_get_host_product (FuEngine *self) |
| 5208 | { |
Mario Limonciello | 8ad4ac0 | 2020-01-15 09:58:53 -0600 | [diff] [blame] | 5209 | const gchar *result = NULL; |
Mario Limonciello | 20cc9ee | 2019-09-05 07:27:26 -0500 | [diff] [blame] | 5210 | g_return_val_if_fail (FU_IS_ENGINE (self), NULL); |
Mario Limonciello | 8ad4ac0 | 2020-01-15 09:58:53 -0600 | [diff] [blame] | 5211 | result = fu_hwids_get_value (self->hwids, FU_HWIDS_KEY_PRODUCT_NAME); |
| 5212 | return result != NULL ? result : "Unknown Product"; |
Mario Limonciello | 20cc9ee | 2019-09-05 07:27:26 -0500 | [diff] [blame] | 5213 | } |
| 5214 | |
Richard Hughes | 0917fb6 | 2019-09-21 12:55:37 +0100 | [diff] [blame] | 5215 | const gchar * |
| 5216 | fu_engine_get_host_machine_id (FuEngine *self) |
| 5217 | { |
| 5218 | g_return_val_if_fail (FU_IS_ENGINE (self), NULL); |
| 5219 | return self->host_machine_id; |
| 5220 | } |
| 5221 | |
Richard Hughes | ad45158 | 2020-05-11 22:14:47 +0100 | [diff] [blame] | 5222 | static void |
Richard Hughes | f58ac73 | 2020-05-12 15:23:44 +0100 | [diff] [blame] | 5223 | fu_engine_add_security_attrs_tainted (FuEngine *self, FuSecurityAttrs *attrs) |
Richard Hughes | ad45158 | 2020-05-11 22:14:47 +0100 | [diff] [blame] | 5224 | { |
Mario Limonciello | a834284 | 2020-05-13 09:47:16 -0500 | [diff] [blame] | 5225 | gboolean disabled_plugins = FALSE; |
| 5226 | GPtrArray *blacklist = fu_config_get_blacklist_plugins (self->config); |
Richard Hughes | b246bca | 2020-05-18 14:31:35 +0100 | [diff] [blame] | 5227 | g_autoptr(FwupdSecurityAttr) attr = fwupd_security_attr_new (FWUPD_SECURITY_ATTR_ID_FWUPD_PLUGINS); |
Richard Hughes | cae111d | 2020-05-15 15:20:24 +0100 | [diff] [blame] | 5228 | fwupd_security_attr_set_plugin (attr, "core"); |
Richard Hughes | ad45158 | 2020-05-11 22:14:47 +0100 | [diff] [blame] | 5229 | fwupd_security_attr_add_flag (attr, FWUPD_SECURITY_ATTR_FLAG_RUNTIME_ISSUE); |
Richard Hughes | b246bca | 2020-05-18 14:31:35 +0100 | [diff] [blame] | 5230 | fu_security_attrs_append (attrs, attr); |
Mario Limonciello | a834284 | 2020-05-13 09:47:16 -0500 | [diff] [blame] | 5231 | for (guint i = 0; i < blacklist->len; i++) { |
| 5232 | const gchar *name_tmp = g_ptr_array_index (blacklist, i); |
| 5233 | if (g_strcmp0 (name_tmp, "test") != 0 && |
| 5234 | g_strcmp0 (name_tmp, "invalid") != 0) { |
| 5235 | disabled_plugins = TRUE; |
| 5236 | break; |
| 5237 | } |
| 5238 | } |
Richard Hughes | ad45158 | 2020-05-11 22:14:47 +0100 | [diff] [blame] | 5239 | if (self->tainted) { |
Richard Hughes | b246bca | 2020-05-18 14:31:35 +0100 | [diff] [blame] | 5240 | fwupd_security_attr_set_result (attr, FWUPD_SECURITY_ATTR_RESULT_TAINTED); |
| 5241 | return; |
Richard Hughes | ad45158 | 2020-05-11 22:14:47 +0100 | [diff] [blame] | 5242 | } |
Richard Hughes | b246bca | 2020-05-18 14:31:35 +0100 | [diff] [blame] | 5243 | if (self->plugin_filter->len > 0 || disabled_plugins) { |
| 5244 | fwupd_security_attr_set_result (attr, FWUPD_SECURITY_ATTR_RESULT_NOT_ENABLED); |
| 5245 | return; |
| 5246 | } |
| 5247 | |
| 5248 | /* success */ |
| 5249 | fwupd_security_attr_add_flag (attr, FWUPD_SECURITY_ATTR_FLAG_SUCCESS); |
| 5250 | fwupd_security_attr_set_result (attr, FWUPD_SECURITY_ATTR_RESULT_NOT_TAINTED); |
Richard Hughes | ad45158 | 2020-05-11 22:14:47 +0100 | [diff] [blame] | 5251 | } |
| 5252 | |
Richard Hughes | 31c1a45 | 2020-05-11 22:16:10 +0100 | [diff] [blame] | 5253 | static void |
Richard Hughes | f58ac73 | 2020-05-12 15:23:44 +0100 | [diff] [blame] | 5254 | fu_engine_add_security_attrs_supported (FuEngine *self, FuSecurityAttrs *attrs) |
Richard Hughes | 31c1a45 | 2020-05-11 22:16:10 +0100 | [diff] [blame] | 5255 | { |
| 5256 | FwupdRelease *rel_current = NULL; |
| 5257 | FwupdRelease *rel_newest = NULL; |
Mario Limonciello | ff303e1 | 2020-05-13 10:25:41 -0500 | [diff] [blame] | 5258 | g_autoptr(FwupdSecurityAttr) attr_a = NULL; |
| 5259 | g_autoptr(FwupdSecurityAttr) attr_u = NULL; |
Richard Hughes | 31c1a45 | 2020-05-11 22:16:10 +0100 | [diff] [blame] | 5260 | guint64 now = (guint64) g_get_real_time () / G_USEC_PER_SEC; |
| 5261 | g_autoptr(FuDevice) device = NULL; |
| 5262 | g_autoptr(GPtrArray) releases = NULL; |
| 5263 | |
Richard Hughes | b246bca | 2020-05-18 14:31:35 +0100 | [diff] [blame] | 5264 | attr_u = fwupd_security_attr_new (FWUPD_SECURITY_ATTR_ID_FWUPD_UPDATES); |
Richard Hughes | cae111d | 2020-05-15 15:20:24 +0100 | [diff] [blame] | 5265 | fwupd_security_attr_set_plugin (attr_u, "core"); |
Richard Hughes | 31c1a45 | 2020-05-11 22:16:10 +0100 | [diff] [blame] | 5266 | fwupd_security_attr_add_flag (attr_u, FWUPD_SECURITY_ATTR_FLAG_RUNTIME_UPDATES); |
Richard Hughes | f58ac73 | 2020-05-12 15:23:44 +0100 | [diff] [blame] | 5267 | fu_security_attrs_append (attrs, attr_u); |
Mario Limonciello | b0d2e9e | 2020-05-18 12:30:47 -0500 | [diff] [blame] | 5268 | attr_a = fwupd_security_attr_new (FWUPD_SECURITY_ATTR_ID_FWUPD_ATTESTATION); |
| 5269 | fwupd_security_attr_set_plugin (attr_a, "core"); |
| 5270 | fwupd_security_attr_add_flag (attr_a, FWUPD_SECURITY_ATTR_FLAG_RUNTIME_ATTESTATION); |
| 5271 | fu_security_attrs_append (attrs, attr_a); |
Richard Hughes | 31c1a45 | 2020-05-11 22:16:10 +0100 | [diff] [blame] | 5272 | /* get device */ |
| 5273 | device = fu_device_list_get_by_guid (self->device_list, |
| 5274 | /* main-system-firmware */ |
| 5275 | "230c8b18-8d9b-53ec-838b-6cfc0383493a", |
| 5276 | NULL); |
Mario Limonciello | b0d2e9e | 2020-05-18 12:30:47 -0500 | [diff] [blame] | 5277 | |
| 5278 | /* find out if there is firmware less than 12 months old */ |
Richard Hughes | 31c1a45 | 2020-05-11 22:16:10 +0100 | [diff] [blame] | 5279 | if (device == NULL) { |
Richard Hughes | b246bca | 2020-05-18 14:31:35 +0100 | [diff] [blame] | 5280 | fwupd_security_attr_set_result (attr_u, FWUPD_SECURITY_ATTR_RESULT_NOT_FOUND); |
Richard Hughes | 31c1a45 | 2020-05-11 22:16:10 +0100 | [diff] [blame] | 5281 | } else { |
| 5282 | releases = fu_engine_get_releases_for_device (self, device, NULL); |
| 5283 | if (releases == NULL) { |
Richard Hughes | b246bca | 2020-05-18 14:31:35 +0100 | [diff] [blame] | 5284 | fwupd_security_attr_set_result (attr_u, FWUPD_SECURITY_ATTR_RESULT_NOT_SUPPORTED); |
Richard Hughes | 31c1a45 | 2020-05-11 22:16:10 +0100 | [diff] [blame] | 5285 | } else { |
| 5286 | /* check the age */ |
Richard Hughes | 31c1a45 | 2020-05-11 22:16:10 +0100 | [diff] [blame] | 5287 | for (guint i = 0; i < releases->len; i++) { |
| 5288 | FwupdRelease *rel_tmp = g_ptr_array_index (releases, i); |
| 5289 | if (rel_newest == NULL || |
| 5290 | fwupd_release_get_created (rel_tmp) > fwupd_release_get_created (rel_newest)) |
| 5291 | rel_newest = rel_tmp; |
| 5292 | } |
Richard Hughes | b246bca | 2020-05-18 14:31:35 +0100 | [diff] [blame] | 5293 | g_debug ("newest release is %" G_GUINT64_FORMAT " months old", |
| 5294 | (now - fwupd_release_get_created (rel_newest)) / (60 * 60 * 24 * 30)); |
| 5295 | fwupd_security_attr_set_result (attr_u, FWUPD_SECURITY_ATTR_RESULT_SUPPORTED); |
| 5296 | if (now - fwupd_release_get_created (rel_newest) < 60 * 60 * 24 * 30 * 12) { |
Richard Hughes | 31c1a45 | 2020-05-11 22:16:10 +0100 | [diff] [blame] | 5297 | fwupd_security_attr_add_flag (attr_u, FWUPD_SECURITY_ATTR_FLAG_SUCCESS); |
Richard Hughes | b246bca | 2020-05-18 14:31:35 +0100 | [diff] [blame] | 5298 | fwupd_security_attr_set_result (attr_a, FWUPD_SECURITY_ATTR_RESULT_SUPPORTED); |
| 5299 | } |
Richard Hughes | 31c1a45 | 2020-05-11 22:16:10 +0100 | [diff] [blame] | 5300 | } |
| 5301 | } |
| 5302 | |
| 5303 | /* do we have attestation checksums */ |
Richard Hughes | 31c1a45 | 2020-05-11 22:16:10 +0100 | [diff] [blame] | 5304 | if (releases != NULL) { |
| 5305 | for (guint i = 0; i < releases->len; i++) { |
| 5306 | FwupdRelease *rel_tmp = g_ptr_array_index (releases, i); |
| 5307 | if (fu_common_vercmp_full (fu_device_get_version (device), |
| 5308 | fwupd_release_get_version (rel_tmp), |
| 5309 | fu_device_get_version_format (device)) == 0) { |
| 5310 | rel_current = rel_tmp; |
| 5311 | break; |
| 5312 | } |
| 5313 | } |
| 5314 | } |
| 5315 | if (rel_current == NULL) { |
Richard Hughes | b246bca | 2020-05-18 14:31:35 +0100 | [diff] [blame] | 5316 | fwupd_security_attr_set_result (attr_a, FWUPD_SECURITY_ATTR_RESULT_NOT_SUPPORTED); |
Mario Limonciello | 5d8c630 | 2020-05-18 12:44:15 -0500 | [diff] [blame] | 5317 | } else { |
| 5318 | g_autoptr(GError) error_local = NULL; |
| 5319 | if (!fu_engine_verify (self, fu_device_get_id (device), &error_local)) { |
| 5320 | fwupd_security_attr_set_result (attr_a, FWUPD_SECURITY_ATTR_RESULT_NOT_SUPPORTED); |
| 5321 | g_debug ("Failed to find attestation checksums: %s", error_local->message); |
| 5322 | } else { |
| 5323 | fwupd_security_attr_add_flag (attr_a, FWUPD_SECURITY_ATTR_FLAG_SUCCESS); |
| 5324 | fwupd_security_attr_set_result (attr_a, FWUPD_SECURITY_ATTR_RESULT_SUPPORTED); |
| 5325 | } |
Richard Hughes | 31c1a45 | 2020-05-11 22:16:10 +0100 | [diff] [blame] | 5326 | } |
| 5327 | } |
| 5328 | |
Richard Hughes | f58ac73 | 2020-05-12 15:23:44 +0100 | [diff] [blame] | 5329 | FuSecurityAttrs * |
Richard Hughes | 56e7ae5 | 2020-05-17 21:00:23 +0100 | [diff] [blame] | 5330 | fu_engine_get_host_security_attrs (FuEngine *self) |
Richard Hughes | 196c6c6 | 2020-05-11 19:42:47 +0100 | [diff] [blame] | 5331 | { |
| 5332 | GPtrArray *plugins = fu_plugin_list_get_all (self->plugin_list); |
Richard Hughes | f58ac73 | 2020-05-12 15:23:44 +0100 | [diff] [blame] | 5333 | g_autoptr(FuSecurityAttrs) attrs = fu_security_attrs_new (); |
Richard Hughes | b246bca | 2020-05-18 14:31:35 +0100 | [diff] [blame] | 5334 | g_autoptr(GPtrArray) items = NULL; |
Richard Hughes | 196c6c6 | 2020-05-11 19:42:47 +0100 | [diff] [blame] | 5335 | |
Richard Hughes | ad45158 | 2020-05-11 22:14:47 +0100 | [diff] [blame] | 5336 | /* built in */ |
Richard Hughes | ad45158 | 2020-05-11 22:14:47 +0100 | [diff] [blame] | 5337 | fu_engine_add_security_attrs_tainted (self, attrs); |
Richard Hughes | 31c1a45 | 2020-05-11 22:16:10 +0100 | [diff] [blame] | 5338 | fu_engine_add_security_attrs_supported (self, attrs); |
Richard Hughes | ad45158 | 2020-05-11 22:14:47 +0100 | [diff] [blame] | 5339 | |
| 5340 | /* call into plugins */ |
Richard Hughes | 196c6c6 | 2020-05-11 19:42:47 +0100 | [diff] [blame] | 5341 | for (guint j = 0; j < plugins->len; j++) { |
| 5342 | FuPlugin *plugin_tmp = g_ptr_array_index (plugins, j); |
Richard Hughes | f58ac73 | 2020-05-12 15:23:44 +0100 | [diff] [blame] | 5343 | fu_plugin_runner_add_security_attrs (plugin_tmp, attrs); |
Richard Hughes | 196c6c6 | 2020-05-11 19:42:47 +0100 | [diff] [blame] | 5344 | } |
| 5345 | |
Richard Hughes | b246bca | 2020-05-18 14:31:35 +0100 | [diff] [blame] | 5346 | /* set the fallback names for clients without native translations */ |
| 5347 | items = fu_security_attrs_get_all (attrs); |
| 5348 | for (guint i = 0; i < items->len; i++) { |
| 5349 | FwupdSecurityAttr *attr = g_ptr_array_index (items, i); |
| 5350 | if (fwupd_security_attr_get_name (attr) == NULL) { |
| 5351 | const gchar *name_tmp = fu_security_attr_get_name (attr); |
| 5352 | if (name_tmp == NULL) { |
| 5353 | g_warning ("failed to get fallback for %s", |
| 5354 | fwupd_security_attr_get_appstream_id (attr)); |
| 5355 | continue; |
| 5356 | } |
| 5357 | fwupd_security_attr_set_name (attr, name_tmp); |
| 5358 | } |
| 5359 | } |
| 5360 | |
Richard Hughes | 196c6c6 | 2020-05-11 19:42:47 +0100 | [diff] [blame] | 5361 | /* set the obsoletes flag for each attr */ |
| 5362 | fu_security_attrs_depsolve (attrs); |
Richard Hughes | b246bca | 2020-05-18 14:31:35 +0100 | [diff] [blame] | 5363 | |
Richard Hughes | 196c6c6 | 2020-05-11 19:42:47 +0100 | [diff] [blame] | 5364 | return g_steal_pointer (&attrs); |
| 5365 | } |
| 5366 | |
| 5367 | const gchar * |
| 5368 | fu_engine_get_host_security_id (FuEngine *self) |
| 5369 | { |
| 5370 | g_return_val_if_fail (FU_IS_ENGINE (self), NULL); |
| 5371 | |
| 5372 | /* rebuild */ |
| 5373 | if (!self->host_security_id_valid) { |
Richard Hughes | f58ac73 | 2020-05-12 15:23:44 +0100 | [diff] [blame] | 5374 | g_autoptr(FuSecurityAttrs) attrs = NULL; |
Richard Hughes | 196c6c6 | 2020-05-11 19:42:47 +0100 | [diff] [blame] | 5375 | g_free (self->host_security_id); |
Richard Hughes | f58ac73 | 2020-05-12 15:23:44 +0100 | [diff] [blame] | 5376 | self->host_security_id = NULL; |
Richard Hughes | 196c6c6 | 2020-05-11 19:42:47 +0100 | [diff] [blame] | 5377 | self->host_security_id_valid = TRUE; |
Richard Hughes | 56e7ae5 | 2020-05-17 21:00:23 +0100 | [diff] [blame] | 5378 | attrs = fu_engine_get_host_security_attrs (self); |
Mario Limonciello | b0e1e5e | 2020-05-18 13:50:29 -0500 | [diff] [blame] | 5379 | self->host_security_id = fu_security_attrs_calculate_hsi (attrs, |
| 5380 | FU_SECURITY_ATTRS_FLAG_ADD_VERSION); |
Richard Hughes | 196c6c6 | 2020-05-11 19:42:47 +0100 | [diff] [blame] | 5381 | } |
| 5382 | |
| 5383 | return self->host_security_id; |
| 5384 | } |
| 5385 | |
Richard Hughes | f425d29 | 2019-01-18 17:57:39 +0000 | [diff] [blame] | 5386 | gboolean |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 5387 | fu_engine_load_plugins (FuEngine *self, GError **error) |
| 5388 | { |
| 5389 | const gchar *fn; |
| 5390 | g_autoptr(GDir) dir = NULL; |
Richard Hughes | 4be17d1 | 2018-05-30 20:36:29 +0100 | [diff] [blame] | 5391 | g_autofree gchar *plugin_path = NULL; |
Richard Hughes | 00d6f47 | 2019-11-22 17:04:02 +0000 | [diff] [blame] | 5392 | g_autofree gchar *suffix = g_strdup_printf (".%s", G_MODULE_SUFFIX); |
Richard Hughes | f77d706 | 2017-11-27 12:06:36 +0000 | [diff] [blame] | 5393 | |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 5394 | /* search */ |
Richard Hughes | 4be17d1 | 2018-05-30 20:36:29 +0100 | [diff] [blame] | 5395 | plugin_path = fu_common_get_path (FU_PATH_KIND_PLUGINDIR_PKG); |
| 5396 | dir = g_dir_open (plugin_path, 0, error); |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 5397 | if (dir == NULL) |
| 5398 | return FALSE; |
| 5399 | while ((fn = g_dir_read_name (dir)) != NULL) { |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 5400 | g_autofree gchar *filename = NULL; |
Richard Hughes | 1e456bc | 2018-05-10 20:16:16 +0100 | [diff] [blame] | 5401 | g_autofree gchar *name = NULL; |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 5402 | g_autoptr(FuPlugin) plugin = NULL; |
| 5403 | g_autoptr(GError) error_local = NULL; |
| 5404 | |
| 5405 | /* ignore non-plugins */ |
Richard Hughes | 00d6f47 | 2019-11-22 17:04:02 +0000 | [diff] [blame] | 5406 | if (!g_str_has_suffix (fn, suffix)) |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 5407 | continue; |
| 5408 | |
Richard Hughes | 1e456bc | 2018-05-10 20:16:16 +0100 | [diff] [blame] | 5409 | /* is blacklisted */ |
| 5410 | name = fu_plugin_guess_name_from_fn (fn); |
| 5411 | if (name == NULL) |
| 5412 | continue; |
| 5413 | if (fu_engine_is_plugin_name_blacklisted (self, name)) { |
Richard Hughes | c02ee4d | 2018-05-22 15:46:03 +0100 | [diff] [blame] | 5414 | g_debug ("plugin %s is blacklisted", name); |
| 5415 | continue; |
| 5416 | } |
| 5417 | if (!fu_engine_is_plugin_name_whitelisted (self, name)) { |
| 5418 | g_debug ("plugin %s is not whitelisted", name); |
Richard Hughes | 1e456bc | 2018-05-10 20:16:16 +0100 | [diff] [blame] | 5419 | continue; |
| 5420 | } |
| 5421 | |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 5422 | /* open module */ |
Richard Hughes | 4be17d1 | 2018-05-30 20:36:29 +0100 | [diff] [blame] | 5423 | filename = g_build_filename (plugin_path, fn, NULL); |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 5424 | plugin = fu_plugin_new (); |
Richard Hughes | 1e456bc | 2018-05-10 20:16:16 +0100 | [diff] [blame] | 5425 | fu_plugin_set_name (plugin, name); |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 5426 | fu_plugin_set_usb_context (plugin, self->usb_ctx); |
| 5427 | fu_plugin_set_hwids (plugin, self->hwids); |
Richard Hughes | 49e5e05 | 2017-09-03 12:15:41 +0100 | [diff] [blame] | 5428 | fu_plugin_set_smbios (plugin, self->smbios); |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 5429 | fu_plugin_set_udev_subsystems (plugin, self->udev_subsystems); |
Richard Hughes | 9c028f0 | 2017-10-28 21:14:28 +0100 | [diff] [blame] | 5430 | fu_plugin_set_quirks (plugin, self->quirks); |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 5431 | fu_plugin_set_runtime_versions (plugin, self->runtime_versions); |
Richard Hughes | 34e0dab | 2018-04-20 16:43:00 +0100 | [diff] [blame] | 5432 | fu_plugin_set_compile_versions (plugin, self->compile_versions); |
Richard Hughes | 95c98a9 | 2019-10-22 16:03:15 +0100 | [diff] [blame] | 5433 | g_signal_connect (plugin, "add-firmware-gtype", |
| 5434 | G_CALLBACK (fu_engine_plugin_add_firmware_gtype_cb), |
| 5435 | self); |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 5436 | g_debug ("adding plugin %s", filename); |
Richard Hughes | 8c71a3f | 2018-05-22 19:19:52 +0100 | [diff] [blame] | 5437 | |
| 5438 | /* if loaded from fu_engine_load() open the plugin */ |
| 5439 | if (self->usb_ctx != NULL) { |
| 5440 | if (!fu_plugin_open (plugin, filename, &error_local)) { |
Mario Limonciello | f560553 | 2019-11-04 07:49:50 -0600 | [diff] [blame] | 5441 | g_warning ("%s", error_local->message); |
Richard Hughes | 8c71a3f | 2018-05-22 19:19:52 +0100 | [diff] [blame] | 5442 | continue; |
| 5443 | } |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 5444 | } |
| 5445 | |
Richard Hughes | 1e456bc | 2018-05-10 20:16:16 +0100 | [diff] [blame] | 5446 | /* self disabled */ |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 5447 | if (!fu_plugin_get_enabled (plugin)) { |
Richard Hughes | 1e456bc | 2018-05-10 20:16:16 +0100 | [diff] [blame] | 5448 | g_debug ("%s self disabled", |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 5449 | fu_plugin_get_name (plugin)); |
| 5450 | continue; |
| 5451 | } |
| 5452 | |
| 5453 | /* watch for changes */ |
| 5454 | g_signal_connect (plugin, "device-added", |
| 5455 | G_CALLBACK (fu_engine_plugin_device_added_cb), |
| 5456 | self); |
| 5457 | g_signal_connect (plugin, "device-removed", |
| 5458 | G_CALLBACK (fu_engine_plugin_device_removed_cb), |
| 5459 | self); |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 5460 | g_signal_connect (plugin, "device-register", |
| 5461 | G_CALLBACK (fu_engine_plugin_device_register_cb), |
| 5462 | self); |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 5463 | g_signal_connect (plugin, "recoldplug", |
| 5464 | G_CALLBACK (fu_engine_plugin_recoldplug_cb), |
| 5465 | self); |
| 5466 | g_signal_connect (plugin, "set-coldplug-delay", |
| 5467 | G_CALLBACK (fu_engine_plugin_set_coldplug_delay_cb), |
| 5468 | self); |
Richard Hughes | aabdc37 | 2018-11-14 10:11:08 +0000 | [diff] [blame] | 5469 | g_signal_connect (plugin, "check-supported", |
| 5470 | G_CALLBACK (fu_engine_plugin_check_supported_cb), |
| 5471 | self); |
Richard Hughes | 75b965d | 2018-11-15 13:51:21 +0000 | [diff] [blame] | 5472 | g_signal_connect (plugin, "rules-changed", |
| 5473 | G_CALLBACK (fu_engine_plugin_rules_changed_cb), |
| 5474 | self); |
Richard Hughes | 399859e | 2020-05-11 19:44:03 +0100 | [diff] [blame] | 5475 | g_signal_connect (plugin, "security-changed", |
| 5476 | G_CALLBACK (fu_engine_plugin_security_changed_cb), |
| 5477 | self); |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 5478 | |
| 5479 | /* add */ |
Richard Hughes | f425d29 | 2019-01-18 17:57:39 +0000 | [diff] [blame] | 5480 | fu_engine_add_plugin (self, plugin); |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 5481 | } |
| 5482 | |
Richard Hughes | e7e9545 | 2017-11-22 09:05:53 +0000 | [diff] [blame] | 5483 | /* depsolve into the correct order */ |
| 5484 | if (!fu_plugin_list_depsolve (self->plugin_list, error)) |
| 5485 | return FALSE; |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 5486 | |
Richard Hughes | e7e9545 | 2017-11-22 09:05:53 +0000 | [diff] [blame] | 5487 | /* success */ |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 5488 | return TRUE; |
| 5489 | } |
| 5490 | |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 5491 | static gboolean |
| 5492 | fu_engine_cleanup_state (GError **error) |
| 5493 | { |
| 5494 | const gchar *filenames[] = { |
| 5495 | "/var/cache/app-info/xmls/fwupd-verify.xml", |
| 5496 | "/var/cache/app-info/xmls/fwupd.xml", |
| 5497 | NULL }; |
| 5498 | for (guint i = 0; filenames[i] != NULL; i++) { |
| 5499 | g_autoptr(GFile) file = g_file_new_for_path (filenames[i]); |
| 5500 | if (g_file_query_exists (file, NULL)) { |
| 5501 | if (!g_file_delete (file, NULL, error)) |
| 5502 | return FALSE; |
| 5503 | } |
| 5504 | } |
| 5505 | return TRUE; |
| 5506 | } |
| 5507 | |
Richard Hughes | c7bbbc2 | 2018-01-02 22:22:25 +0000 | [diff] [blame] | 5508 | guint64 |
| 5509 | fu_engine_get_archive_size_max (FuEngine *self) |
| 5510 | { |
| 5511 | return fu_config_get_archive_size_max (self->config); |
| 5512 | } |
| 5513 | |
Richard Hughes | 104f651 | 2017-11-24 11:44:57 +0000 | [diff] [blame] | 5514 | static void |
| 5515 | fu_engine_usb_device_removed_cb (GUsbContext *ctx, |
| 5516 | GUsbDevice *usb_device, |
| 5517 | FuEngine *self) |
| 5518 | { |
| 5519 | g_autoptr(GPtrArray) devices = NULL; |
| 5520 | |
Richard Hughes | f3880bc | 2019-11-26 12:02:30 +0000 | [diff] [blame] | 5521 | /* debug */ |
| 5522 | if (g_getenv ("FWUPD_PROBE_VERBOSE") != NULL) { |
| 5523 | g_debug ("USB %04x:%04x removed", |
| 5524 | g_usb_device_get_vid (usb_device), |
| 5525 | g_usb_device_get_pid (usb_device)); |
| 5526 | } |
| 5527 | |
Richard Hughes | 104f651 | 2017-11-24 11:44:57 +0000 | [diff] [blame] | 5528 | /* go through each device and remove any that match */ |
Richard Hughes | c125ec0 | 2018-09-05 19:35:17 +0100 | [diff] [blame] | 5529 | devices = fu_device_list_get_all (self->device_list); |
Richard Hughes | 104f651 | 2017-11-24 11:44:57 +0000 | [diff] [blame] | 5530 | for (guint i = 0; i < devices->len; i++) { |
| 5531 | FuDevice *device = g_ptr_array_index (devices, i); |
Richard Hughes | c125ec0 | 2018-09-05 19:35:17 +0100 | [diff] [blame] | 5532 | if (!FU_IS_USB_DEVICE (device)) |
| 5533 | continue; |
| 5534 | if (g_strcmp0 (fu_usb_device_get_platform_id (FU_USB_DEVICE (device)), |
| 5535 | g_usb_device_get_platform_id (usb_device)) == 0) { |
| 5536 | g_debug ("auto-removing GUsbDevice"); |
| 5537 | fu_device_list_remove (self->device_list, device); |
| 5538 | } |
Richard Hughes | 104f651 | 2017-11-24 11:44:57 +0000 | [diff] [blame] | 5539 | } |
| 5540 | } |
| 5541 | |
| 5542 | static void |
| 5543 | fu_engine_usb_device_added_cb (GUsbContext *ctx, |
| 5544 | GUsbDevice *usb_device, |
| 5545 | FuEngine *self) |
| 5546 | { |
Richard Hughes | ff70441 | 2018-09-04 11:28:32 +0100 | [diff] [blame] | 5547 | g_autoptr(FuUsbDevice) device = fu_usb_device_new (usb_device); |
Richard Hughes | 6dec401 | 2018-08-27 19:13:00 +0100 | [diff] [blame] | 5548 | g_autoptr(GError) error_local = NULL; |
Richard Hughes | 45a1815 | 2019-10-30 15:29:04 +0000 | [diff] [blame] | 5549 | g_autoptr(GPtrArray) possible_plugins = NULL; |
Richard Hughes | 6dec401 | 2018-08-27 19:13:00 +0100 | [diff] [blame] | 5550 | |
Richard Hughes | f3880bc | 2019-11-26 12:02:30 +0000 | [diff] [blame] | 5551 | /* debug */ |
| 5552 | if (g_getenv ("FWUPD_PROBE_VERBOSE") != NULL) { |
| 5553 | g_debug ("USB %04x:%04x added", |
| 5554 | g_usb_device_get_vid (usb_device), |
| 5555 | g_usb_device_get_pid (usb_device)); |
| 5556 | } |
| 5557 | |
Richard Hughes | 6dec401 | 2018-08-27 19:13:00 +0100 | [diff] [blame] | 5558 | /* add any extra quirks */ |
Richard Hughes | ff70441 | 2018-09-04 11:28:32 +0100 | [diff] [blame] | 5559 | fu_device_set_quirks (FU_DEVICE (device), self->quirks); |
| 5560 | if (!fu_device_probe (FU_DEVICE (device), &error_local)) { |
Richard Hughes | 6dec401 | 2018-08-27 19:13:00 +0100 | [diff] [blame] | 5561 | g_warning ("failed to probe device %s: %s", |
Richard Hughes | c125ec0 | 2018-09-05 19:35:17 +0100 | [diff] [blame] | 5562 | fu_device_get_physical_id (FU_DEVICE (device)), |
Richard Hughes | 6dec401 | 2018-08-27 19:13:00 +0100 | [diff] [blame] | 5563 | error_local->message); |
| 5564 | return; |
| 5565 | } |
Richard Hughes | 6dbe8fe | 2018-06-28 12:16:26 +0100 | [diff] [blame] | 5566 | |
Richard Hughes | 23170a8 | 2018-08-29 09:11:52 +0100 | [diff] [blame] | 5567 | /* can be specified using a quirk */ |
Richard Hughes | 45a1815 | 2019-10-30 15:29:04 +0000 | [diff] [blame] | 5568 | possible_plugins = fu_device_get_possible_plugins (FU_DEVICE (device)); |
| 5569 | for (guint i = 0; i < possible_plugins->len; i++) { |
| 5570 | FuPlugin *plugin; |
| 5571 | const gchar *plugin_name = g_ptr_array_index (possible_plugins, i); |
| 5572 | g_autoptr(GError) error = NULL; |
Mario Limonciello | 0e50032 | 2019-10-17 18:41:04 -0500 | [diff] [blame] | 5573 | |
Richard Hughes | 45a1815 | 2019-10-30 15:29:04 +0000 | [diff] [blame] | 5574 | plugin = fu_plugin_list_find_by_name (self->plugin_list, |
| 5575 | plugin_name, &error); |
| 5576 | if (plugin == NULL) { |
Richard Hughes | a1f9535 | 2020-02-21 08:14:54 +0000 | [diff] [blame] | 5577 | g_debug ("failed to find specified plugin %s: %s", |
| 5578 | plugin_name, error->message); |
Richard Hughes | 45a1815 | 2019-10-30 15:29:04 +0000 | [diff] [blame] | 5579 | continue; |
| 5580 | } |
| 5581 | if (!fu_plugin_runner_usb_device_added (plugin, device, &error)) { |
| 5582 | if (g_error_matches (error, FWUPD_ERROR, FWUPD_ERROR_NOT_SUPPORTED)) { |
| 5583 | if (g_getenv ("FWUPD_PROBE_VERBOSE") != NULL) { |
| 5584 | g_debug ("%s ignoring: %s", |
| 5585 | fu_plugin_get_name (plugin), |
| 5586 | error->message); |
Mario Limonciello | 0e50032 | 2019-10-17 18:41:04 -0500 | [diff] [blame] | 5587 | } |
Mario Limonciello | 0e50032 | 2019-10-17 18:41:04 -0500 | [diff] [blame] | 5588 | continue; |
| 5589 | } |
Richard Hughes | 45a1815 | 2019-10-30 15:29:04 +0000 | [diff] [blame] | 5590 | g_warning ("failed to add USB device %04x:%04x: %s", |
| 5591 | g_usb_device_get_vid (usb_device), |
| 5592 | g_usb_device_get_pid (usb_device), |
| 5593 | error->message); |
| 5594 | continue; |
Richard Hughes | 6dbe8fe | 2018-06-28 12:16:26 +0100 | [diff] [blame] | 5595 | } |
Richard Hughes | 6dbe8fe | 2018-06-28 12:16:26 +0100 | [diff] [blame] | 5596 | } |
Richard Hughes | 104f651 | 2017-11-24 11:44:57 +0000 | [diff] [blame] | 5597 | } |
| 5598 | |
Richard Hughes | f77d706 | 2017-11-27 12:06:36 +0000 | [diff] [blame] | 5599 | static void |
Richard Hughes | 51a869a | 2019-10-07 11:23:42 +0100 | [diff] [blame] | 5600 | fu_engine_load_quirks (FuEngine *self, FuQuirksLoadFlags quirks_flags) |
Richard Hughes | f77d706 | 2017-11-27 12:06:36 +0000 | [diff] [blame] | 5601 | { |
Richard Hughes | f77d706 | 2017-11-27 12:06:36 +0000 | [diff] [blame] | 5602 | g_autoptr(GError) error = NULL; |
Richard Hughes | 51a869a | 2019-10-07 11:23:42 +0100 | [diff] [blame] | 5603 | if (!fu_quirks_load (self->quirks, quirks_flags, &error)) |
Richard Hughes | f77d706 | 2017-11-27 12:06:36 +0000 | [diff] [blame] | 5604 | g_warning ("Failed to load quirks: %s", error->message); |
| 5605 | } |
| 5606 | |
| 5607 | static void |
| 5608 | fu_engine_load_smbios (FuEngine *self) |
| 5609 | { |
Richard Hughes | f77d706 | 2017-11-27 12:06:36 +0000 | [diff] [blame] | 5610 | g_autoptr(GError) error = NULL; |
Richard Hughes | f77d706 | 2017-11-27 12:06:36 +0000 | [diff] [blame] | 5611 | if (!fu_smbios_setup (self->smbios, &error)) |
| 5612 | g_warning ("Failed to load SMBIOS: %s", error->message); |
| 5613 | } |
| 5614 | |
| 5615 | static void |
| 5616 | fu_engine_load_hwids (FuEngine *self) |
| 5617 | { |
Richard Hughes | f77d706 | 2017-11-27 12:06:36 +0000 | [diff] [blame] | 5618 | g_autoptr(GError) error = NULL; |
Richard Hughes | f77d706 | 2017-11-27 12:06:36 +0000 | [diff] [blame] | 5619 | if (!fu_hwids_setup (self->hwids, self->smbios, &error)) |
| 5620 | g_warning ("Failed to load HWIDs: %s", error->message); |
| 5621 | } |
| 5622 | |
Richard Hughes | a2f8e45 | 2018-01-11 10:11:17 +0000 | [diff] [blame] | 5623 | static gboolean |
| 5624 | fu_engine_update_history_device (FuEngine *self, FuDevice *dev_history, GError **error) |
| 5625 | { |
Richard Hughes | a2f8e45 | 2018-01-11 10:11:17 +0000 | [diff] [blame] | 5626 | FuPlugin *plugin; |
| 5627 | FwupdRelease *rel_history; |
Richard Hughes | f271142 | 2018-01-12 09:49:05 +0000 | [diff] [blame] | 5628 | g_autofree gchar *btime = NULL; |
Richard Hughes | 5a9a6bd | 2018-09-10 10:02:20 +0100 | [diff] [blame] | 5629 | g_autoptr(FuDevice) dev = NULL; |
Richard Hughes | a2f8e45 | 2018-01-11 10:11:17 +0000 | [diff] [blame] | 5630 | |
| 5631 | /* is in the device list */ |
Richard Hughes | 4012754 | 2018-01-12 20:25:55 +0000 | [diff] [blame] | 5632 | dev = fu_device_list_get_by_id (self->device_list, |
| 5633 | fu_device_get_id (dev_history), |
| 5634 | error); |
Richard Hughes | a2f8e45 | 2018-01-11 10:11:17 +0000 | [diff] [blame] | 5635 | if (dev == NULL) |
| 5636 | return FALSE; |
| 5637 | |
| 5638 | /* does the installed version match what we tried to install |
| 5639 | * before fwupd was restarted */ |
| 5640 | rel_history = fu_device_get_release_default (dev_history); |
| 5641 | if (rel_history == NULL) { |
| 5642 | g_set_error_literal (error, |
| 5643 | FWUPD_ERROR, |
| 5644 | FWUPD_ERROR_INTERNAL, |
| 5645 | "no release for history FuDevice"); |
| 5646 | return FALSE; |
| 5647 | } |
| 5648 | |
Richard Hughes | f271142 | 2018-01-12 09:49:05 +0000 | [diff] [blame] | 5649 | /* is this the same boot time as when we scheduled the update, |
| 5650 | * i.e. has fwupd been restarted before we rebooted */ |
| 5651 | btime = fu_engine_get_boot_time (); |
| 5652 | if (g_strcmp0 (fwupd_release_get_metadata_item (rel_history, "BootTime"), |
| 5653 | btime) == 0) { |
| 5654 | g_debug ("service restarted, but no reboot has taken place"); |
| 5655 | return TRUE; |
| 5656 | } |
| 5657 | |
Richard Hughes | a2f8e45 | 2018-01-11 10:11:17 +0000 | [diff] [blame] | 5658 | /* the system is running with the new firmware version */ |
Richard Hughes | 9a68084 | 2020-02-20 11:11:13 +0000 | [diff] [blame] | 5659 | if (fu_common_vercmp_full (fu_device_get_version (dev), |
| 5660 | fwupd_release_get_version (rel_history), |
| 5661 | fu_device_get_version_format (dev)) == 0) { |
Richard Hughes | 4e886a4 | 2018-12-12 10:33:26 +0000 | [diff] [blame] | 5662 | GPtrArray *checksums; |
Richard Hughes | a2f8e45 | 2018-01-11 10:11:17 +0000 | [diff] [blame] | 5663 | g_debug ("installed version %s matching history %s", |
| 5664 | fu_device_get_version (dev), |
| 5665 | fwupd_release_get_version (rel_history)); |
Richard Hughes | 4e886a4 | 2018-12-12 10:33:26 +0000 | [diff] [blame] | 5666 | |
| 5667 | /* copy over runtime checksums if set from probe() */ |
| 5668 | checksums = fu_device_get_checksums (dev); |
| 5669 | for (guint i = 0; i < checksums->len; i++) { |
| 5670 | const gchar *csum = g_ptr_array_index (checksums, i); |
| 5671 | fu_device_add_checksum (dev_history, csum); |
| 5672 | } |
Richard Hughes | f50ff2c | 2020-02-25 09:45:15 +0000 | [diff] [blame] | 5673 | fu_device_set_version_format (dev_history, fu_device_get_version_format (dev)); |
| 5674 | fu_device_set_version (dev_history, fu_device_get_version (dev)); |
Mario Limonciello | 96a0dd5 | 2019-02-25 13:50:03 -0600 | [diff] [blame] | 5675 | fu_device_remove_flag (dev_history, FWUPD_DEVICE_FLAG_NEEDS_ACTIVATION); |
Richard Hughes | c0cd023 | 2018-01-31 15:02:00 +0000 | [diff] [blame] | 5676 | fu_device_set_update_state (dev_history, FWUPD_UPDATE_STATE_SUCCESS); |
Richard Hughes | 0bbef29 | 2019-11-01 12:15:15 +0000 | [diff] [blame] | 5677 | return fu_history_modify_device (self->history, dev_history, error); |
Richard Hughes | a2f8e45 | 2018-01-11 10:11:17 +0000 | [diff] [blame] | 5678 | } |
| 5679 | |
Richard Hughes | 7e070c9 | 2018-01-12 16:50:05 +0000 | [diff] [blame] | 5680 | /* does the plugin know the update failure */ |
Richard Hughes | a2f8e45 | 2018-01-11 10:11:17 +0000 | [diff] [blame] | 5681 | plugin = fu_plugin_list_find_by_name (self->plugin_list, |
| 5682 | fu_device_get_plugin (dev), |
| 5683 | error); |
| 5684 | if (plugin == NULL) |
| 5685 | return FALSE; |
Richard Hughes | a2f8e45 | 2018-01-11 10:11:17 +0000 | [diff] [blame] | 5686 | if (!fu_plugin_runner_get_results (plugin, dev, error)) |
| 5687 | return FALSE; |
Richard Hughes | 7e070c9 | 2018-01-12 16:50:05 +0000 | [diff] [blame] | 5688 | |
| 5689 | /* the plugin either can't tell us the error, or doesn't know itself */ |
Richard Hughes | cce6a1c | 2019-04-16 17:25:48 +0100 | [diff] [blame] | 5690 | if (fu_device_get_update_state (dev) != FWUPD_UPDATE_STATE_FAILED && |
| 5691 | fu_device_get_update_state (dev) != FWUPD_UPDATE_STATE_FAILED_TRANSIENT) { |
Richard Hughes | 7e070c9 | 2018-01-12 16:50:05 +0000 | [diff] [blame] | 5692 | g_debug ("falling back to generic failure"); |
Richard Hughes | c0cd023 | 2018-01-31 15:02:00 +0000 | [diff] [blame] | 5693 | fu_device_set_update_error (dev_history, "failed to run update on reboot"); |
Richard Hughes | a2f8e45 | 2018-01-11 10:11:17 +0000 | [diff] [blame] | 5694 | } |
Richard Hughes | 7e070c9 | 2018-01-12 16:50:05 +0000 | [diff] [blame] | 5695 | |
| 5696 | /* update the state in the database */ |
Richard Hughes | c0cd023 | 2018-01-31 15:02:00 +0000 | [diff] [blame] | 5697 | fu_device_set_update_error (dev_history, fu_device_get_update_error (dev)); |
Richard Hughes | 0bbef29 | 2019-11-01 12:15:15 +0000 | [diff] [blame] | 5698 | return fu_history_modify_device (self->history, dev_history, error); |
Richard Hughes | a2f8e45 | 2018-01-11 10:11:17 +0000 | [diff] [blame] | 5699 | } |
| 5700 | |
| 5701 | static gboolean |
| 5702 | fu_engine_update_history_database (FuEngine *self, GError **error) |
| 5703 | { |
| 5704 | g_autoptr(GPtrArray) devices = NULL; |
| 5705 | |
| 5706 | /* get any devices */ |
| 5707 | devices = fu_history_get_devices (self->history, error); |
| 5708 | if (devices == NULL) |
| 5709 | return FALSE; |
| 5710 | for (guint i = 0; i < devices->len; i++) { |
| 5711 | FuDevice *dev = g_ptr_array_index (devices, i); |
| 5712 | g_autoptr(GError) error_local = NULL; |
| 5713 | |
| 5714 | /* not in the required state */ |
| 5715 | if (fu_device_get_update_state (dev) != FWUPD_UPDATE_STATE_NEEDS_REBOOT) |
| 5716 | continue; |
| 5717 | |
| 5718 | /* try to save the new update-state, but ignoring any error */ |
| 5719 | if (!fu_engine_update_history_device (self, dev, &error_local)) |
| 5720 | g_warning ("%s", error_local->message); |
| 5721 | } |
| 5722 | return TRUE; |
| 5723 | } |
| 5724 | |
Richard Hughes | 1665837 | 2019-11-22 09:23:59 +0000 | [diff] [blame] | 5725 | #ifdef HAVE_GUDEV |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 5726 | static void |
| 5727 | fu_engine_udev_uevent_cb (GUdevClient *gudev_client, |
| 5728 | const gchar *action, |
| 5729 | GUdevDevice *udev_device, |
| 5730 | FuEngine *self) |
| 5731 | { |
| 5732 | if (g_strcmp0 (action, "add") == 0) { |
| 5733 | fu_engine_udev_device_add (self, udev_device); |
| 5734 | return; |
| 5735 | } |
| 5736 | if (g_strcmp0 (action, "remove") == 0) { |
| 5737 | fu_engine_udev_device_remove (self, udev_device); |
| 5738 | return; |
| 5739 | } |
| 5740 | if (g_strcmp0 (action, "change") == 0) { |
| 5741 | fu_engine_udev_device_changed (self, udev_device); |
| 5742 | return; |
| 5743 | } |
| 5744 | } |
Richard Hughes | 1665837 | 2019-11-22 09:23:59 +0000 | [diff] [blame] | 5745 | #endif |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 5746 | |
Richard Hughes | f3c7d42 | 2019-03-12 10:29:42 +0000 | [diff] [blame] | 5747 | static void |
| 5748 | fu_engine_ensure_client_certificate (FuEngine *self) |
| 5749 | { |
Richard Hughes | f3c7d42 | 2019-03-12 10:29:42 +0000 | [diff] [blame] | 5750 | g_autoptr(GBytes) blob = g_bytes_new_static ("test\0", 5); |
Richard Hughes | f3c7d42 | 2019-03-12 10:29:42 +0000 | [diff] [blame] | 5751 | g_autoptr(GError) error = NULL; |
Richard Hughes | d5aab65 | 2020-02-25 12:47:50 +0000 | [diff] [blame] | 5752 | g_autoptr(JcatBlob) jcat_sig = NULL; |
| 5753 | g_autoptr(JcatEngine) jcat_engine = NULL; |
Richard Hughes | f3c7d42 | 2019-03-12 10:29:42 +0000 | [diff] [blame] | 5754 | |
| 5755 | /* create keyring and sign dummy data to ensure certificate exists */ |
Richard Hughes | d5aab65 | 2020-02-25 12:47:50 +0000 | [diff] [blame] | 5756 | jcat_engine = jcat_context_get_engine (self->jcat_context, |
| 5757 | JCAT_BLOB_KIND_PKCS7, |
| 5758 | &error); |
| 5759 | if (jcat_engine == NULL) { |
Richard Hughes | f3c7d42 | 2019-03-12 10:29:42 +0000 | [diff] [blame] | 5760 | g_message ("failed to create keyring: %s", error->message); |
| 5761 | return; |
| 5762 | } |
Richard Hughes | d5aab65 | 2020-02-25 12:47:50 +0000 | [diff] [blame] | 5763 | jcat_sig = jcat_engine_self_sign (jcat_engine, blob, JCAT_SIGN_FLAG_NONE, &error); |
| 5764 | if (jcat_sig == NULL) { |
Richard Hughes | f3c7d42 | 2019-03-12 10:29:42 +0000 | [diff] [blame] | 5765 | g_message ("failed to sign using keyring: %s", error->message); |
| 5766 | return; |
| 5767 | } |
| 5768 | g_debug ("client certificate exists and working"); |
| 5769 | } |
| 5770 | |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 5771 | /** |
| 5772 | * fu_engine_load: |
| 5773 | * @self: A #FuEngine |
Richard Hughes | c8cc77c | 2019-03-07 11:57:24 +0000 | [diff] [blame] | 5774 | * @flags: #FuEngineLoadFlags, e.g. %FU_ENGINE_LOAD_FLAG_READONLY_FS |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 5775 | * @error: A #GError, or %NULL |
| 5776 | * |
| 5777 | * Load the firmware update engine so it is ready for use. |
| 5778 | * |
| 5779 | * Returns: %TRUE for success |
| 5780 | **/ |
| 5781 | gboolean |
Richard Hughes | c8cc77c | 2019-03-07 11:57:24 +0000 | [diff] [blame] | 5782 | fu_engine_load (FuEngine *self, FuEngineLoadFlags flags, GError **error) |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 5783 | { |
Richard Hughes | d1808aa | 2019-12-10 15:20:30 +0000 | [diff] [blame] | 5784 | FuRemoteListLoadFlags remote_list_flags = FU_REMOTE_LIST_LOAD_FLAG_NONE; |
Richard Hughes | 51a869a | 2019-10-07 11:23:42 +0100 | [diff] [blame] | 5785 | FuQuirksLoadFlags quirks_flags = FU_QUIRKS_LOAD_FLAG_NONE; |
Richard Hughes | 8dd4c1c | 2019-03-03 18:27:57 +0000 | [diff] [blame] | 5786 | g_autoptr(GPtrArray) checksums = NULL; |
Daniel Campello | b5ae60c | 2020-02-27 17:06:28 -0700 | [diff] [blame] | 5787 | #ifndef _WIN32 |
| 5788 | g_autoptr(GError) error_local = NULL; |
| 5789 | #endif |
Richard Hughes | 8dd4c1c | 2019-03-03 18:27:57 +0000 | [diff] [blame] | 5790 | |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 5791 | g_return_val_if_fail (FU_IS_ENGINE (self), FALSE); |
| 5792 | g_return_val_if_fail (error == NULL || *error == NULL, FALSE); |
| 5793 | |
Mario Limonciello | 46aaee8 | 2019-01-10 12:58:00 -0600 | [diff] [blame] | 5794 | /* avoid re-loading a second time if fu-tool or fu-util request to */ |
| 5795 | if (self->loaded) |
| 5796 | return TRUE; |
| 5797 | |
Richard Hughes | 45a0073 | 2019-11-22 16:57:14 +0000 | [diff] [blame] | 5798 | /* TODO: Read registry key [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography] "MachineGuid" */ |
| 5799 | #ifndef _WIN32 |
Richard Hughes | 0917fb6 | 2019-09-21 12:55:37 +0100 | [diff] [blame] | 5800 | /* cache machine ID so we can use it from a sandboxed app */ |
Daniel Campello | b5ae60c | 2020-02-27 17:06:28 -0700 | [diff] [blame] | 5801 | self->host_machine_id = fwupd_build_machine_id ("fwupd", &error_local); |
Richard Hughes | 0917fb6 | 2019-09-21 12:55:37 +0100 | [diff] [blame] | 5802 | if (self->host_machine_id == NULL) |
Daniel Campello | b5ae60c | 2020-02-27 17:06:28 -0700 | [diff] [blame] | 5803 | g_debug ("%s", error_local->message); |
Richard Hughes | 45a0073 | 2019-11-22 16:57:14 +0000 | [diff] [blame] | 5804 | #endif |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 5805 | /* read config file */ |
Richard Hughes | d1808aa | 2019-12-10 15:20:30 +0000 | [diff] [blame] | 5806 | if (!fu_config_load (self->config, error)) { |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 5807 | g_prefix_error (error, "Failed to load config: "); |
| 5808 | return FALSE; |
| 5809 | } |
| 5810 | |
Richard Hughes | d1808aa | 2019-12-10 15:20:30 +0000 | [diff] [blame] | 5811 | /* read remotes */ |
| 5812 | if (flags & FU_ENGINE_LOAD_FLAG_READONLY_FS) |
| 5813 | remote_list_flags |= FU_REMOTE_LIST_LOAD_FLAG_READONLY_FS; |
| 5814 | if (!fu_remote_list_load (self->remote_list, remote_list_flags, error)) { |
| 5815 | g_prefix_error (error, "Failed to load remotes: "); |
| 5816 | return FALSE; |
| 5817 | } |
| 5818 | |
Richard Hughes | f3c7d42 | 2019-03-12 10:29:42 +0000 | [diff] [blame] | 5819 | /* create client certificate */ |
| 5820 | fu_engine_ensure_client_certificate (self); |
| 5821 | |
Richard Hughes | 8dd4c1c | 2019-03-03 18:27:57 +0000 | [diff] [blame] | 5822 | /* get hardcoded approved firmware */ |
| 5823 | checksums = fu_config_get_approved_firmware (self->config); |
| 5824 | for (guint i = 0; i < checksums->len; i++) { |
| 5825 | const gchar *csum = g_ptr_array_index (checksums, i); |
| 5826 | fu_engine_add_approved_firmware (self, csum); |
| 5827 | } |
| 5828 | |
| 5829 | /* get extra firmware saved to the database */ |
| 5830 | checksums = fu_history_get_approved_firmware (self->history, error); |
| 5831 | if (checksums == NULL) |
| 5832 | return FALSE; |
| 5833 | for (guint i = 0; i < checksums->len; i++) { |
| 5834 | const gchar *csum = g_ptr_array_index (checksums, i); |
| 5835 | fu_engine_add_approved_firmware (self, csum); |
| 5836 | } |
| 5837 | |
Richard Hughes | 75b965d | 2018-11-15 13:51:21 +0000 | [diff] [blame] | 5838 | /* set up idle exit */ |
| 5839 | if ((self->app_flags & FU_APP_FLAGS_NO_IDLE_SOURCES) == 0) |
| 5840 | fu_idle_set_timeout (self->idle, fu_config_get_idle_timeout (self->config)); |
| 5841 | |
Richard Hughes | f77d706 | 2017-11-27 12:06:36 +0000 | [diff] [blame] | 5842 | /* load quirks, SMBIOS and the hwids */ |
| 5843 | fu_engine_load_smbios (self); |
| 5844 | fu_engine_load_hwids (self); |
Richard Hughes | 51a869a | 2019-10-07 11:23:42 +0100 | [diff] [blame] | 5845 | /* on a read-only filesystem don't care about the cache GUID */ |
| 5846 | if (flags & FU_ENGINE_LOAD_FLAG_READONLY_FS) |
| 5847 | quirks_flags |= FU_QUIRKS_LOAD_FLAG_READONLY_FS; |
| 5848 | fu_engine_load_quirks (self, quirks_flags); |
Richard Hughes | 9c028f0 | 2017-10-28 21:14:28 +0100 | [diff] [blame] | 5849 | |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 5850 | /* load AppStream metadata */ |
Richard Hughes | c8cc77c | 2019-03-07 11:57:24 +0000 | [diff] [blame] | 5851 | if (!fu_engine_load_metadata_store (self, flags, error)) { |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 5852 | g_prefix_error (error, "Failed to load AppStream data: "); |
| 5853 | return FALSE; |
| 5854 | } |
| 5855 | |
Richard Hughes | 95c98a9 | 2019-10-22 16:03:15 +0100 | [diff] [blame] | 5856 | /* add the "built-in" firmware types */ |
| 5857 | fu_engine_add_firmware_gtype (self, "raw", FU_TYPE_FIRMWARE); |
| 5858 | fu_engine_add_firmware_gtype (self, "dfu", FU_TYPE_DFU_FIRMWARE); |
| 5859 | fu_engine_add_firmware_gtype (self, "ihex", FU_TYPE_IHEX_FIRMWARE); |
| 5860 | fu_engine_add_firmware_gtype (self, "srec", FU_TYPE_SREC_FIRMWARE); |
| 5861 | |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 5862 | /* set shared USB context */ |
| 5863 | self->usb_ctx = g_usb_context_new (error); |
| 5864 | if (self->usb_ctx == NULL) { |
| 5865 | g_prefix_error (error, "Failed to get USB context: "); |
| 5866 | return FALSE; |
| 5867 | } |
| 5868 | |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 5869 | /* delete old data files */ |
| 5870 | if (!fu_engine_cleanup_state (error)) { |
| 5871 | g_prefix_error (error, "Failed to clean up: "); |
| 5872 | return FALSE; |
| 5873 | } |
| 5874 | |
| 5875 | /* load plugin */ |
| 5876 | if (!fu_engine_load_plugins (self, error)) { |
| 5877 | g_prefix_error (error, "Failed to load plugins: "); |
| 5878 | return FALSE; |
| 5879 | } |
| 5880 | |
Richard Hughes | 170c0c1 | 2017-11-22 11:26:24 +0000 | [diff] [blame] | 5881 | /* watch the device list for updates and proxy */ |
| 5882 | g_signal_connect (self->device_list, "added", |
| 5883 | G_CALLBACK (fu_engine_device_added_cb), |
| 5884 | self); |
| 5885 | g_signal_connect (self->device_list, "removed", |
| 5886 | G_CALLBACK (fu_engine_device_removed_cb), |
| 5887 | self); |
| 5888 | g_signal_connect (self->device_list, "changed", |
| 5889 | G_CALLBACK (fu_engine_device_changed_cb), |
| 5890 | self); |
| 5891 | |
Richard Hughes | 1665837 | 2019-11-22 09:23:59 +0000 | [diff] [blame] | 5892 | #ifdef HAVE_GUDEV |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 5893 | /* udev watches can only be set up in _init() so set up client now */ |
| 5894 | if (self->udev_subsystems->len > 0) { |
Richard Hughes | effcc7a | 2018-08-31 14:32:07 +0100 | [diff] [blame] | 5895 | g_auto(GStrv) udev_subsystems = g_new0 (gchar *, self->udev_subsystems->len + 1); |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 5896 | for (guint i = 0; i < self->udev_subsystems->len; i++) { |
| 5897 | const gchar *subsystem = g_ptr_array_index (self->udev_subsystems, i); |
| 5898 | udev_subsystems[i] = g_strdup (subsystem); |
| 5899 | } |
| 5900 | self->gudev_client = g_udev_client_new ((const gchar * const *) udev_subsystems); |
| 5901 | g_signal_connect (self->gudev_client, "uevent", |
| 5902 | G_CALLBACK (fu_engine_udev_uevent_cb), self); |
| 5903 | } |
Richard Hughes | 1665837 | 2019-11-22 09:23:59 +0000 | [diff] [blame] | 5904 | #endif |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 5905 | |
Mario Limonciello | 6463f31 | 2018-08-09 13:28:46 -0500 | [diff] [blame] | 5906 | fu_engine_set_status (self, FWUPD_STATUS_LOADING); |
| 5907 | |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 5908 | /* add devices */ |
| 5909 | fu_engine_plugins_setup (self); |
Richard Hughes | 8fb2e6a | 2019-10-22 15:37:57 +0100 | [diff] [blame] | 5910 | if ((flags & FU_ENGINE_LOAD_FLAG_NO_ENUMERATE) == 0) |
| 5911 | fu_engine_plugins_coldplug (self, FALSE); |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 5912 | |
Richard Hughes | 634e922 | 2017-11-29 15:50:02 +0000 | [diff] [blame] | 5913 | /* coldplug USB devices */ |
Richard Hughes | 104f651 | 2017-11-24 11:44:57 +0000 | [diff] [blame] | 5914 | g_signal_connect (self->usb_ctx, "device-added", |
| 5915 | G_CALLBACK (fu_engine_usb_device_added_cb), |
| 5916 | self); |
| 5917 | g_signal_connect (self->usb_ctx, "device-removed", |
| 5918 | G_CALLBACK (fu_engine_usb_device_removed_cb), |
| 5919 | self); |
Richard Hughes | e375751 | 2019-09-25 10:12:28 +0100 | [diff] [blame] | 5920 | if ((flags & FU_ENGINE_LOAD_FLAG_NO_ENUMERATE) == 0) |
| 5921 | g_usb_context_enumerate (self->usb_ctx); |
Richard Hughes | 104f651 | 2017-11-24 11:44:57 +0000 | [diff] [blame] | 5922 | |
Richard Hughes | 1665837 | 2019-11-22 09:23:59 +0000 | [diff] [blame] | 5923 | #ifdef HAVE_GUDEV |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 5924 | /* coldplug udev devices */ |
Richard Hughes | e375751 | 2019-09-25 10:12:28 +0100 | [diff] [blame] | 5925 | if ((flags & FU_ENGINE_LOAD_FLAG_NO_ENUMERATE) == 0) |
| 5926 | fu_engine_enumerate_udev (self); |
Richard Hughes | 1665837 | 2019-11-22 09:23:59 +0000 | [diff] [blame] | 5927 | #endif |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 5928 | |
Richard Hughes | f43381f | 2020-02-24 10:11:31 +0000 | [diff] [blame] | 5929 | /* set device properties from the metadata */ |
| 5930 | fu_engine_md_refresh_devices (self); |
| 5931 | |
Richard Hughes | a2f8e45 | 2018-01-11 10:11:17 +0000 | [diff] [blame] | 5932 | /* update the db for devices that were updated during the reboot */ |
| 5933 | if (!fu_engine_update_history_database (self, error)) |
| 5934 | return FALSE; |
| 5935 | |
Mario Limonciello | 6463f31 | 2018-08-09 13:28:46 -0500 | [diff] [blame] | 5936 | fu_engine_set_status (self, FWUPD_STATUS_IDLE); |
Mario Limonciello | 46aaee8 | 2019-01-10 12:58:00 -0600 | [diff] [blame] | 5937 | self->loaded = TRUE; |
Mario Limonciello | 6463f31 | 2018-08-09 13:28:46 -0500 | [diff] [blame] | 5938 | |
Mario Limonciello | d81ea2e | 2020-01-13 14:11:43 -0600 | [diff] [blame] | 5939 | /* let clients know engine finished starting up */ |
| 5940 | fu_engine_emit_changed (self); |
| 5941 | |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 5942 | /* success */ |
| 5943 | return TRUE; |
| 5944 | } |
| 5945 | |
| 5946 | static void |
| 5947 | fu_engine_class_init (FuEngineClass *klass) |
| 5948 | { |
| 5949 | GObjectClass *object_class = G_OBJECT_CLASS (klass); |
| 5950 | object_class->finalize = fu_engine_finalize; |
| 5951 | |
| 5952 | signals[SIGNAL_CHANGED] = |
| 5953 | g_signal_new ("changed", |
| 5954 | G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, |
| 5955 | 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, |
| 5956 | G_TYPE_NONE, 0); |
| 5957 | signals[SIGNAL_DEVICE_ADDED] = |
| 5958 | g_signal_new ("device-added", |
| 5959 | G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, |
| 5960 | 0, NULL, NULL, g_cclosure_marshal_VOID__OBJECT, |
| 5961 | G_TYPE_NONE, 1, FU_TYPE_DEVICE); |
| 5962 | signals[SIGNAL_DEVICE_REMOVED] = |
| 5963 | g_signal_new ("device-removed", |
| 5964 | G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, |
| 5965 | 0, NULL, NULL, g_cclosure_marshal_VOID__OBJECT, |
| 5966 | G_TYPE_NONE, 1, FU_TYPE_DEVICE); |
Richard Hughes | a5bb4d8 | 2017-06-19 20:22:25 +0100 | [diff] [blame] | 5967 | signals[SIGNAL_DEVICE_CHANGED] = |
| 5968 | g_signal_new ("device-changed", |
| 5969 | G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, |
| 5970 | 0, NULL, NULL, g_cclosure_marshal_VOID__OBJECT, |
| 5971 | G_TYPE_NONE, 1, FU_TYPE_DEVICE); |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 5972 | signals[SIGNAL_STATUS_CHANGED] = |
| 5973 | g_signal_new ("status-changed", |
| 5974 | G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, |
| 5975 | 0, NULL, NULL, g_cclosure_marshal_VOID__UINT, |
| 5976 | G_TYPE_NONE, 1, G_TYPE_UINT); |
| 5977 | signals[SIGNAL_PERCENTAGE_CHANGED] = |
| 5978 | g_signal_new ("percentage-changed", |
| 5979 | G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, |
| 5980 | 0, NULL, NULL, g_cclosure_marshal_VOID__UINT, |
| 5981 | G_TYPE_NONE, 1, G_TYPE_UINT); |
| 5982 | } |
| 5983 | |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 5984 | void |
| 5985 | fu_engine_add_runtime_version (FuEngine *self, |
| 5986 | const gchar *component_id, |
| 5987 | const gchar *version) |
| 5988 | { |
| 5989 | g_hash_table_insert (self->runtime_versions, |
| 5990 | g_strdup (component_id), |
| 5991 | g_strdup (version)); |
| 5992 | } |
| 5993 | |
Richard Hughes | f517c9a | 2019-03-22 19:50:35 +0000 | [diff] [blame] | 5994 | void |
| 5995 | fu_engine_add_app_flag (FuEngine *self, FuAppFlags app_flags) |
| 5996 | { |
| 5997 | g_return_if_fail (FU_IS_ENGINE (self)); |
| 5998 | self->app_flags |= app_flags; |
| 5999 | } |
| 6000 | |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 6001 | static void |
Richard Hughes | 75b965d | 2018-11-15 13:51:21 +0000 | [diff] [blame] | 6002 | fu_engine_idle_status_notify_cb (FuIdle *idle, GParamSpec *pspec, FuEngine *self) |
| 6003 | { |
| 6004 | FwupdStatus status = fu_idle_get_status (idle); |
| 6005 | if (status == FWUPD_STATUS_SHUTDOWN) |
| 6006 | fu_engine_set_status (self, status); |
| 6007 | } |
| 6008 | |
| 6009 | static void |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 6010 | fu_engine_init (FuEngine *self) |
| 6011 | { |
Richard Hughes | fc1e267 | 2019-11-22 08:53:33 +0000 | [diff] [blame] | 6012 | #ifdef HAVE_UTSNAME_H |
Richard Hughes | f679e5e | 2019-08-28 15:31:34 +0100 | [diff] [blame] | 6013 | struct utsname uname_tmp; |
Richard Hughes | fc1e267 | 2019-11-22 08:53:33 +0000 | [diff] [blame] | 6014 | #endif |
Richard Hughes | d5aab65 | 2020-02-25 12:47:50 +0000 | [diff] [blame] | 6015 | g_autofree gchar *keyring_path = NULL; |
| 6016 | g_autofree gchar *pkidir_fw = NULL; |
| 6017 | g_autofree gchar *pkidir_md = NULL; |
| 6018 | g_autofree gchar *sysconfdir = NULL; |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 6019 | self->percentage = 0; |
| 6020 | self->status = FWUPD_STATUS_IDLE; |
| 6021 | self->config = fu_config_new (); |
Richard Hughes | d1808aa | 2019-12-10 15:20:30 +0000 | [diff] [blame] | 6022 | self->remote_list = fu_remote_list_new (); |
Richard Hughes | 0a7e783 | 2017-11-22 11:01:13 +0000 | [diff] [blame] | 6023 | self->device_list = fu_device_list_new (); |
Richard Hughes | 49e5e05 | 2017-09-03 12:15:41 +0100 | [diff] [blame] | 6024 | self->smbios = fu_smbios_new (); |
Richard Hughes | d7704d4 | 2017-08-08 20:29:09 +0100 | [diff] [blame] | 6025 | self->hwids = fu_hwids_new (); |
Richard Hughes | 75b965d | 2018-11-15 13:51:21 +0000 | [diff] [blame] | 6026 | self->idle = fu_idle_new (); |
Richard Hughes | 9c028f0 | 2017-10-28 21:14:28 +0100 | [diff] [blame] | 6027 | self->quirks = fu_quirks_new (); |
Richard Hughes | bc3a4e1 | 2018-01-06 22:41:47 +0000 | [diff] [blame] | 6028 | self->history = fu_history_new (); |
Richard Hughes | e7e9545 | 2017-11-22 09:05:53 +0000 | [diff] [blame] | 6029 | self->plugin_list = fu_plugin_list_new (); |
Richard Hughes | c02ee4d | 2018-05-22 15:46:03 +0100 | [diff] [blame] | 6030 | self->plugin_filter = g_ptr_array_new_with_free_func (g_free); |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 6031 | self->udev_subsystems = g_ptr_array_new_with_free_func (g_free); |
Richard Hughes | 1665837 | 2019-11-22 09:23:59 +0000 | [diff] [blame] | 6032 | #ifdef HAVE_GUDEV |
Richard Hughes | 5e952ce | 2019-08-26 11:09:46 +0100 | [diff] [blame] | 6033 | self->udev_changed_ids = g_hash_table_new_full (g_str_hash, g_str_equal, |
| 6034 | g_free, (GDestroyNotify) fu_engine_udev_changed_helper_free); |
Richard Hughes | 1665837 | 2019-11-22 09:23:59 +0000 | [diff] [blame] | 6035 | #endif |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 6036 | self->runtime_versions = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); |
Richard Hughes | 34e0dab | 2018-04-20 16:43:00 +0100 | [diff] [blame] | 6037 | self->compile_versions = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); |
Richard Hughes | 8dd4c1c | 2019-03-03 18:27:57 +0000 | [diff] [blame] | 6038 | self->approved_firmware = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); |
Richard Hughes | 95c98a9 | 2019-10-22 16:03:15 +0100 | [diff] [blame] | 6039 | self->firmware_gtypes = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 6040 | |
Mario Limonciello | 263cab9 | 2019-08-20 17:16:00 -0500 | [diff] [blame] | 6041 | g_signal_connect (self->config, "changed", |
| 6042 | G_CALLBACK (fu_engine_config_changed_cb), |
| 6043 | self); |
Richard Hughes | d1808aa | 2019-12-10 15:20:30 +0000 | [diff] [blame] | 6044 | g_signal_connect (self->remote_list, "changed", |
| 6045 | G_CALLBACK (fu_engine_remote_list_changed_cb), |
| 6046 | self); |
Mario Limonciello | 263cab9 | 2019-08-20 17:16:00 -0500 | [diff] [blame] | 6047 | |
Richard Hughes | 75b965d | 2018-11-15 13:51:21 +0000 | [diff] [blame] | 6048 | g_signal_connect (self->idle, "notify::status", |
| 6049 | G_CALLBACK (fu_engine_idle_status_notify_cb), self); |
| 6050 | |
Richard Hughes | d5aab65 | 2020-02-25 12:47:50 +0000 | [diff] [blame] | 6051 | /* setup Jcat context */ |
| 6052 | self->jcat_context = jcat_context_new (); |
| 6053 | keyring_path = fu_common_get_path (FU_PATH_KIND_LOCALSTATEDIR_PKG); |
| 6054 | jcat_context_set_keyring_path (self->jcat_context, keyring_path); |
| 6055 | sysconfdir = fu_common_get_path (FU_PATH_KIND_SYSCONFDIR); |
| 6056 | pkidir_fw = g_build_filename (sysconfdir, "pki", "fwupd", NULL); |
| 6057 | jcat_context_add_public_keys (self->jcat_context, pkidir_fw); |
| 6058 | pkidir_md = g_build_filename (sysconfdir, "pki", "fwupd-metadata", NULL); |
| 6059 | jcat_context_add_public_keys (self->jcat_context, pkidir_md); |
| 6060 | |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 6061 | /* add some runtime versions of things the daemon depends on */ |
| 6062 | fu_engine_add_runtime_version (self, "org.freedesktop.fwupd", VERSION); |
Richard Hughes | 2d37c3f | 2018-08-04 15:18:25 +0100 | [diff] [blame] | 6063 | fu_engine_add_runtime_version (self, "com.redhat.fwupdate", "12"); |
Richard Hughes | 416ade7 | 2018-10-10 20:36:53 +0100 | [diff] [blame] | 6064 | fu_engine_add_runtime_version (self, "org.freedesktop.appstream-glib", "0.7.14"); |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 6065 | #if G_USB_CHECK_VERSION(0,3,1) |
| 6066 | fu_engine_add_runtime_version (self, "org.freedesktop.gusb", g_usb_version_string ()); |
| 6067 | #endif |
Richard Hughes | 34e0dab | 2018-04-20 16:43:00 +0100 | [diff] [blame] | 6068 | |
Richard Hughes | f679e5e | 2019-08-28 15:31:34 +0100 | [diff] [blame] | 6069 | /* optional kernel version */ |
Richard Hughes | fc1e267 | 2019-11-22 08:53:33 +0000 | [diff] [blame] | 6070 | #ifdef HAVE_UTSNAME_H |
Richard Hughes | f679e5e | 2019-08-28 15:31:34 +0100 | [diff] [blame] | 6071 | memset (&uname_tmp, 0, sizeof(uname_tmp)); |
| 6072 | if (uname (&uname_tmp) >= 0) |
| 6073 | fu_engine_add_runtime_version (self, "org.kernel", uname_tmp.release); |
Richard Hughes | fc1e267 | 2019-11-22 08:53:33 +0000 | [diff] [blame] | 6074 | #endif |
Richard Hughes | f679e5e | 2019-08-28 15:31:34 +0100 | [diff] [blame] | 6075 | |
Richard Hughes | 34e0dab | 2018-04-20 16:43:00 +0100 | [diff] [blame] | 6076 | g_hash_table_insert (self->compile_versions, |
Richard Hughes | 2d37c3f | 2018-08-04 15:18:25 +0100 | [diff] [blame] | 6077 | g_strdup ("com.redhat.fwupdate"), |
| 6078 | g_strdup ("12")); |
| 6079 | g_hash_table_insert (self->compile_versions, |
Richard Hughes | 34e0dab | 2018-04-20 16:43:00 +0100 | [diff] [blame] | 6080 | g_strdup ("org.freedesktop.fwupd"), |
| 6081 | g_strdup (VERSION)); |
| 6082 | g_hash_table_insert (self->compile_versions, |
Richard Hughes | 34e0dab | 2018-04-20 16:43:00 +0100 | [diff] [blame] | 6083 | g_strdup ("org.freedesktop.gusb"), |
| 6084 | g_strdup_printf ("%i.%i.%i", |
| 6085 | G_USB_MAJOR_VERSION, |
| 6086 | G_USB_MINOR_VERSION, |
| 6087 | G_USB_MICRO_VERSION)); |
| 6088 | |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 6089 | } |
| 6090 | |
| 6091 | static void |
| 6092 | fu_engine_finalize (GObject *obj) |
| 6093 | { |
| 6094 | FuEngine *self = FU_ENGINE (obj); |
| 6095 | |
| 6096 | if (self->usb_ctx != NULL) |
| 6097 | g_object_unref (self->usb_ctx); |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 6098 | if (self->silo != NULL) |
| 6099 | g_object_unref (self->silo); |
Richard Hughes | 1665837 | 2019-11-22 09:23:59 +0000 | [diff] [blame] | 6100 | #ifdef HAVE_GUDEV |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 6101 | if (self->gudev_client != NULL) |
| 6102 | g_object_unref (self->gudev_client); |
Richard Hughes | 1665837 | 2019-11-22 09:23:59 +0000 | [diff] [blame] | 6103 | #endif |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 6104 | if (self->coldplug_id != 0) |
| 6105 | g_source_remove (self->coldplug_id); |
| 6106 | |
Richard Hughes | 0917fb6 | 2019-09-21 12:55:37 +0100 | [diff] [blame] | 6107 | g_free (self->host_machine_id); |
Richard Hughes | 196c6c6 | 2020-05-11 19:42:47 +0100 | [diff] [blame] | 6108 | g_free (self->host_security_id); |
Richard Hughes | 75b965d | 2018-11-15 13:51:21 +0000 | [diff] [blame] | 6109 | g_object_unref (self->idle); |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 6110 | g_object_unref (self->config); |
Richard Hughes | d1808aa | 2019-12-10 15:20:30 +0000 | [diff] [blame] | 6111 | g_object_unref (self->remote_list); |
Richard Hughes | 49e5e05 | 2017-09-03 12:15:41 +0100 | [diff] [blame] | 6112 | g_object_unref (self->smbios); |
Richard Hughes | 9c028f0 | 2017-10-28 21:14:28 +0100 | [diff] [blame] | 6113 | g_object_unref (self->quirks); |
Richard Hughes | d7704d4 | 2017-08-08 20:29:09 +0100 | [diff] [blame] | 6114 | g_object_unref (self->hwids); |
Richard Hughes | bc3a4e1 | 2018-01-06 22:41:47 +0000 | [diff] [blame] | 6115 | g_object_unref (self->history); |
Richard Hughes | 0a7e783 | 2017-11-22 11:01:13 +0000 | [diff] [blame] | 6116 | g_object_unref (self->device_list); |
Richard Hughes | d5aab65 | 2020-02-25 12:47:50 +0000 | [diff] [blame] | 6117 | g_object_unref (self->jcat_context); |
Richard Hughes | c02ee4d | 2018-05-22 15:46:03 +0100 | [diff] [blame] | 6118 | g_ptr_array_unref (self->plugin_filter); |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 6119 | g_ptr_array_unref (self->udev_subsystems); |
Richard Hughes | 1665837 | 2019-11-22 09:23:59 +0000 | [diff] [blame] | 6120 | #ifdef HAVE_GUDEV |
Richard Hughes | 5e952ce | 2019-08-26 11:09:46 +0100 | [diff] [blame] | 6121 | g_hash_table_unref (self->udev_changed_ids); |
Richard Hughes | 1665837 | 2019-11-22 09:23:59 +0000 | [diff] [blame] | 6122 | #endif |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 6123 | g_hash_table_unref (self->runtime_versions); |
Richard Hughes | 34e0dab | 2018-04-20 16:43:00 +0100 | [diff] [blame] | 6124 | g_hash_table_unref (self->compile_versions); |
Richard Hughes | 8dd4c1c | 2019-03-03 18:27:57 +0000 | [diff] [blame] | 6125 | g_hash_table_unref (self->approved_firmware); |
Richard Hughes | 95c98a9 | 2019-10-22 16:03:15 +0100 | [diff] [blame] | 6126 | g_hash_table_unref (self->firmware_gtypes); |
Mario Limonciello | 3f9a1c1 | 2018-06-06 14:06:40 -0500 | [diff] [blame] | 6127 | g_object_unref (self->plugin_list); |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 6128 | |
| 6129 | G_OBJECT_CLASS (fu_engine_parent_class)->finalize (obj); |
| 6130 | } |
| 6131 | |
| 6132 | FuEngine * |
Richard Hughes | 5b5f655 | 2018-05-18 10:22:39 +0100 | [diff] [blame] | 6133 | fu_engine_new (FuAppFlags app_flags) |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 6134 | { |
| 6135 | FuEngine *self; |
| 6136 | self = g_object_new (FU_TYPE_ENGINE, NULL); |
Richard Hughes | 5b5f655 | 2018-05-18 10:22:39 +0100 | [diff] [blame] | 6137 | self->app_flags = app_flags; |
Richard Hughes | 9945edb | 2017-06-19 10:03:55 +0100 | [diff] [blame] | 6138 | return FU_ENGINE (self); |
| 6139 | } |