blob: e18d3534cbea85db877a5f26085144ea0631b319 [file] [log] [blame]
Richard Hughes02c90d82018-08-09 12:13:03 +01001/*
Richard Hughes2de8f132018-01-17 09:12:02 +00002 * Copyright (C) 2016-2018 Richard Hughes <richard@hughsie.com>
Richard Hughesd0905142016-03-13 09:46:49 +00003 *
Mario Limonciello51308e62018-05-28 20:05:46 -05004 * SPDX-License-Identifier: LGPL-2.1+
Richard Hughesd0905142016-03-13 09:46:49 +00005 */
6
Richard Hughesb08e7bc2018-09-11 10:51:13 +01007#define G_LOG_DOMAIN "FuPlugin"
8
Richard Hughesd0905142016-03-13 09:46:49 +00009#include "config.h"
10
Richard Hughescff38bc2016-12-12 12:03:37 +000011#include <fwupd.h>
12#include <gmodule.h>
Richard Hughescff38bc2016-12-12 12:03:37 +000013#include <errno.h>
14#include <string.h>
Richard Hughes68f12dd2018-08-09 14:43:31 +010015#include <unistd.h>
Richard Hughescff38bc2016-12-12 12:03:37 +000016#include <gio/gunixinputstream.h>
Mario Limonciello6d0aa3d2017-02-28 08:22:27 -060017#ifdef HAVE_VALGRIND
Richard Hughes576c0122017-02-24 09:47:00 +000018#include <valgrind.h>
Mario Limonciello6d0aa3d2017-02-28 08:22:27 -060019#endif /* HAVE_VALGRIND */
Richard Hughesd0905142016-03-13 09:46:49 +000020
Richard Hughes9dde04f2017-09-13 12:07:15 +010021#include "fu-device-private.h"
Richard Hughescff38bc2016-12-12 12:03:37 +000022#include "fu-plugin-private.h"
Richard Hughesbc3a4e12018-01-06 22:41:47 +000023#include "fu-history.h"
Richard Hughes37d09432018-09-09 10:39:45 +010024#include "fu-mutex.h"
Richard Hughesd0905142016-03-13 09:46:49 +000025
Richard Hughes4eada342017-10-03 21:20:32 +010026/**
27 * SECTION:fu-plugin
28 * @short_description: a daemon plugin
29 *
30 * An object that represents a plugin run by the daemon.
31 *
32 * See also: #FuDevice
33 */
34
Richard Hughesb0829032017-01-10 09:27:08 +000035#define FU_PLUGIN_COLDPLUG_DELAY_MAXIMUM 3000u /* ms */
36
Richard Hughescff38bc2016-12-12 12:03:37 +000037static void fu_plugin_finalize (GObject *object);
38
39typedef struct {
40 GModule *module;
41 GUsbContext *usb_ctx;
42 gboolean enabled;
Richard Hughes08a37992017-09-12 12:57:43 +010043 guint order;
Richard Hughes81c427c2018-08-06 15:20:17 +010044 guint priority;
Richard Hughes08a37992017-09-12 12:57:43 +010045 GPtrArray *rules[FU_PLUGIN_RULE_LAST];
Richard Hughescff38bc2016-12-12 12:03:37 +000046 gchar *name;
Richard Hughesf425d292019-01-18 17:57:39 +000047 gchar *build_hash;
Richard Hughesd7704d42017-08-08 20:29:09 +010048 FuHwids *hwids;
Richard Hughes9c028f02017-10-28 21:14:28 +010049 FuQuirks *quirks;
Richard Hughes0eb123b2018-04-19 12:00:04 +010050 GHashTable *runtime_versions;
Richard Hughes34e0dab2018-04-20 16:43:00 +010051 GHashTable *compile_versions;
Richard Hughes9d6e0e72018-08-24 20:20:17 +010052 GPtrArray *udev_subsystems;
Richard Hughes1354ea92017-09-19 15:58:31 +010053 FuSmbios *smbios;
Richard Hughescff38bc2016-12-12 12:03:37 +000054 GHashTable *devices; /* platform_id:GObject */
Richard Hughes37d09432018-09-09 10:39:45 +010055 FuMutex *devices_mutex;
Richard Hughes80b79bb2018-01-11 21:11:06 +000056 GHashTable *report_metadata; /* key:value */
Richard Hughescff38bc2016-12-12 12:03:37 +000057 FuPluginData *data;
58} FuPluginPrivate;
59
60enum {
61 SIGNAL_DEVICE_ADDED,
62 SIGNAL_DEVICE_REMOVED,
Richard Hughese1fd34d2017-08-24 14:19:51 +010063 SIGNAL_DEVICE_REGISTER,
Richard Hughes75b965d2018-11-15 13:51:21 +000064 SIGNAL_RULES_CHANGED,
Richard Hughes362d6d72017-01-07 21:42:14 +000065 SIGNAL_RECOLDPLUG,
Richard Hughesb0829032017-01-10 09:27:08 +000066 SIGNAL_SET_COLDPLUG_DELAY,
Richard Hughesaabdc372018-11-14 10:11:08 +000067 SIGNAL_CHECK_SUPPORTED,
Richard Hughescff38bc2016-12-12 12:03:37 +000068 SIGNAL_LAST
69};
70
71static guint signals[SIGNAL_LAST] = { 0 };
72
73G_DEFINE_TYPE_WITH_PRIVATE (FuPlugin, fu_plugin, G_TYPE_OBJECT)
74#define GET_PRIVATE(o) (fu_plugin_get_instance_private (o))
75
76typedef const gchar *(*FuPluginGetNameFunc) (void);
Richard Hughes12724852018-09-04 13:53:44 +010077typedef void (*FuPluginInitFunc) (FuPlugin *self);
78typedef gboolean (*FuPluginStartupFunc) (FuPlugin *self,
Richard Hughescff38bc2016-12-12 12:03:37 +000079 GError **error);
Richard Hughes12724852018-09-04 13:53:44 +010080typedef void (*FuPluginDeviceRegisterFunc) (FuPlugin *self,
Richard Hughese1fd34d2017-08-24 14:19:51 +010081 FuDevice *device);
Richard Hughes12724852018-09-04 13:53:44 +010082typedef gboolean (*FuPluginDeviceFunc) (FuPlugin *self,
Richard Hughescff38bc2016-12-12 12:03:37 +000083 FuDevice *device,
84 GError **error);
Richard Hughes12724852018-09-04 13:53:44 +010085typedef gboolean (*FuPluginFlaggedDeviceFunc) (FuPlugin *self,
Mario Limoncielloe3b1a3f2018-08-21 13:01:45 -050086 FwupdInstallFlags flags,
87 FuDevice *device,
88 GError **error);
Richard Hughes12724852018-09-04 13:53:44 +010089typedef gboolean (*FuPluginDeviceArrayFunc) (FuPlugin *self,
Richard Hughesdbd8c762018-06-15 20:31:40 +010090 GPtrArray *devices,
91 GError **error);
Richard Hughes12724852018-09-04 13:53:44 +010092typedef gboolean (*FuPluginVerifyFunc) (FuPlugin *self,
Richard Hughescff38bc2016-12-12 12:03:37 +000093 FuDevice *device,
94 FuPluginVerifyFlags flags,
95 GError **error);
Richard Hughes12724852018-09-04 13:53:44 +010096typedef gboolean (*FuPluginUpdateFunc) (FuPlugin *self,
Richard Hughescff38bc2016-12-12 12:03:37 +000097 FuDevice *device,
98 GBytes *blob_fw,
99 FwupdInstallFlags flags,
100 GError **error);
Richard Hughes12724852018-09-04 13:53:44 +0100101typedef gboolean (*FuPluginUsbDeviceAddedFunc) (FuPlugin *self,
Richard Hughesff704412018-09-04 11:28:32 +0100102 FuUsbDevice *device,
Richard Hughes104f6512017-11-24 11:44:57 +0000103 GError **error);
Richard Hughes12724852018-09-04 13:53:44 +0100104typedef gboolean (*FuPluginUdevDeviceAddedFunc) (FuPlugin *self,
Richard Hughesff704412018-09-04 11:28:32 +0100105 FuUdevDevice *device,
Richard Hughes9d6e0e72018-08-24 20:20:17 +0100106 GError **error);
Richard Hughescff38bc2016-12-12 12:03:37 +0000107
Richard Hughes57d18222017-01-10 16:02:59 +0000108/**
109 * fu_plugin_get_name:
Richard Hughes2c0635a2018-09-04 14:52:46 +0100110 * @self: A #FuPlugin
Richard Hughes57d18222017-01-10 16:02:59 +0000111 *
112 * Gets the plugin name.
113 *
114 * Returns: a plugin name, or %NULL for unknown.
115 *
116 * Since: 0.8.0
117 **/
Richard Hughescff38bc2016-12-12 12:03:37 +0000118const gchar *
Richard Hughes12724852018-09-04 13:53:44 +0100119fu_plugin_get_name (FuPlugin *self)
Richard Hughesd0905142016-03-13 09:46:49 +0000120{
Richard Hughes12724852018-09-04 13:53:44 +0100121 FuPluginPrivate *priv = GET_PRIVATE (self);
122 g_return_val_if_fail (FU_IS_PLUGIN (self), NULL);
Richard Hughescff38bc2016-12-12 12:03:37 +0000123 return priv->name;
124}
Richard Hughesd0905142016-03-13 09:46:49 +0000125
Richard Hughes34834102017-11-21 21:55:00 +0000126void
Richard Hughes12724852018-09-04 13:53:44 +0100127fu_plugin_set_name (FuPlugin *self, const gchar *name)
Richard Hughes34834102017-11-21 21:55:00 +0000128{
Richard Hughes12724852018-09-04 13:53:44 +0100129 FuPluginPrivate *priv = GET_PRIVATE (self);
130 g_return_if_fail (FU_IS_PLUGIN (self));
Richard Hughes34834102017-11-21 21:55:00 +0000131 g_return_if_fail (name != NULL);
132 g_free (priv->name);
133 priv->name = g_strdup (name);
134}
135
Richard Hughes57d18222017-01-10 16:02:59 +0000136/**
Richard Hughesf425d292019-01-18 17:57:39 +0000137 * fu_plugin_set_build_hash:
138 * @self: A #FuPlugin
139 * @build_hash: A checksum
140 *
141 * Sets the plugin build hash, typically a SHA256 checksum. All plugins must
142 * set the correct checksum to avoid the daemon being marked as tainted.
143 *
144 * Since: 1.2.4
145 **/
146void
147fu_plugin_set_build_hash (FuPlugin *self, const gchar *build_hash)
148{
149 FuPluginPrivate *priv = GET_PRIVATE (self);
150 g_return_if_fail (FU_IS_PLUGIN (self));
151 g_return_if_fail (build_hash != NULL);
152 g_free (priv->build_hash);
153 priv->build_hash = g_strdup (build_hash);
154}
155
156const gchar *
157fu_plugin_get_build_hash (FuPlugin *self)
158{
159 FuPluginPrivate *priv = GET_PRIVATE (self);
160 g_return_val_if_fail (FU_IS_PLUGIN (self), NULL);
161 return priv->build_hash;
162}
163
164/**
Richard Hughes57d18222017-01-10 16:02:59 +0000165 * fu_plugin_cache_lookup:
Richard Hughes2c0635a2018-09-04 14:52:46 +0100166 * @self: A #FuPlugin
Richard Hughes57d18222017-01-10 16:02:59 +0000167 * @id: the key
168 *
169 * Finds an object in the per-plugin cache.
170 *
171 * Returns: (transfer none): a #GObject, or %NULL for unfound.
172 *
173 * Since: 0.8.0
174 **/
Richard Hughescff38bc2016-12-12 12:03:37 +0000175gpointer
Richard Hughes12724852018-09-04 13:53:44 +0100176fu_plugin_cache_lookup (FuPlugin *self, const gchar *id)
Richard Hughescff38bc2016-12-12 12:03:37 +0000177{
Richard Hughes12724852018-09-04 13:53:44 +0100178 FuPluginPrivate *priv = GET_PRIVATE (self);
Richard Hughes37d09432018-09-09 10:39:45 +0100179 g_autoptr(FuMutexLocker) locker = fu_mutex_read_locker_new (priv->devices_mutex);
Richard Hughes12724852018-09-04 13:53:44 +0100180 g_return_val_if_fail (FU_IS_PLUGIN (self), NULL);
Richard Hughesccd78a92017-01-11 16:57:41 +0000181 g_return_val_if_fail (id != NULL, NULL);
Richard Hughes37d09432018-09-09 10:39:45 +0100182 g_return_val_if_fail (locker != NULL, NULL);
Richard Hughescff38bc2016-12-12 12:03:37 +0000183 return g_hash_table_lookup (priv->devices, id);
184}
Richard Hughesd0905142016-03-13 09:46:49 +0000185
Richard Hughes57d18222017-01-10 16:02:59 +0000186/**
187 * fu_plugin_cache_add:
Richard Hughes2c0635a2018-09-04 14:52:46 +0100188 * @self: A #FuPlugin
Richard Hughes57d18222017-01-10 16:02:59 +0000189 * @id: the key
190 * @dev: a #GObject, typically a #FuDevice
191 *
192 * Adds an object to the per-plugin cache.
193 *
194 * Since: 0.8.0
195 **/
Richard Hughescff38bc2016-12-12 12:03:37 +0000196void
Richard Hughes12724852018-09-04 13:53:44 +0100197fu_plugin_cache_add (FuPlugin *self, const gchar *id, gpointer dev)
Richard Hughescff38bc2016-12-12 12:03:37 +0000198{
Richard Hughes12724852018-09-04 13:53:44 +0100199 FuPluginPrivate *priv = GET_PRIVATE (self);
Richard Hughes37d09432018-09-09 10:39:45 +0100200 g_autoptr(FuMutexLocker) locker = fu_mutex_write_locker_new (priv->devices_mutex);
Richard Hughes12724852018-09-04 13:53:44 +0100201 g_return_if_fail (FU_IS_PLUGIN (self));
Richard Hughesccd78a92017-01-11 16:57:41 +0000202 g_return_if_fail (id != NULL);
Richard Hughes37d09432018-09-09 10:39:45 +0100203 g_return_if_fail (locker != NULL);
Richard Hughescff38bc2016-12-12 12:03:37 +0000204 g_hash_table_insert (priv->devices, g_strdup (id), g_object_ref (dev));
205}
206
Richard Hughes57d18222017-01-10 16:02:59 +0000207/**
208 * fu_plugin_cache_remove:
Richard Hughes2c0635a2018-09-04 14:52:46 +0100209 * @self: A #FuPlugin
Richard Hughes57d18222017-01-10 16:02:59 +0000210 * @id: the key
211 *
212 * Removes an object from the per-plugin cache.
213 *
214 * Since: 0.8.0
215 **/
Richard Hughescff38bc2016-12-12 12:03:37 +0000216void
Richard Hughes12724852018-09-04 13:53:44 +0100217fu_plugin_cache_remove (FuPlugin *self, const gchar *id)
Richard Hughescff38bc2016-12-12 12:03:37 +0000218{
Richard Hughes12724852018-09-04 13:53:44 +0100219 FuPluginPrivate *priv = GET_PRIVATE (self);
Richard Hughes37d09432018-09-09 10:39:45 +0100220 g_autoptr(FuMutexLocker) locker = fu_mutex_write_locker_new (priv->devices_mutex);
Richard Hughes12724852018-09-04 13:53:44 +0100221 g_return_if_fail (FU_IS_PLUGIN (self));
Richard Hughesccd78a92017-01-11 16:57:41 +0000222 g_return_if_fail (id != NULL);
Richard Hughes37d09432018-09-09 10:39:45 +0100223 g_return_if_fail (locker != NULL);
Richard Hughescff38bc2016-12-12 12:03:37 +0000224 g_hash_table_remove (priv->devices, id);
225}
226
Richard Hughes57d18222017-01-10 16:02:59 +0000227/**
228 * fu_plugin_get_data:
Richard Hughes2c0635a2018-09-04 14:52:46 +0100229 * @self: A #FuPlugin
Richard Hughes57d18222017-01-10 16:02:59 +0000230 *
Richard Hughes4eada342017-10-03 21:20:32 +0100231 * Gets the per-plugin allocated private data. This will return %NULL unless
232 * fu_plugin_alloc_data() has been called by the plugin.
Richard Hughes57d18222017-01-10 16:02:59 +0000233 *
Richard Hughes4eada342017-10-03 21:20:32 +0100234 * Returns: (transfer none): a pointer to a structure, or %NULL for unset.
Richard Hughes57d18222017-01-10 16:02:59 +0000235 *
236 * Since: 0.8.0
237 **/
Richard Hughescff38bc2016-12-12 12:03:37 +0000238FuPluginData *
Richard Hughes12724852018-09-04 13:53:44 +0100239fu_plugin_get_data (FuPlugin *self)
Richard Hughescff38bc2016-12-12 12:03:37 +0000240{
Richard Hughes12724852018-09-04 13:53:44 +0100241 FuPluginPrivate *priv = GET_PRIVATE (self);
242 g_return_val_if_fail (FU_IS_PLUGIN (self), NULL);
Richard Hughescff38bc2016-12-12 12:03:37 +0000243 return priv->data;
244}
245
Richard Hughes57d18222017-01-10 16:02:59 +0000246/**
247 * fu_plugin_alloc_data:
Richard Hughes2c0635a2018-09-04 14:52:46 +0100248 * @self: A #FuPlugin
Richard Hughes57d18222017-01-10 16:02:59 +0000249 * @data_sz: the size to allocate
250 *
251 * Allocates the per-plugin allocated private data.
252 *
253 * Returns: (transfer full): a pointer to a structure, or %NULL for unset.
254 *
255 * Since: 0.8.0
256 **/
Richard Hughescff38bc2016-12-12 12:03:37 +0000257FuPluginData *
Richard Hughes12724852018-09-04 13:53:44 +0100258fu_plugin_alloc_data (FuPlugin *self, gsize data_sz)
Richard Hughescff38bc2016-12-12 12:03:37 +0000259{
Richard Hughes12724852018-09-04 13:53:44 +0100260 FuPluginPrivate *priv = GET_PRIVATE (self);
261 g_return_val_if_fail (FU_IS_PLUGIN (self), NULL);
Richard Hughes44dee882017-01-11 08:31:10 +0000262 if (priv->data != NULL) {
263 g_critical ("fu_plugin_alloc_data() already used by plugin");
264 return priv->data;
265 }
Richard Hughescff38bc2016-12-12 12:03:37 +0000266 priv->data = g_malloc0 (data_sz);
267 return priv->data;
Richard Hughesd0905142016-03-13 09:46:49 +0000268}
269
Richard Hughes57d18222017-01-10 16:02:59 +0000270/**
271 * fu_plugin_get_usb_context:
Richard Hughes2c0635a2018-09-04 14:52:46 +0100272 * @self: A #FuPlugin
Richard Hughes57d18222017-01-10 16:02:59 +0000273 *
274 * Gets the shared USB context that all plugins can use.
275 *
276 * Returns: (transfer none): a #GUsbContext.
277 *
278 * Since: 0.8.0
279 **/
Richard Hughesbc93e4a2016-12-08 17:29:51 +0000280GUsbContext *
Richard Hughes12724852018-09-04 13:53:44 +0100281fu_plugin_get_usb_context (FuPlugin *self)
Richard Hughesbc93e4a2016-12-08 17:29:51 +0000282{
Richard Hughes12724852018-09-04 13:53:44 +0100283 FuPluginPrivate *priv = GET_PRIVATE (self);
284 g_return_val_if_fail (FU_IS_PLUGIN (self), NULL);
Richard Hughescff38bc2016-12-12 12:03:37 +0000285 return priv->usb_ctx;
Richard Hughesbc93e4a2016-12-08 17:29:51 +0000286}
287
288void
Richard Hughes12724852018-09-04 13:53:44 +0100289fu_plugin_set_usb_context (FuPlugin *self, GUsbContext *usb_ctx)
Richard Hughesbc93e4a2016-12-08 17:29:51 +0000290{
Richard Hughes12724852018-09-04 13:53:44 +0100291 FuPluginPrivate *priv = GET_PRIVATE (self);
Richard Hughescff38bc2016-12-12 12:03:37 +0000292 g_set_object (&priv->usb_ctx, usb_ctx);
293}
294
Richard Hughes57d18222017-01-10 16:02:59 +0000295/**
296 * fu_plugin_get_enabled:
Richard Hughes2c0635a2018-09-04 14:52:46 +0100297 * @self: A #FuPlugin
Richard Hughes57d18222017-01-10 16:02:59 +0000298 *
Richard Hughes4eada342017-10-03 21:20:32 +0100299 * Returns if the plugin is enabled. Plugins may self-disable using
300 * fu_plugin_set_enabled() or can be disabled by the daemon.
Richard Hughes57d18222017-01-10 16:02:59 +0000301 *
302 * Returns: %TRUE if the plugin is currently enabled.
303 *
304 * Since: 0.8.0
305 **/
Richard Hughescff38bc2016-12-12 12:03:37 +0000306gboolean
Richard Hughes12724852018-09-04 13:53:44 +0100307fu_plugin_get_enabled (FuPlugin *self)
Richard Hughescff38bc2016-12-12 12:03:37 +0000308{
Richard Hughes12724852018-09-04 13:53:44 +0100309 FuPluginPrivate *priv = GET_PRIVATE (self);
310 g_return_val_if_fail (FU_IS_PLUGIN (self), FALSE);
Richard Hughescff38bc2016-12-12 12:03:37 +0000311 return priv->enabled;
Richard Hughesbc93e4a2016-12-08 17:29:51 +0000312}
313
Richard Hughes57d18222017-01-10 16:02:59 +0000314/**
315 * fu_plugin_set_enabled:
Richard Hughes2c0635a2018-09-04 14:52:46 +0100316 * @self: A #FuPlugin
Richard Hughes57d18222017-01-10 16:02:59 +0000317 * @enabled: the enabled value
318 *
319 * Enables or disables a plugin. Plugins can self-disable at any point.
320 *
321 * Since: 0.8.0
322 **/
Richard Hughesd0905142016-03-13 09:46:49 +0000323void
Richard Hughes12724852018-09-04 13:53:44 +0100324fu_plugin_set_enabled (FuPlugin *self, gboolean enabled)
Richard Hughesd0905142016-03-13 09:46:49 +0000325{
Richard Hughes12724852018-09-04 13:53:44 +0100326 FuPluginPrivate *priv = GET_PRIVATE (self);
327 g_return_if_fail (FU_IS_PLUGIN (self));
Richard Hughescff38bc2016-12-12 12:03:37 +0000328 priv->enabled = enabled;
329}
330
Richard Hughes1e456bc2018-05-10 20:16:16 +0100331gchar *
332fu_plugin_guess_name_from_fn (const gchar *filename)
333{
334 const gchar *prefix = "libfu_plugin_";
335 gchar *name;
336 gchar *str = g_strstr_len (filename, -1, prefix);
337 if (str == NULL)
338 return NULL;
339 name = g_strdup (str + strlen (prefix));
340 g_strdelimit (name, ".", '\0');
341 return name;
342}
343
Richard Hughescff38bc2016-12-12 12:03:37 +0000344gboolean
Richard Hughes12724852018-09-04 13:53:44 +0100345fu_plugin_open (FuPlugin *self, const gchar *filename, GError **error)
Richard Hughescff38bc2016-12-12 12:03:37 +0000346{
Richard Hughes12724852018-09-04 13:53:44 +0100347 FuPluginPrivate *priv = GET_PRIVATE (self);
Richard Hughescff38bc2016-12-12 12:03:37 +0000348 FuPluginInitFunc func = NULL;
Richard Hughescff38bc2016-12-12 12:03:37 +0000349
350 priv->module = g_module_open (filename, 0);
351 if (priv->module == NULL) {
352 g_set_error (error,
353 G_IO_ERROR,
354 G_IO_ERROR_FAILED,
355 "failed to open plugin: %s",
356 g_module_error ());
357 return FALSE;
358 }
359
360 /* set automatically */
Richard Hughes1e456bc2018-05-10 20:16:16 +0100361 if (priv->name == NULL)
362 priv->name = fu_plugin_guess_name_from_fn (filename);
Richard Hughesd0905142016-03-13 09:46:49 +0000363
364 /* optional */
Richard Hughescff38bc2016-12-12 12:03:37 +0000365 g_module_symbol (priv->module, "fu_plugin_init", (gpointer *) &func);
366 if (func != NULL) {
367 g_debug ("performing init() on %s", filename);
Richard Hughes12724852018-09-04 13:53:44 +0100368 func (self);
Richard Hughesd0905142016-03-13 09:46:49 +0000369 }
370
Richard Hughescff38bc2016-12-12 12:03:37 +0000371 return TRUE;
372}
373
Richard Hughes57d18222017-01-10 16:02:59 +0000374/**
375 * fu_plugin_device_add:
Richard Hughes2c0635a2018-09-04 14:52:46 +0100376 * @self: A #FuPlugin
Richard Hughes57d18222017-01-10 16:02:59 +0000377 * @device: A #FuDevice
378 *
379 * Asks the daemon to add a device to the exported list. If this device ID
380 * has already been added by a different plugin then this request will be
381 * ignored.
382 *
383 * Plugins should use fu_plugin_device_add_delay() if they are not capable of
384 * actually flashing an image to the hardware so that higher-priority plugins
385 * can add the device themselves.
386 *
387 * Since: 0.8.0
388 **/
Richard Hughescff38bc2016-12-12 12:03:37 +0000389void
Richard Hughes12724852018-09-04 13:53:44 +0100390fu_plugin_device_add (FuPlugin *self, FuDevice *device)
Richard Hughescff38bc2016-12-12 12:03:37 +0000391{
Richard Hughes5e447292018-04-27 14:25:54 +0100392 GPtrArray *children;
Richard Hughesc125ec02018-09-05 19:35:17 +0100393 g_autoptr(GError) error = NULL;
Richard Hughes5e447292018-04-27 14:25:54 +0100394
Richard Hughes12724852018-09-04 13:53:44 +0100395 g_return_if_fail (FU_IS_PLUGIN (self));
Richard Hughesccd78a92017-01-11 16:57:41 +0000396 g_return_if_fail (FU_IS_DEVICE (device));
397
Richard Hughesc125ec02018-09-05 19:35:17 +0100398 /* ensure the device ID is set from the physical and logical IDs */
399 if (!fu_device_ensure_id (device, &error)) {
400 g_warning ("ignoring add: %s", error->message);
401 return;
402 }
403
Richard Hughescff38bc2016-12-12 12:03:37 +0000404 g_debug ("emit added from %s: %s",
Richard Hughes12724852018-09-04 13:53:44 +0100405 fu_plugin_get_name (self),
Richard Hughescff38bc2016-12-12 12:03:37 +0000406 fu_device_get_id (device));
407 fu_device_set_created (device, (guint64) g_get_real_time () / G_USEC_PER_SEC);
Richard Hughes12724852018-09-04 13:53:44 +0100408 fu_device_set_plugin (device, fu_plugin_get_name (self));
409 g_signal_emit (self, signals[SIGNAL_DEVICE_ADDED], 0, device);
Richard Hughes5e447292018-04-27 14:25:54 +0100410
Richard Hughes128c0162018-08-10 11:00:29 +0100411 /* add children if they have not already been added */
Richard Hughes5e447292018-04-27 14:25:54 +0100412 children = fu_device_get_children (device);
413 for (guint i = 0; i < children->len; i++) {
414 FuDevice *child = g_ptr_array_index (children, i);
Richard Hughes128c0162018-08-10 11:00:29 +0100415 if (fu_device_get_created (child) == 0)
Richard Hughes12724852018-09-04 13:53:44 +0100416 fu_plugin_device_add (self, child);
Richard Hughes5e447292018-04-27 14:25:54 +0100417 }
Richard Hughescff38bc2016-12-12 12:03:37 +0000418}
419
Richard Hughese1fd34d2017-08-24 14:19:51 +0100420/**
421 * fu_plugin_device_register:
Richard Hughes2c0635a2018-09-04 14:52:46 +0100422 * @self: A #FuPlugin
Richard Hughese1fd34d2017-08-24 14:19:51 +0100423 * @device: A #FuDevice
424 *
425 * Registers the device with other plugins so they can set metadata.
426 *
427 * Plugins do not have to call this manually as this is done automatically
428 * when using fu_plugin_device_add(). They may wish to use this manually
429 * if for intance the coldplug should be ignored based on the metadata
430 * set from other plugins.
431 *
432 * Since: 0.9.7
433 **/
434void
Richard Hughes12724852018-09-04 13:53:44 +0100435fu_plugin_device_register (FuPlugin *self, FuDevice *device)
Richard Hughese1fd34d2017-08-24 14:19:51 +0100436{
Richard Hughesc125ec02018-09-05 19:35:17 +0100437 g_autoptr(GError) error = NULL;
438
Richard Hughes12724852018-09-04 13:53:44 +0100439 g_return_if_fail (FU_IS_PLUGIN (self));
Richard Hughese1fd34d2017-08-24 14:19:51 +0100440 g_return_if_fail (FU_IS_DEVICE (device));
441
Richard Hughesc125ec02018-09-05 19:35:17 +0100442 /* ensure the device ID is set from the physical and logical IDs */
443 if (!fu_device_ensure_id (device, &error)) {
444 g_warning ("ignoring registration: %s", error->message);
445 return;
446 }
447
Richard Hughese1fd34d2017-08-24 14:19:51 +0100448 g_debug ("emit device-register from %s: %s",
Richard Hughes12724852018-09-04 13:53:44 +0100449 fu_plugin_get_name (self),
Richard Hughese1fd34d2017-08-24 14:19:51 +0100450 fu_device_get_id (device));
Richard Hughes12724852018-09-04 13:53:44 +0100451 g_signal_emit (self, signals[SIGNAL_DEVICE_REGISTER], 0, device);
Richard Hughese1fd34d2017-08-24 14:19:51 +0100452}
453
Richard Hughes57d18222017-01-10 16:02:59 +0000454/**
Richard Hughes4eada342017-10-03 21:20:32 +0100455 * fu_plugin_device_remove:
Richard Hughes2c0635a2018-09-04 14:52:46 +0100456 * @self: A #FuPlugin
Richard Hughes57d18222017-01-10 16:02:59 +0000457 * @device: A #FuDevice
458 *
459 * Asks the daemon to remove a device from the exported list.
460 *
461 * Since: 0.8.0
462 **/
Richard Hughescff38bc2016-12-12 12:03:37 +0000463void
Richard Hughes12724852018-09-04 13:53:44 +0100464fu_plugin_device_remove (FuPlugin *self, FuDevice *device)
Richard Hughescff38bc2016-12-12 12:03:37 +0000465{
Richard Hughes12724852018-09-04 13:53:44 +0100466 g_return_if_fail (FU_IS_PLUGIN (self));
Richard Hughesccd78a92017-01-11 16:57:41 +0000467 g_return_if_fail (FU_IS_DEVICE (device));
468
Richard Hughescff38bc2016-12-12 12:03:37 +0000469 g_debug ("emit removed from %s: %s",
Richard Hughes12724852018-09-04 13:53:44 +0100470 fu_plugin_get_name (self),
Richard Hughescff38bc2016-12-12 12:03:37 +0000471 fu_device_get_id (device));
Richard Hughes12724852018-09-04 13:53:44 +0100472 g_signal_emit (self, signals[SIGNAL_DEVICE_REMOVED], 0, device);
Richard Hughescff38bc2016-12-12 12:03:37 +0000473}
474
Richard Hughes57d18222017-01-10 16:02:59 +0000475/**
Richard Hughes2de8f132018-01-17 09:12:02 +0000476 * fu_plugin_request_recoldplug:
Richard Hughes2c0635a2018-09-04 14:52:46 +0100477 * @self: A #FuPlugin
Richard Hughes362d6d72017-01-07 21:42:14 +0000478 *
479 * Ask all the plugins to coldplug all devices, which will include the prepare()
480 * and cleanup() phases. Duplicate devices added will be ignored.
481 *
482 * Since: 0.8.0
483 **/
484void
Richard Hughes12724852018-09-04 13:53:44 +0100485fu_plugin_request_recoldplug (FuPlugin *self)
Richard Hughes362d6d72017-01-07 21:42:14 +0000486{
Richard Hughes12724852018-09-04 13:53:44 +0100487 g_return_if_fail (FU_IS_PLUGIN (self));
488 g_signal_emit (self, signals[SIGNAL_RECOLDPLUG], 0);
Richard Hughes362d6d72017-01-07 21:42:14 +0000489}
490
Richard Hughesb0829032017-01-10 09:27:08 +0000491/**
Richard Hughesb8f8db22017-04-25 15:56:00 +0100492 * fu_plugin_check_hwid:
Richard Hughes2c0635a2018-09-04 14:52:46 +0100493 * @self: A #FuPlugin
Richard Hughes4eada342017-10-03 21:20:32 +0100494 * @hwid: A Hardware ID GUID, e.g. `6de5d951-d755-576b-bd09-c5cf66b27234`
Richard Hughesb8f8db22017-04-25 15:56:00 +0100495 *
Richard Hughesd7704d42017-08-08 20:29:09 +0100496 * Checks to see if a specific GUID exists. All hardware IDs on a
Richard Hughesb8f8db22017-04-25 15:56:00 +0100497 * specific system can be shown using the `fwupdmgr hwids` command.
498 *
Richard Hughes4eada342017-10-03 21:20:32 +0100499 * Returns: %TRUE if the HwId is found on the system.
500 *
Richard Hughesb8f8db22017-04-25 15:56:00 +0100501 * Since: 0.9.1
502 **/
503gboolean
Richard Hughes12724852018-09-04 13:53:44 +0100504fu_plugin_check_hwid (FuPlugin *self, const gchar *hwid)
Richard Hughesb8f8db22017-04-25 15:56:00 +0100505{
Richard Hughes12724852018-09-04 13:53:44 +0100506 FuPluginPrivate *priv = GET_PRIVATE (self);
Richard Hughesb8f8db22017-04-25 15:56:00 +0100507 if (priv->hwids == NULL)
508 return FALSE;
Richard Hughesd7704d42017-08-08 20:29:09 +0100509 return fu_hwids_has_guid (priv->hwids, hwid);
510}
511
512/**
Richard Hughes69a5f352018-08-08 11:58:15 +0100513 * fu_plugin_get_hwids:
Richard Hughes2c0635a2018-09-04 14:52:46 +0100514 * @self: A #FuPlugin
Richard Hughes69a5f352018-08-08 11:58:15 +0100515 *
516 * Returns all the HWIDs defined in the system. All hardware IDs on a
517 * specific system can be shown using the `fwupdmgr hwids` command.
518 *
519 * Returns: (transfer none) (element-type utf-8): An array of GUIDs
520 *
521 * Since: 1.1.1
522 **/
523GPtrArray *
Richard Hughes12724852018-09-04 13:53:44 +0100524fu_plugin_get_hwids (FuPlugin *self)
Richard Hughes69a5f352018-08-08 11:58:15 +0100525{
Richard Hughes12724852018-09-04 13:53:44 +0100526 FuPluginPrivate *priv = GET_PRIVATE (self);
Richard Hughes69a5f352018-08-08 11:58:15 +0100527 if (priv->hwids == NULL)
528 return NULL;
529 return fu_hwids_get_guids (priv->hwids);
530}
531
532/**
Richard Hughes1354ea92017-09-19 15:58:31 +0100533 * fu_plugin_check_supported:
Richard Hughes2c0635a2018-09-04 14:52:46 +0100534 * @self: A #FuPlugin
Richard Hughes4eada342017-10-03 21:20:32 +0100535 * @guid: A Hardware ID GUID, e.g. `6de5d951-d755-576b-bd09-c5cf66b27234`
Richard Hughes1354ea92017-09-19 15:58:31 +0100536 *
537 * Checks to see if a specific device GUID is supported, i.e. available in the
538 * AppStream metadata.
539 *
Richard Hughes4eada342017-10-03 21:20:32 +0100540 * Returns: %TRUE if the device is supported.
541 *
Richard Hughes1354ea92017-09-19 15:58:31 +0100542 * Since: 1.0.0
543 **/
544gboolean
Richard Hughes12724852018-09-04 13:53:44 +0100545fu_plugin_check_supported (FuPlugin *self, const gchar *guid)
Richard Hughes1354ea92017-09-19 15:58:31 +0100546{
Richard Hughesaabdc372018-11-14 10:11:08 +0000547 gboolean retval = FALSE;
548 g_signal_emit (self, signals[SIGNAL_CHECK_SUPPORTED], 0, guid, &retval);
549 return retval;
Richard Hughes1354ea92017-09-19 15:58:31 +0100550}
551
552/**
Richard Hughesd7704d42017-08-08 20:29:09 +0100553 * fu_plugin_get_dmi_value:
Richard Hughes2c0635a2018-09-04 14:52:46 +0100554 * @self: A #FuPlugin
Richard Hughes4eada342017-10-03 21:20:32 +0100555 * @dmi_id: A DMI ID, e.g. `BiosVersion`
Richard Hughesd7704d42017-08-08 20:29:09 +0100556 *
557 * Gets a hardware DMI value.
558 *
Richard Hughes4eada342017-10-03 21:20:32 +0100559 * Returns: The string, or %NULL
560 *
Richard Hughesd7704d42017-08-08 20:29:09 +0100561 * Since: 0.9.7
562 **/
563const gchar *
Richard Hughes12724852018-09-04 13:53:44 +0100564fu_plugin_get_dmi_value (FuPlugin *self, const gchar *dmi_id)
Richard Hughesd7704d42017-08-08 20:29:09 +0100565{
Richard Hughes12724852018-09-04 13:53:44 +0100566 FuPluginPrivate *priv = GET_PRIVATE (self);
Richard Hughesd7704d42017-08-08 20:29:09 +0100567 if (priv->hwids == NULL)
Richard Hughes7ef96b82017-08-23 18:28:24 +0100568 return NULL;
Richard Hughesd7704d42017-08-08 20:29:09 +0100569 return fu_hwids_get_value (priv->hwids, dmi_id);
Richard Hughesb8f8db22017-04-25 15:56:00 +0100570}
571
Richard Hughes49e5e052017-09-03 12:15:41 +0100572/**
573 * fu_plugin_get_smbios_string:
Richard Hughes2c0635a2018-09-04 14:52:46 +0100574 * @self: A #FuPlugin
Richard Hughes49e5e052017-09-03 12:15:41 +0100575 * @structure_type: A SMBIOS structure type, e.g. %FU_SMBIOS_STRUCTURE_TYPE_BIOS
576 * @offset: A SMBIOS offset
577 *
578 * Gets a hardware SMBIOS string.
579 *
580 * The @type and @offset can be referenced from the DMTF SMBIOS specification:
581 * https://www.dmtf.org/sites/default/files/standards/documents/DSP0134_3.1.1.pdf
582 *
Richard Hughes4eada342017-10-03 21:20:32 +0100583 * Returns: A string, or %NULL
584 *
Richard Hughes49e5e052017-09-03 12:15:41 +0100585 * Since: 0.9.8
586 **/
587const gchar *
Richard Hughes12724852018-09-04 13:53:44 +0100588fu_plugin_get_smbios_string (FuPlugin *self, guint8 structure_type, guint8 offset)
Richard Hughes49e5e052017-09-03 12:15:41 +0100589{
Richard Hughes12724852018-09-04 13:53:44 +0100590 FuPluginPrivate *priv = GET_PRIVATE (self);
Richard Hughes49e5e052017-09-03 12:15:41 +0100591 if (priv->smbios == NULL)
592 return NULL;
593 return fu_smbios_get_string (priv->smbios, structure_type, offset, NULL);
594}
595
596/**
597 * fu_plugin_get_smbios_data:
Richard Hughes2c0635a2018-09-04 14:52:46 +0100598 * @self: A #FuPlugin
Richard Hughes49e5e052017-09-03 12:15:41 +0100599 * @structure_type: A SMBIOS structure type, e.g. %FU_SMBIOS_STRUCTURE_TYPE_BIOS
600 *
601 * Gets a hardware SMBIOS data.
602 *
Richard Hughes4eada342017-10-03 21:20:32 +0100603 * Returns: (transfer none): A #GBytes, or %NULL
604 *
Richard Hughes49e5e052017-09-03 12:15:41 +0100605 * Since: 0.9.8
606 **/
607GBytes *
Richard Hughes12724852018-09-04 13:53:44 +0100608fu_plugin_get_smbios_data (FuPlugin *self, guint8 structure_type)
Richard Hughes49e5e052017-09-03 12:15:41 +0100609{
Richard Hughes12724852018-09-04 13:53:44 +0100610 FuPluginPrivate *priv = GET_PRIVATE (self);
Richard Hughes49e5e052017-09-03 12:15:41 +0100611 if (priv->smbios == NULL)
612 return NULL;
613 return fu_smbios_get_data (priv->smbios, structure_type, NULL);
614}
615
Richard Hughesb8f8db22017-04-25 15:56:00 +0100616void
Richard Hughes12724852018-09-04 13:53:44 +0100617fu_plugin_set_hwids (FuPlugin *self, FuHwids *hwids)
Richard Hughesb8f8db22017-04-25 15:56:00 +0100618{
Richard Hughes12724852018-09-04 13:53:44 +0100619 FuPluginPrivate *priv = GET_PRIVATE (self);
Richard Hughesd7704d42017-08-08 20:29:09 +0100620 g_set_object (&priv->hwids, hwids);
Richard Hughesb8f8db22017-04-25 15:56:00 +0100621}
622
Richard Hughes49e5e052017-09-03 12:15:41 +0100623void
Richard Hughes12724852018-09-04 13:53:44 +0100624fu_plugin_set_udev_subsystems (FuPlugin *self, GPtrArray *udev_subsystems)
Richard Hughes9d6e0e72018-08-24 20:20:17 +0100625{
Richard Hughes12724852018-09-04 13:53:44 +0100626 FuPluginPrivate *priv = GET_PRIVATE (self);
Richard Hughes9d6e0e72018-08-24 20:20:17 +0100627 if (priv->udev_subsystems != NULL)
628 g_ptr_array_unref (priv->udev_subsystems);
629 priv->udev_subsystems = g_ptr_array_ref (udev_subsystems);
630}
631
632void
Richard Hughes12724852018-09-04 13:53:44 +0100633fu_plugin_set_quirks (FuPlugin *self, FuQuirks *quirks)
Richard Hughes9c028f02017-10-28 21:14:28 +0100634{
Richard Hughes12724852018-09-04 13:53:44 +0100635 FuPluginPrivate *priv = GET_PRIVATE (self);
Richard Hughes9c028f02017-10-28 21:14:28 +0100636 g_set_object (&priv->quirks, quirks);
637}
638
639/**
640 * fu_plugin_get_quirks:
Richard Hughes2c0635a2018-09-04 14:52:46 +0100641 * @self: A #FuPlugin
Richard Hughes9c028f02017-10-28 21:14:28 +0100642 *
643 * Returns the hardware database object. This can be used to discover device
644 * quirks or other device-specific settings.
645 *
646 * Returns: (transfer none): a #FuQuirks, or %NULL if not set
647 *
648 * Since: 1.0.1
649 **/
650FuQuirks *
Richard Hughes12724852018-09-04 13:53:44 +0100651fu_plugin_get_quirks (FuPlugin *self)
Richard Hughes9c028f02017-10-28 21:14:28 +0100652{
Richard Hughes12724852018-09-04 13:53:44 +0100653 FuPluginPrivate *priv = GET_PRIVATE (self);
Richard Hughes9c028f02017-10-28 21:14:28 +0100654 return priv->quirks;
655}
656
Richard Hughes0eb123b2018-04-19 12:00:04 +0100657void
Richard Hughes12724852018-09-04 13:53:44 +0100658fu_plugin_set_runtime_versions (FuPlugin *self, GHashTable *runtime_versions)
Richard Hughes0eb123b2018-04-19 12:00:04 +0100659{
Richard Hughes12724852018-09-04 13:53:44 +0100660 FuPluginPrivate *priv = GET_PRIVATE (self);
Richard Hughes0eb123b2018-04-19 12:00:04 +0100661 priv->runtime_versions = g_hash_table_ref (runtime_versions);
662}
663
664/**
665 * fu_plugin_add_runtime_version:
Richard Hughes2c0635a2018-09-04 14:52:46 +0100666 * @self: A #FuPlugin
Richard Hughes0eb123b2018-04-19 12:00:04 +0100667 * @component_id: An AppStream component id, e.g. "org.gnome.Software"
668 * @version: A version string, e.g. "1.2.3"
669 *
670 * Sets a runtime version of a specific dependancy.
671 *
672 * Since: 1.0.7
673 **/
674void
Richard Hughes12724852018-09-04 13:53:44 +0100675fu_plugin_add_runtime_version (FuPlugin *self,
Richard Hughes0eb123b2018-04-19 12:00:04 +0100676 const gchar *component_id,
677 const gchar *version)
678{
Richard Hughes12724852018-09-04 13:53:44 +0100679 FuPluginPrivate *priv = GET_PRIVATE (self);
Richard Hughesb01b4862018-04-20 16:39:48 +0100680 if (priv->runtime_versions == NULL)
681 return;
Richard Hughes0eb123b2018-04-19 12:00:04 +0100682 g_hash_table_insert (priv->runtime_versions,
683 g_strdup (component_id),
684 g_strdup (version));
685}
686
Richard Hughes34e0dab2018-04-20 16:43:00 +0100687void
Richard Hughes12724852018-09-04 13:53:44 +0100688fu_plugin_set_compile_versions (FuPlugin *self, GHashTable *compile_versions)
Richard Hughes34e0dab2018-04-20 16:43:00 +0100689{
Richard Hughes12724852018-09-04 13:53:44 +0100690 FuPluginPrivate *priv = GET_PRIVATE (self);
Richard Hughes34e0dab2018-04-20 16:43:00 +0100691 priv->compile_versions = g_hash_table_ref (compile_versions);
692}
693
694/**
695 * fu_plugin_add_compile_version:
Richard Hughes2c0635a2018-09-04 14:52:46 +0100696 * @self: A #FuPlugin
Richard Hughes34e0dab2018-04-20 16:43:00 +0100697 * @component_id: An AppStream component id, e.g. "org.gnome.Software"
698 * @version: A version string, e.g. "1.2.3"
699 *
700 * Sets a compile-time version of a specific dependancy.
701 *
702 * Since: 1.0.7
703 **/
704void
Richard Hughes12724852018-09-04 13:53:44 +0100705fu_plugin_add_compile_version (FuPlugin *self,
Richard Hughes34e0dab2018-04-20 16:43:00 +0100706 const gchar *component_id,
707 const gchar *version)
708{
Richard Hughes12724852018-09-04 13:53:44 +0100709 FuPluginPrivate *priv = GET_PRIVATE (self);
Richard Hughes34e0dab2018-04-20 16:43:00 +0100710 if (priv->compile_versions == NULL)
711 return;
712 g_hash_table_insert (priv->compile_versions,
713 g_strdup (component_id),
714 g_strdup (version));
715}
716
Richard Hughes9c028f02017-10-28 21:14:28 +0100717/**
718 * fu_plugin_lookup_quirk_by_id:
Richard Hughes2c0635a2018-09-04 14:52:46 +0100719 * @self: A #FuPlugin
Richard Hughes87fb9ff2018-06-28 12:55:59 +0100720 * @group: A string, e.g. "DfuFlags"
721 * @key: An ID to match the entry, e.g. "Summary"
Richard Hughes9c028f02017-10-28 21:14:28 +0100722 *
723 * Looks up an entry in the hardware database using a string value.
724 *
725 * Returns: (transfer none): values from the database, or %NULL if not found
726 *
727 * Since: 1.0.1
728 **/
729const gchar *
Richard Hughes12724852018-09-04 13:53:44 +0100730fu_plugin_lookup_quirk_by_id (FuPlugin *self, const gchar *group, const gchar *key)
Richard Hughes9c028f02017-10-28 21:14:28 +0100731{
Richard Hughes12724852018-09-04 13:53:44 +0100732 FuPluginPrivate *priv = GET_PRIVATE (self);
733 g_return_val_if_fail (FU_IS_PLUGIN (self), NULL);
Richard Hughes9c028f02017-10-28 21:14:28 +0100734
Richard Hughes9c028f02017-10-28 21:14:28 +0100735 /* exact ID */
Richard Hughes87fb9ff2018-06-28 12:55:59 +0100736 return fu_quirks_lookup_by_id (priv->quirks, group, key);
Richard Hughes9c028f02017-10-28 21:14:28 +0100737}
738
739/**
Richard Hughes8fe7cdd2018-08-23 10:02:44 +0100740 * fu_plugin_lookup_quirk_by_id_as_uint64:
Richard Hughes2c0635a2018-09-04 14:52:46 +0100741 * @self: A #FuPlugin
Richard Hughes8fe7cdd2018-08-23 10:02:44 +0100742 * @group: A string, e.g. "DfuFlags"
743 * @key: An ID to match the entry, e.g. "Size"
744 *
745 * Looks up an entry in the hardware database using a string key, returning
746 * an integer value. Values are assumed base 10, unless prefixed with "0x"
747 * where they are parsed as base 16.
748 *
749 * Returns: (transfer none): value from the database, or 0 if not found
750 *
751 * Since: 1.1.2
752 **/
753guint64
Richard Hughes12724852018-09-04 13:53:44 +0100754fu_plugin_lookup_quirk_by_id_as_uint64 (FuPlugin *self, const gchar *group, const gchar *key)
Richard Hughes8fe7cdd2018-08-23 10:02:44 +0100755{
Richard Hughes12724852018-09-04 13:53:44 +0100756 return fu_common_strtoull (fu_plugin_lookup_quirk_by_id (self, group, key));
Richard Hughes8fe7cdd2018-08-23 10:02:44 +0100757}
758
Richard Hughes1354ea92017-09-19 15:58:31 +0100759void
Richard Hughes12724852018-09-04 13:53:44 +0100760fu_plugin_set_smbios (FuPlugin *self, FuSmbios *smbios)
Richard Hughes49e5e052017-09-03 12:15:41 +0100761{
Richard Hughes12724852018-09-04 13:53:44 +0100762 FuPluginPrivate *priv = GET_PRIVATE (self);
Richard Hughes49e5e052017-09-03 12:15:41 +0100763 g_set_object (&priv->smbios, smbios);
764}
765
Richard Hughesb8f8db22017-04-25 15:56:00 +0100766/**
Richard Hughesb0829032017-01-10 09:27:08 +0000767 * fu_plugin_set_coldplug_delay:
Richard Hughes2c0635a2018-09-04 14:52:46 +0100768 * @self: A #FuPlugin
Richard Hughesb0829032017-01-10 09:27:08 +0000769 * @duration: A delay in milliseconds
770 *
771 * Set the minimum time that should be waited inbetween the call to
772 * fu_plugin_coldplug_prepare() and fu_plugin_coldplug(). This is usually going
773 * to be the minimum hardware initialisation time from a datasheet.
774 *
775 * It is better to use this function rather than using a sleep() in the plugin
776 * itself as then only one delay is done in the daemon rather than waiting for
777 * each coldplug prepare in a serial way.
778 *
779 * Additionally, very long delays should be avoided as the daemon will be
780 * blocked from processing requests whilst the coldplug delay is being
781 * performed.
782 *
783 * Since: 0.8.0
784 **/
785void
Richard Hughes12724852018-09-04 13:53:44 +0100786fu_plugin_set_coldplug_delay (FuPlugin *self, guint duration)
Richard Hughesb0829032017-01-10 09:27:08 +0000787{
Richard Hughes12724852018-09-04 13:53:44 +0100788 g_return_if_fail (FU_IS_PLUGIN (self));
Richard Hughesb0829032017-01-10 09:27:08 +0000789 g_return_if_fail (duration > 0);
790
791 /* check sanity */
792 if (duration > FU_PLUGIN_COLDPLUG_DELAY_MAXIMUM) {
793 g_warning ("duration of %ums is crazy, truncating to %ums",
794 duration,
795 FU_PLUGIN_COLDPLUG_DELAY_MAXIMUM);
796 duration = FU_PLUGIN_COLDPLUG_DELAY_MAXIMUM;
797 }
798
799 /* emit */
Richard Hughes12724852018-09-04 13:53:44 +0100800 g_signal_emit (self, signals[SIGNAL_SET_COLDPLUG_DELAY], 0, duration);
Richard Hughesb0829032017-01-10 09:27:08 +0000801}
802
Richard Hughesd0905142016-03-13 09:46:49 +0000803gboolean
Richard Hughes12724852018-09-04 13:53:44 +0100804fu_plugin_runner_startup (FuPlugin *self, GError **error)
Richard Hughesd0905142016-03-13 09:46:49 +0000805{
Richard Hughes12724852018-09-04 13:53:44 +0100806 FuPluginPrivate *priv = GET_PRIVATE (self);
Richard Hughes7b8b2022016-12-12 16:15:03 +0000807 FuPluginStartupFunc func = NULL;
Richard Hughescd2fb3e2018-11-29 19:58:09 +0000808 g_autoptr(GError) error_local = NULL;
Richard Hughesd0905142016-03-13 09:46:49 +0000809
810 /* not enabled */
Richard Hughescff38bc2016-12-12 12:03:37 +0000811 if (!priv->enabled)
Richard Hughesd0905142016-03-13 09:46:49 +0000812 return TRUE;
813
Richard Hughes639da472018-01-06 22:35:04 +0000814 /* no object loaded */
815 if (priv->module == NULL)
816 return TRUE;
817
Richard Hughesd0905142016-03-13 09:46:49 +0000818 /* optional */
Richard Hughescff38bc2016-12-12 12:03:37 +0000819 g_module_symbol (priv->module, "fu_plugin_startup", (gpointer *) &func);
820 if (func == NULL)
Richard Hughesd0905142016-03-13 09:46:49 +0000821 return TRUE;
Richard Hughescff38bc2016-12-12 12:03:37 +0000822 g_debug ("performing startup() on %s", priv->name);
Richard Hughescd2fb3e2018-11-29 19:58:09 +0000823 if (!func (self, &error_local)) {
824 if (error_local == NULL) {
825 g_critical ("unset error in plugin %s for startup()",
826 priv->name);
827 g_set_error_literal (&error_local,
828 FWUPD_ERROR,
829 FWUPD_ERROR_INTERNAL,
830 "unspecified error");
831 }
832 g_propagate_prefixed_error (error, g_steal_pointer (&error_local),
833 "failed to startup using %s: ",
834 priv->name);
Richard Hughescff38bc2016-12-12 12:03:37 +0000835 return FALSE;
836 }
837 return TRUE;
838}
839
840static gboolean
841fu_plugin_runner_offline_invalidate (GError **error)
842{
843 g_autoptr(GError) error_local = NULL;
844 g_autoptr(GFile) file1 = NULL;
845
846 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
847
848 file1 = g_file_new_for_path (FU_OFFLINE_TRIGGER_FILENAME);
849 if (!g_file_query_exists (file1, NULL))
850 return TRUE;
851 if (!g_file_delete (file1, NULL, &error_local)) {
852 g_set_error (error,
853 FWUPD_ERROR,
854 FWUPD_ERROR_INTERNAL,
855 "Cannot delete %s: %s",
856 FU_OFFLINE_TRIGGER_FILENAME,
857 error_local->message);
858 return FALSE;
859 }
860 return TRUE;
861}
862
863static gboolean
864fu_plugin_runner_offline_setup (GError **error)
865{
Richard Hughes484ee292019-03-22 16:10:50 +0000866 const gchar *symlink_target = "/var/lib/fwupd";
Richard Hughescff38bc2016-12-12 12:03:37 +0000867 gint rc;
Richard Hughes484ee292019-03-22 16:10:50 +0000868 g_autofree gchar *filename = NULL;
Richard Hughescff38bc2016-12-12 12:03:37 +0000869
870 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
871
Richard Hughes484ee292019-03-22 16:10:50 +0000872 /* does already exist */
873 filename = fu_common_realpath (FU_OFFLINE_TRIGGER_FILENAME, NULL);
874 if (g_strcmp0 (filename, symlink_target) == 0) {
875 g_debug ("%s already points to %s, skipping creation",
876 FU_OFFLINE_TRIGGER_FILENAME, symlink_target);
877 return TRUE;
878 }
879
Richard Hughescff38bc2016-12-12 12:03:37 +0000880 /* create symlink for the systemd-system-update-generator */
Richard Hughes484ee292019-03-22 16:10:50 +0000881 rc = symlink (symlink_target, FU_OFFLINE_TRIGGER_FILENAME);
Richard Hughescff38bc2016-12-12 12:03:37 +0000882 if (rc < 0) {
883 g_set_error (error,
884 FWUPD_ERROR,
885 FWUPD_ERROR_INTERNAL,
886 "Failed to create symlink %s to %s: %s",
887 FU_OFFLINE_TRIGGER_FILENAME,
888 "/var/lib", strerror (errno));
Richard Hughesd0905142016-03-13 09:46:49 +0000889 return FALSE;
890 }
891 return TRUE;
892}
893
Richard Hughes0d7fdb32017-11-11 20:23:14 +0000894static gboolean
Richard Hughes12724852018-09-04 13:53:44 +0100895fu_plugin_runner_device_generic (FuPlugin *self, FuDevice *device,
Richard Hughes0d7fdb32017-11-11 20:23:14 +0000896 const gchar *symbol_name, GError **error)
897{
Richard Hughes12724852018-09-04 13:53:44 +0100898 FuPluginPrivate *priv = GET_PRIVATE (self);
Richard Hughes0d7fdb32017-11-11 20:23:14 +0000899 FuPluginDeviceFunc func = NULL;
Richard Hughescd2fb3e2018-11-29 19:58:09 +0000900 g_autoptr(GError) error_local = NULL;
Richard Hughes0d7fdb32017-11-11 20:23:14 +0000901
902 /* not enabled */
903 if (!priv->enabled)
904 return TRUE;
905
Richard Hughesd3d96cc2017-11-14 11:34:33 +0000906 /* no object loaded */
907 if (priv->module == NULL)
908 return TRUE;
909
Richard Hughes0d7fdb32017-11-11 20:23:14 +0000910 /* optional */
911 g_module_symbol (priv->module, symbol_name, (gpointer *) &func);
912 if (func == NULL)
913 return TRUE;
914 g_debug ("performing %s() on %s", symbol_name + 10, priv->name);
Richard Hughescd2fb3e2018-11-29 19:58:09 +0000915 if (!func (self, device, &error_local)) {
916 if (error_local == NULL) {
917 g_critical ("unset error in plugin %s for %s()",
918 priv->name, symbol_name + 10);
919 g_set_error_literal (&error_local,
920 FWUPD_ERROR,
921 FWUPD_ERROR_INTERNAL,
922 "unspecified error");
923 }
924 g_propagate_prefixed_error (error, g_steal_pointer (&error_local),
925 "failed to %s using %s: ",
926 symbol_name + 10, priv->name);
Richard Hughes0d7fdb32017-11-11 20:23:14 +0000927 return FALSE;
928 }
929 return TRUE;
930}
931
Richard Hughesdbd8c762018-06-15 20:31:40 +0100932static gboolean
Richard Hughes12724852018-09-04 13:53:44 +0100933fu_plugin_runner_flagged_device_generic (FuPlugin *self, FwupdInstallFlags flags,
Mario Limoncielloe3b1a3f2018-08-21 13:01:45 -0500934 FuDevice *device,
935 const gchar *symbol_name, GError **error)
936{
Richard Hughes12724852018-09-04 13:53:44 +0100937 FuPluginPrivate *priv = GET_PRIVATE (self);
Mario Limoncielloe3b1a3f2018-08-21 13:01:45 -0500938 FuPluginFlaggedDeviceFunc func = NULL;
Richard Hughescd2fb3e2018-11-29 19:58:09 +0000939 g_autoptr(GError) error_local = NULL;
Mario Limoncielloe3b1a3f2018-08-21 13:01:45 -0500940
941 /* not enabled */
942 if (!priv->enabled)
943 return TRUE;
944
945 /* no object loaded */
946 if (priv->module == NULL)
947 return TRUE;
948
949 /* optional */
950 g_module_symbol (priv->module, symbol_name, (gpointer *) &func);
951 if (func == NULL)
952 return TRUE;
953 g_debug ("performing %s() on %s", symbol_name + 10, priv->name);
Richard Hughescd2fb3e2018-11-29 19:58:09 +0000954 if (!func (self, flags, device, &error_local)) {
955 if (error_local == NULL) {
956 g_critical ("unset error in plugin %s for %s()",
957 priv->name, symbol_name + 10);
958 g_set_error_literal (&error_local,
959 FWUPD_ERROR,
960 FWUPD_ERROR_INTERNAL,
961 "unspecified error");
962 }
963 g_propagate_prefixed_error (error, g_steal_pointer (&error_local),
964 "failed to %s using %s: ",
965 symbol_name + 10, priv->name);
Mario Limoncielloe3b1a3f2018-08-21 13:01:45 -0500966 return FALSE;
967 }
968 return TRUE;
969
970}
971
972static gboolean
Richard Hughes12724852018-09-04 13:53:44 +0100973fu_plugin_runner_device_array_generic (FuPlugin *self, GPtrArray *devices,
Richard Hughesdbd8c762018-06-15 20:31:40 +0100974 const gchar *symbol_name, GError **error)
975{
Richard Hughes12724852018-09-04 13:53:44 +0100976 FuPluginPrivate *priv = GET_PRIVATE (self);
Richard Hughesdbd8c762018-06-15 20:31:40 +0100977 FuPluginDeviceArrayFunc func = NULL;
Richard Hughescd2fb3e2018-11-29 19:58:09 +0000978 g_autoptr(GError) error_local = NULL;
Richard Hughesdbd8c762018-06-15 20:31:40 +0100979
980 /* not enabled */
981 if (!priv->enabled)
982 return TRUE;
983
984 /* no object loaded */
985 if (priv->module == NULL)
986 return TRUE;
987
988 /* optional */
989 g_module_symbol (priv->module, symbol_name, (gpointer *) &func);
990 if (func == NULL)
991 return TRUE;
992 g_debug ("performing %s() on %s", symbol_name + 10, priv->name);
Richard Hughescd2fb3e2018-11-29 19:58:09 +0000993 if (!func (self, devices, &error_local)) {
994 if (error_local == NULL) {
995 g_critical ("unset error in plugin %s for %s()",
996 priv->name, symbol_name + 10);
997 g_set_error_literal (&error_local,
998 FWUPD_ERROR,
999 FWUPD_ERROR_INTERNAL,
1000 "unspecified error");
1001 }
1002 g_propagate_prefixed_error (error, g_steal_pointer (&error_local),
1003 "failed to %s using %s: ",
1004 symbol_name + 10, priv->name);
Richard Hughesdbd8c762018-06-15 20:31:40 +01001005 return FALSE;
1006 }
1007 return TRUE;
1008}
1009
Richard Hughesd0905142016-03-13 09:46:49 +00001010gboolean
Richard Hughes12724852018-09-04 13:53:44 +01001011fu_plugin_runner_coldplug (FuPlugin *self, GError **error)
Richard Hughesd0905142016-03-13 09:46:49 +00001012{
Richard Hughes12724852018-09-04 13:53:44 +01001013 FuPluginPrivate *priv = GET_PRIVATE (self);
Richard Hughes7b8b2022016-12-12 16:15:03 +00001014 FuPluginStartupFunc func = NULL;
Richard Hughescd2fb3e2018-11-29 19:58:09 +00001015 g_autoptr(GError) error_local = NULL;
Richard Hughesd0905142016-03-13 09:46:49 +00001016
1017 /* not enabled */
Richard Hughescff38bc2016-12-12 12:03:37 +00001018 if (!priv->enabled)
Richard Hughesd0905142016-03-13 09:46:49 +00001019 return TRUE;
1020
Richard Hughes639da472018-01-06 22:35:04 +00001021 /* no object loaded */
1022 if (priv->module == NULL)
1023 return TRUE;
1024
Richard Hughesd0905142016-03-13 09:46:49 +00001025 /* optional */
Richard Hughescff38bc2016-12-12 12:03:37 +00001026 g_module_symbol (priv->module, "fu_plugin_coldplug", (gpointer *) &func);
1027 if (func == NULL)
Richard Hughesd0905142016-03-13 09:46:49 +00001028 return TRUE;
Richard Hughescff38bc2016-12-12 12:03:37 +00001029 g_debug ("performing coldplug() on %s", priv->name);
Richard Hughescd2fb3e2018-11-29 19:58:09 +00001030 if (!func (self, &error_local)) {
1031 if (error_local == NULL) {
1032 g_critical ("unset error in plugin %s for coldplug()",
1033 priv->name);
1034 g_set_error_literal (&error_local,
1035 FWUPD_ERROR,
1036 FWUPD_ERROR_INTERNAL,
1037 "unspecified error");
1038 }
1039 g_propagate_prefixed_error (error, g_steal_pointer (&error_local),
1040 "failed to coldplug using %s: ", priv->name);
Richard Hughescff38bc2016-12-12 12:03:37 +00001041 return FALSE;
1042 }
1043 return TRUE;
1044}
1045
Richard Hughes7b8b2022016-12-12 16:15:03 +00001046gboolean
Richard Hughes12724852018-09-04 13:53:44 +01001047fu_plugin_runner_recoldplug (FuPlugin *self, GError **error)
Richard Hughes2de8f132018-01-17 09:12:02 +00001048{
Richard Hughes12724852018-09-04 13:53:44 +01001049 FuPluginPrivate *priv = GET_PRIVATE (self);
Richard Hughes2de8f132018-01-17 09:12:02 +00001050 FuPluginStartupFunc func = NULL;
Richard Hughescd2fb3e2018-11-29 19:58:09 +00001051 g_autoptr(GError) error_local = NULL;
Richard Hughes2de8f132018-01-17 09:12:02 +00001052
1053 /* not enabled */
1054 if (!priv->enabled)
1055 return TRUE;
1056
1057 /* no object loaded */
1058 if (priv->module == NULL)
1059 return TRUE;
1060
1061 /* optional */
1062 g_module_symbol (priv->module, "fu_plugin_recoldplug", (gpointer *) &func);
1063 if (func == NULL)
1064 return TRUE;
1065 g_debug ("performing recoldplug() on %s", priv->name);
Richard Hughescd2fb3e2018-11-29 19:58:09 +00001066 if (!func (self, &error_local)) {
1067 if (error_local == NULL) {
1068 g_critical ("unset error in plugin %s for recoldplug()",
1069 priv->name);
1070 g_set_error_literal (&error_local,
1071 FWUPD_ERROR,
1072 FWUPD_ERROR_INTERNAL,
1073 "unspecified error");
1074 }
1075 g_propagate_prefixed_error (error, g_steal_pointer (&error_local),
1076 "failed to recoldplug using %s: ",
1077 priv->name);
Richard Hughes2de8f132018-01-17 09:12:02 +00001078 return FALSE;
1079 }
1080 return TRUE;
1081}
1082
1083gboolean
Richard Hughes12724852018-09-04 13:53:44 +01001084fu_plugin_runner_coldplug_prepare (FuPlugin *self, GError **error)
Richard Hughes46487c92017-01-07 21:26:34 +00001085{
Richard Hughes12724852018-09-04 13:53:44 +01001086 FuPluginPrivate *priv = GET_PRIVATE (self);
Richard Hughes46487c92017-01-07 21:26:34 +00001087 FuPluginStartupFunc func = NULL;
Richard Hughescd2fb3e2018-11-29 19:58:09 +00001088 g_autoptr(GError) error_local = NULL;
Richard Hughes46487c92017-01-07 21:26:34 +00001089
1090 /* not enabled */
1091 if (!priv->enabled)
1092 return TRUE;
1093
Richard Hughes639da472018-01-06 22:35:04 +00001094 /* no object loaded */
1095 if (priv->module == NULL)
1096 return TRUE;
1097
Richard Hughes46487c92017-01-07 21:26:34 +00001098 /* optional */
1099 g_module_symbol (priv->module, "fu_plugin_coldplug_prepare", (gpointer *) &func);
1100 if (func == NULL)
1101 return TRUE;
1102 g_debug ("performing coldplug_prepare() on %s", priv->name);
Richard Hughescd2fb3e2018-11-29 19:58:09 +00001103 if (!func (self, &error_local)) {
1104 if (error_local == NULL) {
1105 g_critical ("unset error in plugin %s for coldplug_prepare()",
1106 priv->name);
1107 g_set_error_literal (&error_local,
1108 FWUPD_ERROR,
1109 FWUPD_ERROR_INTERNAL,
1110 "unspecified error");
1111 }
1112 g_propagate_prefixed_error (error, g_steal_pointer (&error_local),
1113 "failed to coldplug_prepare using %s: ",
1114 priv->name);
Richard Hughes46487c92017-01-07 21:26:34 +00001115 return FALSE;
1116 }
1117 return TRUE;
1118}
1119
1120gboolean
Richard Hughes12724852018-09-04 13:53:44 +01001121fu_plugin_runner_coldplug_cleanup (FuPlugin *self, GError **error)
Richard Hughes46487c92017-01-07 21:26:34 +00001122{
Richard Hughes12724852018-09-04 13:53:44 +01001123 FuPluginPrivate *priv = GET_PRIVATE (self);
Richard Hughes46487c92017-01-07 21:26:34 +00001124 FuPluginStartupFunc func = NULL;
Richard Hughescd2fb3e2018-11-29 19:58:09 +00001125 g_autoptr(GError) error_local = NULL;
Richard Hughes46487c92017-01-07 21:26:34 +00001126
1127 /* not enabled */
1128 if (!priv->enabled)
1129 return TRUE;
1130
Richard Hughes639da472018-01-06 22:35:04 +00001131 /* no object loaded */
1132 if (priv->module == NULL)
1133 return TRUE;
1134
Richard Hughes46487c92017-01-07 21:26:34 +00001135 /* optional */
1136 g_module_symbol (priv->module, "fu_plugin_coldplug_cleanup", (gpointer *) &func);
1137 if (func == NULL)
1138 return TRUE;
1139 g_debug ("performing coldplug_cleanup() on %s", priv->name);
Richard Hughescd2fb3e2018-11-29 19:58:09 +00001140 if (!func (self, &error_local)) {
1141 if (error_local == NULL) {
1142 g_critical ("unset error in plugin %s for coldplug_cleanup()",
1143 priv->name);
1144 g_set_error_literal (&error_local,
1145 FWUPD_ERROR,
1146 FWUPD_ERROR_INTERNAL,
1147 "unspecified error");
1148 }
1149 g_propagate_prefixed_error (error, g_steal_pointer (&error_local),
1150 "failed to coldplug_cleanup using %s: ",
1151 priv->name);
Richard Hughes46487c92017-01-07 21:26:34 +00001152 return FALSE;
1153 }
1154 return TRUE;
1155}
1156
1157gboolean
Richard Hughes12724852018-09-04 13:53:44 +01001158fu_plugin_runner_composite_prepare (FuPlugin *self, GPtrArray *devices, GError **error)
Richard Hughesdbd8c762018-06-15 20:31:40 +01001159{
Richard Hughes12724852018-09-04 13:53:44 +01001160 return fu_plugin_runner_device_array_generic (self, devices,
Richard Hughesdbd8c762018-06-15 20:31:40 +01001161 "fu_plugin_composite_prepare",
1162 error);
1163}
1164
1165gboolean
Richard Hughes12724852018-09-04 13:53:44 +01001166fu_plugin_runner_composite_cleanup (FuPlugin *self, GPtrArray *devices, GError **error)
Richard Hughesdbd8c762018-06-15 20:31:40 +01001167{
Richard Hughes12724852018-09-04 13:53:44 +01001168 return fu_plugin_runner_device_array_generic (self, devices,
Richard Hughesdbd8c762018-06-15 20:31:40 +01001169 "fu_plugin_composite_cleanup",
1170 error);
1171}
1172
1173gboolean
Richard Hughes12724852018-09-04 13:53:44 +01001174fu_plugin_runner_update_prepare (FuPlugin *self, FwupdInstallFlags flags, FuDevice *device,
Mario Limoncielloe3b1a3f2018-08-21 13:01:45 -05001175 GError **error)
Richard Hughes7b8b2022016-12-12 16:15:03 +00001176{
Richard Hughes12724852018-09-04 13:53:44 +01001177 return fu_plugin_runner_flagged_device_generic (self, flags, device,
Mario Limoncielloe3b1a3f2018-08-21 13:01:45 -05001178 "fu_plugin_update_prepare",
1179 error);
Richard Hughes7b8b2022016-12-12 16:15:03 +00001180}
1181
1182gboolean
Richard Hughes12724852018-09-04 13:53:44 +01001183fu_plugin_runner_update_cleanup (FuPlugin *self, FwupdInstallFlags flags, FuDevice *device,
Mario Limoncielloe3b1a3f2018-08-21 13:01:45 -05001184 GError **error)
Richard Hughes7b8b2022016-12-12 16:15:03 +00001185{
Richard Hughes12724852018-09-04 13:53:44 +01001186 return fu_plugin_runner_flagged_device_generic (self, flags, device,
Mario Limoncielloe3b1a3f2018-08-21 13:01:45 -05001187 "fu_plugin_update_cleanup",
1188 error);
Richard Hughes0d7fdb32017-11-11 20:23:14 +00001189}
Richard Hughes7b8b2022016-12-12 16:15:03 +00001190
Richard Hughes0d7fdb32017-11-11 20:23:14 +00001191gboolean
Richard Hughes12724852018-09-04 13:53:44 +01001192fu_plugin_runner_update_attach (FuPlugin *self, FuDevice *device, GError **error)
Richard Hughes0d7fdb32017-11-11 20:23:14 +00001193{
Richard Hughes12724852018-09-04 13:53:44 +01001194 return fu_plugin_runner_device_generic (self, device,
Richard Hughes0d7fdb32017-11-11 20:23:14 +00001195 "fu_plugin_update_attach", error);
1196}
Richard Hughes7b8b2022016-12-12 16:15:03 +00001197
Richard Hughes0d7fdb32017-11-11 20:23:14 +00001198gboolean
Richard Hughes12724852018-09-04 13:53:44 +01001199fu_plugin_runner_update_detach (FuPlugin *self, FuDevice *device, GError **error)
Richard Hughes0d7fdb32017-11-11 20:23:14 +00001200{
Richard Hughes12724852018-09-04 13:53:44 +01001201 return fu_plugin_runner_device_generic (self, device,
Richard Hughes0d7fdb32017-11-11 20:23:14 +00001202 "fu_plugin_update_detach", error);
1203}
1204
1205gboolean
Richard Hughes12724852018-09-04 13:53:44 +01001206fu_plugin_runner_update_reload (FuPlugin *self, FuDevice *device, GError **error)
Richard Hughes0d7fdb32017-11-11 20:23:14 +00001207{
Richard Hughes12724852018-09-04 13:53:44 +01001208 return fu_plugin_runner_device_generic (self, device,
Richard Hughes0d7fdb32017-11-11 20:23:14 +00001209 "fu_plugin_update_reload", error);
Richard Hughes7b8b2022016-12-12 16:15:03 +00001210}
1211
Richard Hughes9d6e0e72018-08-24 20:20:17 +01001212/**
1213 * fu_plugin_add_udev_subsystem:
Richard Hughes2c0635a2018-09-04 14:52:46 +01001214 * @self: a #FuPlugin
Richard Hughes9d6e0e72018-08-24 20:20:17 +01001215 * @subsystem: a subsystem name, e.g. `pciport`
1216 *
1217 * Registers the udev subsystem to be watched by the daemon.
1218 *
1219 * Plugins can use this method only in fu_plugin_init()
1220 **/
1221void
Richard Hughes12724852018-09-04 13:53:44 +01001222fu_plugin_add_udev_subsystem (FuPlugin *self, const gchar *subsystem)
Richard Hughes9d6e0e72018-08-24 20:20:17 +01001223{
Richard Hughes12724852018-09-04 13:53:44 +01001224 FuPluginPrivate *priv = GET_PRIVATE (self);
Richard Hughes9d6e0e72018-08-24 20:20:17 +01001225 for (guint i = 0; i < priv->udev_subsystems->len; i++) {
1226 const gchar *subsystem_tmp = g_ptr_array_index (priv->udev_subsystems, i);
1227 if (g_strcmp0 (subsystem_tmp, subsystem) == 0)
1228 return;
1229 }
1230 g_debug ("added udev subsystem watch of %s", subsystem);
1231 g_ptr_array_add (priv->udev_subsystems, g_strdup (subsystem));
1232}
1233
Richard Hughes104f6512017-11-24 11:44:57 +00001234gboolean
Richard Hughes12724852018-09-04 13:53:44 +01001235fu_plugin_runner_usb_device_added (FuPlugin *self, FuUsbDevice *device, GError **error)
Richard Hughes104f6512017-11-24 11:44:57 +00001236{
Richard Hughes12724852018-09-04 13:53:44 +01001237 FuPluginPrivate *priv = GET_PRIVATE (self);
Richard Hughes104f6512017-11-24 11:44:57 +00001238 FuPluginUsbDeviceAddedFunc func = NULL;
Richard Hughescd2fb3e2018-11-29 19:58:09 +00001239 g_autoptr(GError) error_local = NULL;
Richard Hughes104f6512017-11-24 11:44:57 +00001240
1241 /* not enabled */
1242 if (!priv->enabled)
1243 return TRUE;
Richard Hughes639da472018-01-06 22:35:04 +00001244
1245 /* no object loaded */
Richard Hughes104f6512017-11-24 11:44:57 +00001246 if (priv->module == NULL)
1247 return TRUE;
1248
1249 /* optional */
1250 g_module_symbol (priv->module, "fu_plugin_usb_device_added", (gpointer *) &func);
Richard Hughescd2fb3e2018-11-29 19:58:09 +00001251 if (func == NULL)
1252 return TRUE;
1253 g_debug ("performing usb_device_added() on %s", priv->name);
1254 if (!func (self, device, &error_local)) {
1255 if (error_local == NULL) {
1256 g_critical ("unset error in plugin %s for usb_device_added()",
1257 priv->name);
1258 g_set_error_literal (&error_local,
1259 FWUPD_ERROR,
1260 FWUPD_ERROR_INTERNAL,
1261 "unspecified error");
1262 }
1263 g_propagate_prefixed_error (error, g_steal_pointer (&error_local),
1264 "failed to add device using on %s: ",
1265 priv->name);
1266 return FALSE;
Richard Hughes104f6512017-11-24 11:44:57 +00001267 }
1268 return TRUE;
1269}
1270
Richard Hughes9d6e0e72018-08-24 20:20:17 +01001271gboolean
Richard Hughes12724852018-09-04 13:53:44 +01001272fu_plugin_runner_udev_device_added (FuPlugin *self, FuUdevDevice *device, GError **error)
Richard Hughes9d6e0e72018-08-24 20:20:17 +01001273{
Richard Hughes12724852018-09-04 13:53:44 +01001274 FuPluginPrivate *priv = GET_PRIVATE (self);
Richard Hughes9d6e0e72018-08-24 20:20:17 +01001275 FuPluginUdevDeviceAddedFunc func = NULL;
Richard Hughescd2fb3e2018-11-29 19:58:09 +00001276 g_autoptr(GError) error_local = NULL;
Richard Hughes9d6e0e72018-08-24 20:20:17 +01001277
1278 /* not enabled */
1279 if (!priv->enabled)
1280 return TRUE;
1281
1282 /* no object loaded */
1283 if (priv->module == NULL)
1284 return TRUE;
1285
1286 /* optional */
1287 g_module_symbol (priv->module, "fu_plugin_udev_device_added", (gpointer *) &func);
Richard Hughescd2fb3e2018-11-29 19:58:09 +00001288 if (func == NULL)
1289 return TRUE;
1290 g_debug ("performing udev_device_added() on %s", priv->name);
1291 if (!func (self, device, &error_local)) {
1292 if (error_local == NULL) {
1293 g_critical ("unset error in plugin %s for udev_device_added()",
1294 priv->name);
1295 g_set_error_literal (&error_local,
1296 FWUPD_ERROR,
1297 FWUPD_ERROR_INTERNAL,
1298 "unspecified error");
1299 }
1300 g_propagate_prefixed_error (error, g_steal_pointer (&error_local),
1301 "failed to add device using on %s: ",
1302 priv->name);
1303 return FALSE;
Richard Hughes9d6e0e72018-08-24 20:20:17 +01001304 }
1305 return TRUE;
1306}
1307
Richard Hughese1fd34d2017-08-24 14:19:51 +01001308void
Richard Hughes12724852018-09-04 13:53:44 +01001309fu_plugin_runner_device_removed (FuPlugin *self, FuDevice *device)
Mario Limoncielloe260ead2018-09-01 09:19:24 -05001310{
1311 g_autoptr(GError) error_local= NULL;
1312
Richard Hughes12724852018-09-04 13:53:44 +01001313 if (!fu_plugin_runner_device_generic (self, device,
Mario Limoncielloe260ead2018-09-01 09:19:24 -05001314 "fu_plugin_device_removed",
1315 &error_local))
1316 g_warning ("%s", error_local->message);
1317}
1318
1319void
Richard Hughes12724852018-09-04 13:53:44 +01001320fu_plugin_runner_device_register (FuPlugin *self, FuDevice *device)
Richard Hughese1fd34d2017-08-24 14:19:51 +01001321{
Richard Hughes12724852018-09-04 13:53:44 +01001322 FuPluginPrivate *priv = GET_PRIVATE (self);
Richard Hughese1fd34d2017-08-24 14:19:51 +01001323 FuPluginDeviceRegisterFunc func = NULL;
1324
1325 /* not enabled */
1326 if (!priv->enabled)
1327 return;
Richard Hughes34834102017-11-21 21:55:00 +00001328 if (priv->module == NULL)
1329 return;
Richard Hughese1fd34d2017-08-24 14:19:51 +01001330
Mario Limonciello4910b242018-06-22 15:04:21 -05001331 /* don't notify plugins on their own devices */
Richard Hughes12724852018-09-04 13:53:44 +01001332 if (g_strcmp0 (fu_device_get_plugin (device), fu_plugin_get_name (self)) == 0)
Mario Limonciello4910b242018-06-22 15:04:21 -05001333 return;
1334
Richard Hughese1fd34d2017-08-24 14:19:51 +01001335 /* optional */
1336 g_module_symbol (priv->module, "fu_plugin_device_registered", (gpointer *) &func);
1337 if (func != NULL) {
Richard Hughes1bf7ff92018-08-24 20:21:35 +01001338 g_debug ("performing fu_plugin_device_registered() on %s", priv->name);
Richard Hughes12724852018-09-04 13:53:44 +01001339 func (self, device);
Richard Hughese1fd34d2017-08-24 14:19:51 +01001340 }
1341}
1342
Richard Hughesc6c312f2019-02-01 16:37:14 +00001343gboolean
Richard Hughes12724852018-09-04 13:53:44 +01001344fu_plugin_runner_schedule_update (FuPlugin *self,
Richard Hughescff38bc2016-12-12 12:03:37 +00001345 FuDevice *device,
1346 GBytes *blob_cab,
1347 GError **error)
1348{
Richard Hughes38fb56c2018-02-01 22:07:52 +00001349 FwupdRelease *release;
Richard Hughescff38bc2016-12-12 12:03:37 +00001350 gchar tmpname[] = {"XXXXXX.cap"};
1351 g_autofree gchar *dirname = NULL;
1352 g_autofree gchar *filename = NULL;
Richard Hughes68982c62017-09-13 15:40:14 +01001353 g_autoptr(FuDevice) res_tmp = NULL;
Richard Hughes780ef3f2018-01-12 16:20:31 +00001354 g_autoptr(FuHistory) history = NULL;
Richard Hughes38fb56c2018-02-01 22:07:52 +00001355 g_autoptr(FwupdRelease) release_tmp = fwupd_release_new ();
Richard Hughescff38bc2016-12-12 12:03:37 +00001356 g_autoptr(GFile) file = NULL;
1357
1358 /* id already exists */
Richard Hughes780ef3f2018-01-12 16:20:31 +00001359 history = fu_history_new ();
Richard Hughes0b9d9962018-01-12 16:31:28 +00001360 res_tmp = fu_history_get_device_by_id (history, fu_device_get_id (device), NULL);
Richard Hughes42a1b9a2019-03-21 17:05:19 +00001361 if (res_tmp != NULL &&
1362 fu_device_get_update_state (res_tmp) == FWUPD_UPDATE_STATE_PENDING) {
Richard Hughescff38bc2016-12-12 12:03:37 +00001363 g_set_error (error,
1364 FWUPD_ERROR,
1365 FWUPD_ERROR_ALREADY_PENDING,
1366 "%s is already scheduled to be updated",
1367 fu_device_get_id (device));
1368 return FALSE;
1369 }
1370
1371 /* create directory */
Richard Hughes4be17d12018-05-30 20:36:29 +01001372 dirname = fu_common_get_path (FU_PATH_KIND_LOCALSTATEDIR_PKG);
Richard Hughescff38bc2016-12-12 12:03:37 +00001373 file = g_file_new_for_path (dirname);
1374 if (!g_file_query_exists (file, NULL)) {
1375 if (!g_file_make_directory_with_parents (file, NULL, error))
1376 return FALSE;
1377 }
1378
1379 /* get a random filename */
1380 for (guint i = 0; i < 6; i++)
1381 tmpname[i] = (gchar) g_random_int_range ('A', 'Z');
1382 filename = g_build_filename (dirname, tmpname, NULL);
1383
1384 /* just copy to the temp file */
Richard Hughes23135eb2017-11-30 21:01:25 +00001385 fu_device_set_status (device, FWUPD_STATUS_SCHEDULING);
Richard Hughescff38bc2016-12-12 12:03:37 +00001386 if (!g_file_set_contents (filename,
1387 g_bytes_get_data (blob_cab, NULL),
1388 (gssize) g_bytes_get_size (blob_cab),
1389 error))
1390 return FALSE;
1391
1392 /* schedule for next boot */
1393 g_debug ("schedule %s to be installed to %s on next boot",
1394 filename, fu_device_get_id (device));
Richard Hughes38fb56c2018-02-01 22:07:52 +00001395 release = fu_device_get_release_default (device);
1396 fwupd_release_set_version (release_tmp, fwupd_release_get_version (release));
1397 fwupd_release_set_filename (release_tmp, filename);
Richard Hughescff38bc2016-12-12 12:03:37 +00001398
1399 /* add to database */
Richard Hughes3e90a582018-01-06 22:38:09 +00001400 fu_device_set_update_state (device, FWUPD_UPDATE_STATE_PENDING);
Richard Hughes38fb56c2018-02-01 22:07:52 +00001401 if (!fu_history_add_device (history, device, release_tmp, error))
Richard Hughescff38bc2016-12-12 12:03:37 +00001402 return FALSE;
1403
1404 /* next boot we run offline */
Richard Hughesdb69c812019-03-22 16:10:15 +00001405 fu_device_set_progress (device, 100);
Richard Hughescff38bc2016-12-12 12:03:37 +00001406 return fu_plugin_runner_offline_setup (error);
1407}
1408
1409gboolean
Richard Hughes12724852018-09-04 13:53:44 +01001410fu_plugin_runner_verify (FuPlugin *self,
Richard Hughescff38bc2016-12-12 12:03:37 +00001411 FuDevice *device,
1412 FuPluginVerifyFlags flags,
1413 GError **error)
1414{
Richard Hughes12724852018-09-04 13:53:44 +01001415 FuPluginPrivate *priv = GET_PRIVATE (self);
Richard Hughes7b8b2022016-12-12 16:15:03 +00001416 FuPluginVerifyFunc func = NULL;
Richard Hughesababbb72017-06-15 20:18:36 +01001417 GPtrArray *checksums;
Richard Hughescd2fb3e2018-11-29 19:58:09 +00001418 g_autoptr(GError) error_local = NULL;
Richard Hughescff38bc2016-12-12 12:03:37 +00001419
1420 /* not enabled */
1421 if (!priv->enabled)
1422 return TRUE;
1423
Richard Hughes639da472018-01-06 22:35:04 +00001424 /* no object loaded */
1425 if (priv->module == NULL)
1426 return TRUE;
1427
Richard Hughescff38bc2016-12-12 12:03:37 +00001428 /* optional */
1429 g_module_symbol (priv->module, "fu_plugin_verify", (gpointer *) &func);
1430 if (func == NULL)
1431 return TRUE;
Richard Hughes1812fc72018-12-14 11:37:54 +00001432
1433 /* clear any existing verification checksums */
1434 checksums = fu_device_get_checksums (device);
1435 g_ptr_array_set_size (checksums, 0);
1436
Richard Hughesc9223be2019-03-18 08:46:42 +00001437 /* run additional detach */
1438 if (!fu_plugin_runner_device_generic (self, device,
1439 "fu_plugin_verify_detach",
1440 error))
1441 return FALSE;
1442
Richard Hughes1812fc72018-12-14 11:37:54 +00001443 /* run vfunc */
Richard Hughescff38bc2016-12-12 12:03:37 +00001444 g_debug ("performing verify() on %s", priv->name);
Richard Hughescd2fb3e2018-11-29 19:58:09 +00001445 if (!func (self, device, flags, &error_local)) {
Richard Hughesc9223be2019-03-18 08:46:42 +00001446 g_autoptr(GError) error_attach = NULL;
Richard Hughescd2fb3e2018-11-29 19:58:09 +00001447 if (error_local == NULL) {
1448 g_critical ("unset error in plugin %s for verify()",
1449 priv->name);
1450 g_set_error_literal (&error_local,
1451 FWUPD_ERROR,
1452 FWUPD_ERROR_INTERNAL,
1453 "unspecified error");
1454 }
1455 g_propagate_prefixed_error (error, g_steal_pointer (&error_local),
1456 "failed to verify using %s: ",
1457 priv->name);
Richard Hughesc9223be2019-03-18 08:46:42 +00001458 /* make the device "work" again, but don't prefix the error */
1459 if (!fu_plugin_runner_device_generic (self, device,
1460 "fu_plugin_verify_attach",
1461 &error_attach)) {
1462 g_warning ("failed to attach whilst aborting verify(): %s",
1463 error_attach->message);
1464 }
Richard Hughesd0905142016-03-13 09:46:49 +00001465 return FALSE;
1466 }
Richard Hughesc9223be2019-03-18 08:46:42 +00001467
1468 /* run optional attach */
1469 if (!fu_plugin_runner_device_generic (self, device,
1470 "fu_plugin_verify_attach",
1471 error))
1472 return FALSE;
1473
1474 /* success */
Richard Hughesd0905142016-03-13 09:46:49 +00001475 return TRUE;
1476}
1477
Richard Hughesd0905142016-03-13 09:46:49 +00001478gboolean
Mario Limonciello96a0dd52019-02-25 13:50:03 -06001479fu_plugin_runner_activate (FuPlugin *self, FuDevice *device, GError **error)
1480{
1481 guint64 flags;
1482
1483 /* final check */
1484 flags = fu_device_get_flags (device);
1485 if ((flags & FWUPD_DEVICE_FLAG_NEEDS_ACTIVATION) == 0) {
1486 g_set_error (error,
1487 FWUPD_ERROR,
1488 FWUPD_ERROR_NOT_SUPPORTED,
1489 "Device %s does not need activation",
1490 fu_device_get_id (device));
1491 return FALSE;
1492 }
1493
1494 /* run vfunc */
1495 if (!fu_plugin_runner_device_generic (self, device,
1496 "fu_plugin_activate", error))
1497 return FALSE;
1498
1499 /* update with correct flags */
1500 fu_device_remove_flag (device, FWUPD_DEVICE_FLAG_NEEDS_ACTIVATION);
1501 fu_device_set_modified (device, (guint64) g_get_real_time () / G_USEC_PER_SEC);
1502 return TRUE;
1503}
1504
1505gboolean
Richard Hughes12724852018-09-04 13:53:44 +01001506fu_plugin_runner_unlock (FuPlugin *self, FuDevice *device, GError **error)
Richard Hughesd0905142016-03-13 09:46:49 +00001507{
Richard Hughescff38bc2016-12-12 12:03:37 +00001508 guint64 flags;
Richard Hughescff38bc2016-12-12 12:03:37 +00001509
1510 /* final check */
1511 flags = fu_device_get_flags (device);
1512 if ((flags & FWUPD_DEVICE_FLAG_LOCKED) == 0) {
1513 g_set_error (error,
1514 FWUPD_ERROR,
1515 FWUPD_ERROR_NOT_SUPPORTED,
1516 "Device %s is not locked",
1517 fu_device_get_id (device));
1518 return FALSE;
1519 }
1520
Richard Hughes9c4b5312017-11-14 11:34:53 +00001521 /* run vfunc */
Richard Hughes12724852018-09-04 13:53:44 +01001522 if (!fu_plugin_runner_device_generic (self, device,
Richard Hughes9c4b5312017-11-14 11:34:53 +00001523 "fu_plugin_unlock", error))
1524 return FALSE;
Richard Hughescff38bc2016-12-12 12:03:37 +00001525
1526 /* update with correct flags */
1527 flags = fu_device_get_flags (device);
1528 fu_device_set_flags (device, flags &= ~FWUPD_DEVICE_FLAG_LOCKED);
1529 fu_device_set_modified (device, (guint64) g_get_real_time () / G_USEC_PER_SEC);
1530 return TRUE;
1531}
1532
1533gboolean
Richard Hughes12724852018-09-04 13:53:44 +01001534fu_plugin_runner_update (FuPlugin *self,
Richard Hughesa785a1c2017-08-25 16:00:58 +01001535 FuDevice *device,
Richard Hughesa785a1c2017-08-25 16:00:58 +01001536 GBytes *blob_fw,
1537 FwupdInstallFlags flags,
1538 GError **error)
Richard Hughescff38bc2016-12-12 12:03:37 +00001539{
Richard Hughes12724852018-09-04 13:53:44 +01001540 FuPluginPrivate *priv = GET_PRIVATE (self);
Richard Hughesa785a1c2017-08-25 16:00:58 +01001541 FuPluginUpdateFunc update_func;
Richard Hughes780ef3f2018-01-12 16:20:31 +00001542 g_autoptr(FuHistory) history = NULL;
Richard Hughes68982c62017-09-13 15:40:14 +01001543 g_autoptr(FuDevice) device_pending = NULL;
Richard Hughescd2fb3e2018-11-29 19:58:09 +00001544 g_autoptr(GError) error_local = NULL;
Richard Hughescff38bc2016-12-12 12:03:37 +00001545
1546 /* not enabled */
Richard Hughes41c15482018-02-01 22:07:21 +00001547 if (!priv->enabled) {
1548 g_debug ("plugin not enabled, skipping");
Richard Hughesd0905142016-03-13 09:46:49 +00001549 return TRUE;
Richard Hughes41c15482018-02-01 22:07:21 +00001550 }
Richard Hughesd0905142016-03-13 09:46:49 +00001551
Richard Hughes639da472018-01-06 22:35:04 +00001552 /* no object loaded */
Richard Hughes41c15482018-02-01 22:07:21 +00001553 if (priv->module == NULL) {
1554 g_debug ("module not enabled, skipping");
Richard Hughes639da472018-01-06 22:35:04 +00001555 return TRUE;
Richard Hughes41c15482018-02-01 22:07:21 +00001556 }
Richard Hughes639da472018-01-06 22:35:04 +00001557
Richard Hughesd0905142016-03-13 09:46:49 +00001558 /* optional */
Richard Hughesa785a1c2017-08-25 16:00:58 +01001559 g_module_symbol (priv->module, "fu_plugin_update", (gpointer *) &update_func);
1560 if (update_func == NULL) {
1561 g_set_error_literal (error,
1562 FWUPD_ERROR,
1563 FWUPD_ERROR_NOT_SUPPORTED,
1564 "No update possible");
1565 return FALSE;
1566 }
Richard Hughesd0905142016-03-13 09:46:49 +00001567
Richard Hughescff38bc2016-12-12 12:03:37 +00001568 /* cancel the pending action */
1569 if (!fu_plugin_runner_offline_invalidate (error))
1570 return FALSE;
1571
1572 /* online */
Richard Hughes780ef3f2018-01-12 16:20:31 +00001573 history = fu_history_new ();
Richard Hughes0b9d9962018-01-12 16:31:28 +00001574 device_pending = fu_history_get_device_by_id (history, fu_device_get_id (device), NULL);
Richard Hughescd2fb3e2018-11-29 19:58:09 +00001575 if (!update_func (self, device, blob_fw, flags, &error_local)) {
1576 if (error_local == NULL) {
1577 g_critical ("unset error in plugin %s for update()",
1578 priv->name);
1579 g_set_error_literal (&error_local,
Richard Hughes3c8ada32018-10-12 10:08:58 +01001580 FWUPD_ERROR,
1581 FWUPD_ERROR_INTERNAL,
1582 "unspecified error");
Richard Hughescd2fb3e2018-11-29 19:58:09 +00001583 return FALSE;
Richard Hughes3c8ada32018-10-12 10:08:58 +01001584 }
Richard Hughescd2fb3e2018-11-29 19:58:09 +00001585 fu_device_set_update_error (device, error_local->message);
1586 g_propagate_error (error, g_steal_pointer (&error_local));
Richard Hughescff38bc2016-12-12 12:03:37 +00001587 return FALSE;
1588 }
1589
Richard Hughesf556d372017-06-15 19:49:18 +01001590 /* no longer valid */
Richard Hughesf8039642019-01-16 12:22:22 +00001591 if (!fu_device_has_flag (device, FWUPD_DEVICE_FLAG_NEEDS_REBOOT) &&
1592 !fu_device_has_flag (device, FWUPD_DEVICE_FLAG_NEEDS_SHUTDOWN)) {
Richard Hughes08435162018-12-12 10:34:16 +00001593 GPtrArray *checksums = fu_device_get_checksums (device);
1594 g_ptr_array_set_size (checksums, 0);
1595 }
Richard Hughesf556d372017-06-15 19:49:18 +01001596
Richard Hughescff38bc2016-12-12 12:03:37 +00001597 /* cleanup */
Richard Hughes68982c62017-09-13 15:40:14 +01001598 if (device_pending != NULL) {
Richard Hughescff38bc2016-12-12 12:03:37 +00001599 const gchar *tmp;
Richard Hughesbc3a4e12018-01-06 22:41:47 +00001600 FwupdRelease *release;
Richard Hughescff38bc2016-12-12 12:03:37 +00001601
Richard Hughes780ef3f2018-01-12 16:20:31 +00001602 /* update history database */
Richard Hughesc0cd0232018-01-31 15:02:00 +00001603 fu_device_set_update_state (device, FWUPD_UPDATE_STATE_SUCCESS);
1604 if (!fu_history_modify_device (history, device,
1605 FU_HISTORY_FLAGS_MATCH_NEW_VERSION,
1606 error))
Richard Hughes0b9d9962018-01-12 16:31:28 +00001607 return FALSE;
Richard Hughescff38bc2016-12-12 12:03:37 +00001608
1609 /* delete cab file */
Richard Hughesbc3a4e12018-01-06 22:41:47 +00001610 release = fu_device_get_release_default (device_pending);
1611 tmp = fwupd_release_get_filename (release);
Richard Hughescff38bc2016-12-12 12:03:37 +00001612 if (tmp != NULL && g_str_has_prefix (tmp, LIBEXECDIR)) {
Richard Hughescd2fb3e2018-11-29 19:58:09 +00001613 g_autoptr(GError) error_delete = NULL;
Richard Hughescff38bc2016-12-12 12:03:37 +00001614 g_autoptr(GFile) file = NULL;
1615 file = g_file_new_for_path (tmp);
Richard Hughescd2fb3e2018-11-29 19:58:09 +00001616 if (!g_file_delete (file, NULL, &error_delete)) {
Richard Hughescff38bc2016-12-12 12:03:37 +00001617 g_set_error (error,
1618 FWUPD_ERROR,
1619 FWUPD_ERROR_INVALID_FILE,
1620 "Failed to delete %s: %s",
Richard Hughescd2fb3e2018-11-29 19:58:09 +00001621 tmp, error_delete->message);
Richard Hughescff38bc2016-12-12 12:03:37 +00001622 return FALSE;
1623 }
1624 }
1625 }
Richard Hughesd0905142016-03-13 09:46:49 +00001626 return TRUE;
1627}
Richard Hughescff38bc2016-12-12 12:03:37 +00001628
1629gboolean
Richard Hughes12724852018-09-04 13:53:44 +01001630fu_plugin_runner_clear_results (FuPlugin *self, FuDevice *device, GError **error)
Richard Hughescff38bc2016-12-12 12:03:37 +00001631{
Richard Hughes12724852018-09-04 13:53:44 +01001632 FuPluginPrivate *priv = GET_PRIVATE (self);
Richard Hughes7b8b2022016-12-12 16:15:03 +00001633 FuPluginDeviceFunc func = NULL;
Richard Hughescd2fb3e2018-11-29 19:58:09 +00001634 g_autoptr(GError) error_local = NULL;
Richard Hughescff38bc2016-12-12 12:03:37 +00001635
1636 /* not enabled */
1637 if (!priv->enabled)
1638 return TRUE;
1639
Richard Hughes639da472018-01-06 22:35:04 +00001640 /* no object loaded */
1641 if (priv->module == NULL)
1642 return TRUE;
1643
Richard Hughes65e44ca2018-01-30 17:26:30 +00001644 /* optional */
1645 g_module_symbol (priv->module, "fu_plugin_get_results", (gpointer *) &func);
1646 if (func == NULL)
Richard Hughescff38bc2016-12-12 12:03:37 +00001647 return TRUE;
Richard Hughes65e44ca2018-01-30 17:26:30 +00001648 g_debug ("performing clear_result() on %s", priv->name);
Richard Hughescd2fb3e2018-11-29 19:58:09 +00001649 if (!func (self, device, &error_local)) {
1650 if (error_local == NULL) {
1651 g_critical ("unset error in plugin %s for clear_result()",
1652 priv->name);
1653 g_set_error_literal (&error_local,
1654 FWUPD_ERROR,
1655 FWUPD_ERROR_INTERNAL,
1656 "unspecified error");
1657 }
1658 g_propagate_prefixed_error (error, g_steal_pointer (&error_local),
1659 "failed to clear_result using %s: ",
1660 priv->name);
Richard Hughescff38bc2016-12-12 12:03:37 +00001661 return FALSE;
1662 }
Richard Hughes65e44ca2018-01-30 17:26:30 +00001663 return TRUE;
Richard Hughescff38bc2016-12-12 12:03:37 +00001664}
1665
1666gboolean
Richard Hughes12724852018-09-04 13:53:44 +01001667fu_plugin_runner_get_results (FuPlugin *self, FuDevice *device, GError **error)
Richard Hughescff38bc2016-12-12 12:03:37 +00001668{
Richard Hughes12724852018-09-04 13:53:44 +01001669 FuPluginPrivate *priv = GET_PRIVATE (self);
Richard Hughes7b8b2022016-12-12 16:15:03 +00001670 FuPluginDeviceFunc func = NULL;
Richard Hughescd2fb3e2018-11-29 19:58:09 +00001671 g_autoptr(GError) error_local = NULL;
Richard Hughescff38bc2016-12-12 12:03:37 +00001672
1673 /* not enabled */
1674 if (!priv->enabled)
1675 return TRUE;
1676
Richard Hughes639da472018-01-06 22:35:04 +00001677 /* no object loaded */
1678 if (priv->module == NULL)
1679 return TRUE;
1680
Richard Hughes65e44ca2018-01-30 17:26:30 +00001681 /* optional */
Richard Hughescff38bc2016-12-12 12:03:37 +00001682 g_module_symbol (priv->module, "fu_plugin_get_results", (gpointer *) &func);
Richard Hughes65e44ca2018-01-30 17:26:30 +00001683 if (func == NULL)
Richard Hughescff38bc2016-12-12 12:03:37 +00001684 return TRUE;
Richard Hughes65e44ca2018-01-30 17:26:30 +00001685 g_debug ("performing get_results() on %s", priv->name);
Richard Hughescd2fb3e2018-11-29 19:58:09 +00001686 if (!func (self, device, &error_local)) {
1687 if (error_local == NULL) {
1688 g_critical ("unset error in plugin %s for get_results()",
1689 priv->name);
1690 g_set_error_literal (&error_local,
1691 FWUPD_ERROR,
1692 FWUPD_ERROR_INTERNAL,
1693 "unspecified error");
1694 }
1695 g_propagate_prefixed_error (error, g_steal_pointer (&error_local),
1696 "failed to get_results using %s: ",
1697 priv->name);
Richard Hughescff38bc2016-12-12 12:03:37 +00001698 return FALSE;
1699 }
Richard Hughescff38bc2016-12-12 12:03:37 +00001700 return TRUE;
1701}
1702
Richard Hughes08a37992017-09-12 12:57:43 +01001703/**
1704 * fu_plugin_get_order:
Richard Hughes2c0635a2018-09-04 14:52:46 +01001705 * @self: a #FuPlugin
Richard Hughes08a37992017-09-12 12:57:43 +01001706 *
1707 * Gets the plugin order, where higher numbers are run after lower
1708 * numbers.
1709 *
1710 * Returns: the integer value
1711 **/
1712guint
Richard Hughes12724852018-09-04 13:53:44 +01001713fu_plugin_get_order (FuPlugin *self)
Richard Hughes08a37992017-09-12 12:57:43 +01001714{
Richard Hughes12724852018-09-04 13:53:44 +01001715 FuPluginPrivate *priv = fu_plugin_get_instance_private (self);
Richard Hughes08a37992017-09-12 12:57:43 +01001716 return priv->order;
1717}
1718
1719/**
1720 * fu_plugin_set_order:
Richard Hughes2c0635a2018-09-04 14:52:46 +01001721 * @self: a #FuPlugin
Richard Hughes08a37992017-09-12 12:57:43 +01001722 * @order: a integer value
1723 *
1724 * Sets the plugin order, where higher numbers are run after lower
1725 * numbers.
1726 **/
1727void
Richard Hughes12724852018-09-04 13:53:44 +01001728fu_plugin_set_order (FuPlugin *self, guint order)
Richard Hughes08a37992017-09-12 12:57:43 +01001729{
Richard Hughes12724852018-09-04 13:53:44 +01001730 FuPluginPrivate *priv = fu_plugin_get_instance_private (self);
Richard Hughes08a37992017-09-12 12:57:43 +01001731 priv->order = order;
1732}
1733
1734/**
Richard Hughes81c427c2018-08-06 15:20:17 +01001735 * fu_plugin_get_priority:
Richard Hughes2c0635a2018-09-04 14:52:46 +01001736 * @self: a #FuPlugin
Richard Hughes81c427c2018-08-06 15:20:17 +01001737 *
1738 * Gets the plugin priority, where higher numbers are better.
1739 *
1740 * Returns: the integer value
1741 **/
1742guint
Richard Hughes12724852018-09-04 13:53:44 +01001743fu_plugin_get_priority (FuPlugin *self)
Richard Hughes81c427c2018-08-06 15:20:17 +01001744{
Richard Hughes12724852018-09-04 13:53:44 +01001745 FuPluginPrivate *priv = fu_plugin_get_instance_private (self);
Richard Hughes81c427c2018-08-06 15:20:17 +01001746 return priv->priority;
1747}
1748
1749/**
1750 * fu_plugin_set_priority:
Richard Hughes2c0635a2018-09-04 14:52:46 +01001751 * @self: a #FuPlugin
Richard Hughes81c427c2018-08-06 15:20:17 +01001752 * @priority: a integer value
1753 *
1754 * Sets the plugin priority, where higher numbers are better.
1755 **/
1756void
Richard Hughes12724852018-09-04 13:53:44 +01001757fu_plugin_set_priority (FuPlugin *self, guint priority)
Richard Hughes81c427c2018-08-06 15:20:17 +01001758{
Richard Hughes12724852018-09-04 13:53:44 +01001759 FuPluginPrivate *priv = fu_plugin_get_instance_private (self);
Richard Hughes81c427c2018-08-06 15:20:17 +01001760 priv->priority = priority;
1761}
1762
1763/**
Richard Hughes08a37992017-09-12 12:57:43 +01001764 * fu_plugin_add_rule:
Richard Hughes2c0635a2018-09-04 14:52:46 +01001765 * @self: a #FuPlugin
Richard Hughes08a37992017-09-12 12:57:43 +01001766 * @rule: a #FuPluginRule, e.g. %FU_PLUGIN_RULE_CONFLICTS
Richard Hughes4eada342017-10-03 21:20:32 +01001767 * @name: a plugin name, e.g. `upower`
Richard Hughes08a37992017-09-12 12:57:43 +01001768 *
1769 * If the plugin name is found, the rule will be used to sort the plugin list,
1770 * for example the plugin specified by @name will be ordered after this plugin
1771 * when %FU_PLUGIN_RULE_RUN_AFTER is used.
1772 *
1773 * NOTE: The depsolver is iterative and may not solve overly-complicated rules;
1774 * If depsolving fails then fwupd will not start.
1775 **/
1776void
Richard Hughes12724852018-09-04 13:53:44 +01001777fu_plugin_add_rule (FuPlugin *self, FuPluginRule rule, const gchar *name)
Richard Hughes08a37992017-09-12 12:57:43 +01001778{
Richard Hughes12724852018-09-04 13:53:44 +01001779 FuPluginPrivate *priv = fu_plugin_get_instance_private (self);
Richard Hughes08a37992017-09-12 12:57:43 +01001780 g_ptr_array_add (priv->rules[rule], g_strdup (name));
Richard Hughes75b965d2018-11-15 13:51:21 +00001781 g_signal_emit (self, signals[SIGNAL_RULES_CHANGED], 0);
Richard Hughes08a37992017-09-12 12:57:43 +01001782}
1783
1784/**
1785 * fu_plugin_get_rules:
Richard Hughes2c0635a2018-09-04 14:52:46 +01001786 * @self: a #FuPlugin
Richard Hughes08a37992017-09-12 12:57:43 +01001787 * @rule: a #FuPluginRule, e.g. %FU_PLUGIN_RULE_CONFLICTS
1788 *
1789 * Gets the plugin IDs that should be run after this plugin.
1790 *
1791 * Returns: (element-type utf8) (transfer none): the list of plugin names, e.g. ['appstream']
1792 **/
1793GPtrArray *
Richard Hughes12724852018-09-04 13:53:44 +01001794fu_plugin_get_rules (FuPlugin *self, FuPluginRule rule)
Richard Hughes08a37992017-09-12 12:57:43 +01001795{
Richard Hughes12724852018-09-04 13:53:44 +01001796 FuPluginPrivate *priv = fu_plugin_get_instance_private (self);
Richard Hughes08a37992017-09-12 12:57:43 +01001797 return priv->rules[rule];
1798}
1799
Richard Hughes80b79bb2018-01-11 21:11:06 +00001800/**
Richard Hughes5f3a56b2018-06-28 12:13:59 +01001801 * fu_plugin_has_rule:
Richard Hughes2c0635a2018-09-04 14:52:46 +01001802 * @self: a #FuPlugin
Richard Hughes5f3a56b2018-06-28 12:13:59 +01001803 * @rule: a #FuPluginRule, e.g. %FU_PLUGIN_RULE_CONFLICTS
1804 * @name: a plugin name, e.g. `upower`
1805 *
Richard Hughes87fb9ff2018-06-28 12:55:59 +01001806 * Gets the plugin IDs that should be run after this plugin.
Richard Hughes5f3a56b2018-06-28 12:13:59 +01001807 *
1808 * Returns: %TRUE if the name exists for the specific rule
1809 **/
1810gboolean
Richard Hughes12724852018-09-04 13:53:44 +01001811fu_plugin_has_rule (FuPlugin *self, FuPluginRule rule, const gchar *name)
Richard Hughes5f3a56b2018-06-28 12:13:59 +01001812{
Richard Hughes12724852018-09-04 13:53:44 +01001813 FuPluginPrivate *priv = fu_plugin_get_instance_private (self);
Richard Hughes5f3a56b2018-06-28 12:13:59 +01001814 for (guint i = 0; i < priv->rules[rule]->len; i++) {
1815 const gchar *tmp = g_ptr_array_index (priv->rules[rule], i);
1816 if (g_strcmp0 (tmp, name) == 0)
1817 return TRUE;
1818 }
1819 return FALSE;
1820}
1821
1822/**
Richard Hughes80b79bb2018-01-11 21:11:06 +00001823 * fu_plugin_add_report_metadata:
Richard Hughes2c0635a2018-09-04 14:52:46 +01001824 * @self: a #FuPlugin
Richard Hughes80b79bb2018-01-11 21:11:06 +00001825 * @key: a string, e.g. `FwupdateVersion`
1826 * @value: a string, e.g. `10`
1827 *
1828 * Sets any additional metadata to be included in the firmware report to aid
1829 * debugging problems.
1830 *
1831 * Any data included here will be sent to the metadata server after user
1832 * confirmation.
1833 **/
1834void
Richard Hughes12724852018-09-04 13:53:44 +01001835fu_plugin_add_report_metadata (FuPlugin *self, const gchar *key, const gchar *value)
Richard Hughes80b79bb2018-01-11 21:11:06 +00001836{
Richard Hughes12724852018-09-04 13:53:44 +01001837 FuPluginPrivate *priv = fu_plugin_get_instance_private (self);
Richard Hughes80b79bb2018-01-11 21:11:06 +00001838 g_hash_table_insert (priv->report_metadata, g_strdup (key), g_strdup (value));
1839}
1840
1841/**
1842 * fu_plugin_get_report_metadata:
Richard Hughes2c0635a2018-09-04 14:52:46 +01001843 * @self: a #FuPlugin
Richard Hughes80b79bb2018-01-11 21:11:06 +00001844 *
1845 * Returns the list of additional metadata to be added when filing a report.
1846 *
1847 * Returns: (transfer none): the map of report metadata
1848 **/
1849GHashTable *
Richard Hughes12724852018-09-04 13:53:44 +01001850fu_plugin_get_report_metadata (FuPlugin *self)
Richard Hughes80b79bb2018-01-11 21:11:06 +00001851{
Richard Hughes12724852018-09-04 13:53:44 +01001852 FuPluginPrivate *priv = fu_plugin_get_instance_private (self);
Richard Hughes80b79bb2018-01-11 21:11:06 +00001853 return priv->report_metadata;
1854}
1855
Mario Limonciello963dc422018-02-27 14:26:58 -06001856/**
1857 * fu_plugin_get_config_value:
Richard Hughes2c0635a2018-09-04 14:52:46 +01001858 * @self: a #FuPlugin
Mario Limonciello963dc422018-02-27 14:26:58 -06001859 * @key: A settings key
1860 *
1861 * Return the value of a key if it's been configured
1862 *
1863 * Since: 1.0.6
1864 **/
1865gchar *
Richard Hughes12724852018-09-04 13:53:44 +01001866fu_plugin_get_config_value (FuPlugin *self, const gchar *key)
Mario Limonciello963dc422018-02-27 14:26:58 -06001867{
Richard Hughes4be17d12018-05-30 20:36:29 +01001868 g_autofree gchar *conf_dir = NULL;
Mario Limonciello963dc422018-02-27 14:26:58 -06001869 g_autofree gchar *conf_file = NULL;
1870 g_autofree gchar *conf_path = NULL;
1871 g_autoptr(GKeyFile) keyfile = NULL;
1872 const gchar *plugin_name;
1873
Richard Hughes4be17d12018-05-30 20:36:29 +01001874 conf_dir = fu_common_get_path (FU_PATH_KIND_SYSCONFDIR_PKG);
Richard Hughes12724852018-09-04 13:53:44 +01001875 plugin_name = fu_plugin_get_name (self);
Mario Limonciello963dc422018-02-27 14:26:58 -06001876 conf_file = g_strdup_printf ("%s.conf", plugin_name);
Richard Hughes4be17d12018-05-30 20:36:29 +01001877 conf_path = g_build_filename (conf_dir, conf_file, NULL);
Mario Limonciello963dc422018-02-27 14:26:58 -06001878 if (!g_file_test (conf_path, G_FILE_TEST_IS_REGULAR))
1879 return NULL;
1880 keyfile = g_key_file_new ();
1881 if (!g_key_file_load_from_file (keyfile, conf_path,
1882 G_KEY_FILE_NONE, NULL))
1883 return NULL;
1884 return g_key_file_get_string (keyfile, plugin_name, key, NULL);
1885}
1886
Richard Hughes8c71a3f2018-05-22 19:19:52 +01001887/**
1888 * fu_plugin_name_compare:
1889 * @plugin1: first #FuPlugin to compare.
1890 * @plugin2: second #FuPlugin to compare.
1891 *
1892 * Compares two plugins by their names.
1893 *
1894 * Returns: 1, 0 or -1 if @plugin1 is greater, equal, or less than @plugin2.
1895 **/
1896gint
1897fu_plugin_name_compare (FuPlugin *plugin1, FuPlugin *plugin2)
1898{
1899 FuPluginPrivate *priv1 = fu_plugin_get_instance_private (plugin1);
1900 FuPluginPrivate *priv2 = fu_plugin_get_instance_private (plugin2);
1901 return g_strcmp0 (priv1->name, priv2->name);
1902}
1903
1904/**
1905 * fu_plugin_order_compare:
1906 * @plugin1: first #FuPlugin to compare.
1907 * @plugin2: second #FuPlugin to compare.
1908 *
1909 * Compares two plugins by their depsolved order.
1910 *
1911 * Returns: 1, 0 or -1 if @plugin1 is greater, equal, or less than @plugin2.
1912 **/
1913gint
1914fu_plugin_order_compare (FuPlugin *plugin1, FuPlugin *plugin2)
1915{
1916 FuPluginPrivate *priv1 = fu_plugin_get_instance_private (plugin1);
1917 FuPluginPrivate *priv2 = fu_plugin_get_instance_private (plugin2);
1918 if (priv1->order < priv2->order)
1919 return -1;
1920 if (priv1->order > priv2->order)
1921 return 1;
1922 return 0;
1923}
1924
Richard Hughescff38bc2016-12-12 12:03:37 +00001925static void
1926fu_plugin_class_init (FuPluginClass *klass)
1927{
1928 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1929 object_class->finalize = fu_plugin_finalize;
1930 signals[SIGNAL_DEVICE_ADDED] =
1931 g_signal_new ("device-added",
1932 G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
1933 G_STRUCT_OFFSET (FuPluginClass, device_added),
1934 NULL, NULL, g_cclosure_marshal_VOID__OBJECT,
1935 G_TYPE_NONE, 1, FU_TYPE_DEVICE);
1936 signals[SIGNAL_DEVICE_REMOVED] =
1937 g_signal_new ("device-removed",
1938 G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
1939 G_STRUCT_OFFSET (FuPluginClass, device_removed),
1940 NULL, NULL, g_cclosure_marshal_VOID__OBJECT,
1941 G_TYPE_NONE, 1, FU_TYPE_DEVICE);
Richard Hughese1fd34d2017-08-24 14:19:51 +01001942 signals[SIGNAL_DEVICE_REGISTER] =
1943 g_signal_new ("device-register",
1944 G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
1945 G_STRUCT_OFFSET (FuPluginClass, device_register),
1946 NULL, NULL, g_cclosure_marshal_VOID__OBJECT,
1947 G_TYPE_NONE, 1, FU_TYPE_DEVICE);
Richard Hughes362d6d72017-01-07 21:42:14 +00001948 signals[SIGNAL_RECOLDPLUG] =
1949 g_signal_new ("recoldplug",
1950 G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
1951 G_STRUCT_OFFSET (FuPluginClass, recoldplug),
1952 NULL, NULL, g_cclosure_marshal_VOID__VOID,
1953 G_TYPE_NONE, 0);
Richard Hughesb0829032017-01-10 09:27:08 +00001954 signals[SIGNAL_SET_COLDPLUG_DELAY] =
1955 g_signal_new ("set-coldplug-delay",
1956 G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
1957 G_STRUCT_OFFSET (FuPluginClass, set_coldplug_delay),
1958 NULL, NULL, g_cclosure_marshal_VOID__UINT,
1959 G_TYPE_NONE, 1, G_TYPE_UINT);
Richard Hughesaabdc372018-11-14 10:11:08 +00001960 signals[SIGNAL_CHECK_SUPPORTED] =
1961 g_signal_new ("check-supported",
1962 G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
1963 G_STRUCT_OFFSET (FuPluginClass, check_supported),
1964 NULL, NULL, g_cclosure_marshal_generic,
1965 G_TYPE_BOOLEAN, 1, G_TYPE_STRING);
Richard Hughes75b965d2018-11-15 13:51:21 +00001966 signals[SIGNAL_RULES_CHANGED] =
1967 g_signal_new ("rules-changed",
1968 G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
1969 G_STRUCT_OFFSET (FuPluginClass, rules_changed),
1970 NULL, NULL, g_cclosure_marshal_VOID__VOID,
1971 G_TYPE_NONE, 0);
Richard Hughescff38bc2016-12-12 12:03:37 +00001972}
1973
1974static void
Richard Hughes12724852018-09-04 13:53:44 +01001975fu_plugin_init (FuPlugin *self)
Richard Hughescff38bc2016-12-12 12:03:37 +00001976{
Richard Hughes12724852018-09-04 13:53:44 +01001977 FuPluginPrivate *priv = GET_PRIVATE (self);
Richard Hughescff38bc2016-12-12 12:03:37 +00001978 priv->enabled = TRUE;
1979 priv->devices = g_hash_table_new_full (g_str_hash, g_str_equal,
1980 g_free, (GDestroyNotify) g_object_unref);
Richard Hughes37d09432018-09-09 10:39:45 +01001981 priv->devices_mutex = fu_mutex_new (G_OBJECT_TYPE_NAME(self), "devices");
Richard Hughes80b79bb2018-01-11 21:11:06 +00001982 priv->report_metadata = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
Richard Hughes08a37992017-09-12 12:57:43 +01001983 for (guint i = 0; i < FU_PLUGIN_RULE_LAST; i++)
1984 priv->rules[i] = g_ptr_array_new_with_free_func (g_free);
Richard Hughescff38bc2016-12-12 12:03:37 +00001985}
1986
1987static void
1988fu_plugin_finalize (GObject *object)
1989{
Richard Hughes12724852018-09-04 13:53:44 +01001990 FuPlugin *self = FU_PLUGIN (object);
1991 FuPluginPrivate *priv = GET_PRIVATE (self);
Richard Hughescff38bc2016-12-12 12:03:37 +00001992 FuPluginInitFunc func = NULL;
1993
1994 /* optional */
1995 if (priv->module != NULL) {
1996 g_module_symbol (priv->module, "fu_plugin_destroy", (gpointer *) &func);
1997 if (func != NULL) {
1998 g_debug ("performing destroy() on %s", priv->name);
Richard Hughes12724852018-09-04 13:53:44 +01001999 func (self);
Richard Hughescff38bc2016-12-12 12:03:37 +00002000 }
2001 }
2002
Richard Hughes08a37992017-09-12 12:57:43 +01002003 for (guint i = 0; i < FU_PLUGIN_RULE_LAST; i++)
2004 g_ptr_array_unref (priv->rules[i]);
2005
Richard Hughescff38bc2016-12-12 12:03:37 +00002006 if (priv->usb_ctx != NULL)
2007 g_object_unref (priv->usb_ctx);
Richard Hughesb8f8db22017-04-25 15:56:00 +01002008 if (priv->hwids != NULL)
Richard Hughesd7704d42017-08-08 20:29:09 +01002009 g_object_unref (priv->hwids);
Richard Hughes9c028f02017-10-28 21:14:28 +01002010 if (priv->quirks != NULL)
2011 g_object_unref (priv->quirks);
Richard Hughes9d6e0e72018-08-24 20:20:17 +01002012 if (priv->udev_subsystems != NULL)
2013 g_ptr_array_unref (priv->udev_subsystems);
Richard Hughes49e5e052017-09-03 12:15:41 +01002014 if (priv->smbios != NULL)
2015 g_object_unref (priv->smbios);
Richard Hughes275d3b42018-04-20 16:40:37 +01002016 if (priv->runtime_versions != NULL)
2017 g_hash_table_unref (priv->runtime_versions);
Richard Hughes34e0dab2018-04-20 16:43:00 +01002018 if (priv->compile_versions != NULL)
2019 g_hash_table_unref (priv->compile_versions);
Richard Hughescff38bc2016-12-12 12:03:37 +00002020 g_hash_table_unref (priv->devices);
Richard Hughes80b79bb2018-01-11 21:11:06 +00002021 g_hash_table_unref (priv->report_metadata);
Richard Hughes37d09432018-09-09 10:39:45 +01002022 g_object_unref (priv->devices_mutex);
Richard Hughescff38bc2016-12-12 12:03:37 +00002023 g_free (priv->name);
2024 g_free (priv->data);
Mario Limonciello3f9a1c12018-06-06 14:06:40 -05002025 /* Must happen as the last step to avoid prematurely
2026 * freeing memory held by the plugin */
2027#ifndef RUNNING_ON_VALGRIND
2028 if (priv->module != NULL)
2029 g_module_close (priv->module);
2030#endif
Richard Hughescff38bc2016-12-12 12:03:37 +00002031
2032 G_OBJECT_CLASS (fu_plugin_parent_class)->finalize (object);
2033}
2034
2035FuPlugin *
2036fu_plugin_new (void)
2037{
Richard Hughes12724852018-09-04 13:53:44 +01002038 return FU_PLUGIN (g_object_new (FU_TYPE_PLUGIN, NULL));
Richard Hughescff38bc2016-12-12 12:03:37 +00002039}