blob: 10c5dbca6b616cf53f19ad7d7ade45dbb09ef00b [file] [log] [blame]
Richard Hughesd0905142016-03-13 09:46:49 +00001/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
2 *
Richard Hughesa785a1c2017-08-25 16:00:58 +01003 * Copyright (C) 2016-2017 Richard Hughes <richard@hughsie.com>
Richard Hughesd0905142016-03-13 09:46:49 +00004 *
5 * Licensed under the GNU General Public License Version 2
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 */
21
22#include "config.h"
23
Richard Hughescff38bc2016-12-12 12:03:37 +000024#include <fwupd.h>
25#include <gmodule.h>
26#include <appstream-glib.h>
27#include <errno.h>
28#include <string.h>
29#include <gio/gunixinputstream.h>
Mario Limonciello6d0aa3d2017-02-28 08:22:27 -060030#ifdef HAVE_VALGRIND
Richard Hughes576c0122017-02-24 09:47:00 +000031#include <valgrind.h>
Mario Limonciello6d0aa3d2017-02-28 08:22:27 -060032#endif /* HAVE_VALGRIND */
Richard Hughesd0905142016-03-13 09:46:49 +000033
Richard Hughes9dde04f2017-09-13 12:07:15 +010034#include "fu-device-private.h"
Richard Hughescff38bc2016-12-12 12:03:37 +000035#include "fu-plugin-private.h"
36#include "fu-pending.h"
Richard Hughesd0905142016-03-13 09:46:49 +000037
Richard Hughes4eada342017-10-03 21:20:32 +010038/**
39 * SECTION:fu-plugin
40 * @short_description: a daemon plugin
41 *
42 * An object that represents a plugin run by the daemon.
43 *
44 * See also: #FuDevice
45 */
46
Richard Hughesb0829032017-01-10 09:27:08 +000047#define FU_PLUGIN_COLDPLUG_DELAY_MAXIMUM 3000u /* ms */
48
Richard Hughescff38bc2016-12-12 12:03:37 +000049static void fu_plugin_finalize (GObject *object);
50
51typedef struct {
52 GModule *module;
53 GUsbContext *usb_ctx;
54 gboolean enabled;
Richard Hughes08a37992017-09-12 12:57:43 +010055 guint order;
56 GPtrArray *rules[FU_PLUGIN_RULE_LAST];
Richard Hughescff38bc2016-12-12 12:03:37 +000057 gchar *name;
Richard Hughesd7704d42017-08-08 20:29:09 +010058 FuHwids *hwids;
Richard Hughes9c028f02017-10-28 21:14:28 +010059 FuQuirks *quirks;
Richard Hughes1354ea92017-09-19 15:58:31 +010060 GPtrArray *supported_guids;
61 FuSmbios *smbios;
Richard Hughescff38bc2016-12-12 12:03:37 +000062 GHashTable *devices; /* platform_id:GObject */
Richard Hughesae3d65f2016-12-16 09:38:01 +000063 GHashTable *devices_delay; /* FuDevice:FuPluginHelper */
Richard Hughescff38bc2016-12-12 12:03:37 +000064 FuPluginData *data;
65} FuPluginPrivate;
66
67enum {
68 SIGNAL_DEVICE_ADDED,
69 SIGNAL_DEVICE_REMOVED,
Richard Hughese1fd34d2017-08-24 14:19:51 +010070 SIGNAL_DEVICE_REGISTER,
Richard Hughescff38bc2016-12-12 12:03:37 +000071 SIGNAL_STATUS_CHANGED,
72 SIGNAL_PERCENTAGE_CHANGED,
Richard Hughes362d6d72017-01-07 21:42:14 +000073 SIGNAL_RECOLDPLUG,
Richard Hughesb0829032017-01-10 09:27:08 +000074 SIGNAL_SET_COLDPLUG_DELAY,
Richard Hughescff38bc2016-12-12 12:03:37 +000075 SIGNAL_LAST
76};
77
78static guint signals[SIGNAL_LAST] = { 0 };
79
80G_DEFINE_TYPE_WITH_PRIVATE (FuPlugin, fu_plugin, G_TYPE_OBJECT)
81#define GET_PRIVATE(o) (fu_plugin_get_instance_private (o))
82
83typedef const gchar *(*FuPluginGetNameFunc) (void);
84typedef void (*FuPluginInitFunc) (FuPlugin *plugin);
85typedef gboolean (*FuPluginStartupFunc) (FuPlugin *plugin,
86 GError **error);
Richard Hughese1fd34d2017-08-24 14:19:51 +010087typedef void (*FuPluginDeviceRegisterFunc) (FuPlugin *plugin,
88 FuDevice *device);
Richard Hughescff38bc2016-12-12 12:03:37 +000089typedef gboolean (*FuPluginDeviceFunc) (FuPlugin *plugin,
90 FuDevice *device,
91 GError **error);
92typedef gboolean (*FuPluginVerifyFunc) (FuPlugin *plugin,
93 FuDevice *device,
94 FuPluginVerifyFlags flags,
95 GError **error);
96typedef gboolean (*FuPluginUpdateFunc) (FuPlugin *plugin,
97 FuDevice *device,
98 GBytes *blob_fw,
99 FwupdInstallFlags flags,
100 GError **error);
101
Richard Hughes57d18222017-01-10 16:02:59 +0000102/**
103 * fu_plugin_get_name:
104 * @plugin: A #FuPlugin
105 *
106 * Gets the plugin name.
107 *
108 * Returns: a plugin name, or %NULL for unknown.
109 *
110 * Since: 0.8.0
111 **/
Richard Hughescff38bc2016-12-12 12:03:37 +0000112const gchar *
113fu_plugin_get_name (FuPlugin *plugin)
Richard Hughesd0905142016-03-13 09:46:49 +0000114{
Richard Hughescff38bc2016-12-12 12:03:37 +0000115 FuPluginPrivate *priv = GET_PRIVATE (plugin);
Richard Hughesccd78a92017-01-11 16:57:41 +0000116 g_return_val_if_fail (FU_IS_PLUGIN (plugin), NULL);
Richard Hughescff38bc2016-12-12 12:03:37 +0000117 return priv->name;
118}
Richard Hughesd0905142016-03-13 09:46:49 +0000119
Richard Hughes57d18222017-01-10 16:02:59 +0000120/**
121 * fu_plugin_cache_lookup:
122 * @plugin: A #FuPlugin
123 * @id: the key
124 *
125 * Finds an object in the per-plugin cache.
126 *
127 * Returns: (transfer none): a #GObject, or %NULL for unfound.
128 *
129 * Since: 0.8.0
130 **/
Richard Hughescff38bc2016-12-12 12:03:37 +0000131gpointer
132fu_plugin_cache_lookup (FuPlugin *plugin, const gchar *id)
133{
134 FuPluginPrivate *priv = GET_PRIVATE (plugin);
Richard Hughesccd78a92017-01-11 16:57:41 +0000135 g_return_val_if_fail (FU_IS_PLUGIN (plugin), NULL);
136 g_return_val_if_fail (id != NULL, NULL);
Richard Hughescff38bc2016-12-12 12:03:37 +0000137 return g_hash_table_lookup (priv->devices, id);
138}
Richard Hughesd0905142016-03-13 09:46:49 +0000139
Richard Hughes57d18222017-01-10 16:02:59 +0000140/**
141 * fu_plugin_cache_add:
142 * @plugin: A #FuPlugin
143 * @id: the key
144 * @dev: a #GObject, typically a #FuDevice
145 *
146 * Adds an object to the per-plugin cache.
147 *
148 * Since: 0.8.0
149 **/
Richard Hughescff38bc2016-12-12 12:03:37 +0000150void
151fu_plugin_cache_add (FuPlugin *plugin, const gchar *id, gpointer dev)
152{
153 FuPluginPrivate *priv = GET_PRIVATE (plugin);
Richard Hughesccd78a92017-01-11 16:57:41 +0000154 g_return_if_fail (FU_IS_PLUGIN (plugin));
155 g_return_if_fail (id != NULL);
Richard Hughescff38bc2016-12-12 12:03:37 +0000156 g_hash_table_insert (priv->devices, g_strdup (id), g_object_ref (dev));
157}
158
Richard Hughes57d18222017-01-10 16:02:59 +0000159/**
160 * fu_plugin_cache_remove:
161 * @plugin: A #FuPlugin
162 * @id: the key
163 *
164 * Removes an object from the per-plugin cache.
165 *
166 * Since: 0.8.0
167 **/
Richard Hughescff38bc2016-12-12 12:03:37 +0000168void
169fu_plugin_cache_remove (FuPlugin *plugin, const gchar *id)
170{
171 FuPluginPrivate *priv = GET_PRIVATE (plugin);
Richard Hughesccd78a92017-01-11 16:57:41 +0000172 g_return_if_fail (FU_IS_PLUGIN (plugin));
173 g_return_if_fail (id != NULL);
Richard Hughescff38bc2016-12-12 12:03:37 +0000174 g_hash_table_remove (priv->devices, id);
175}
176
Richard Hughes57d18222017-01-10 16:02:59 +0000177/**
178 * fu_plugin_get_data:
179 * @plugin: A #FuPlugin
180 *
Richard Hughes4eada342017-10-03 21:20:32 +0100181 * Gets the per-plugin allocated private data. This will return %NULL unless
182 * fu_plugin_alloc_data() has been called by the plugin.
Richard Hughes57d18222017-01-10 16:02:59 +0000183 *
Richard Hughes4eada342017-10-03 21:20:32 +0100184 * Returns: (transfer none): a pointer to a structure, or %NULL for unset.
Richard Hughes57d18222017-01-10 16:02:59 +0000185 *
186 * Since: 0.8.0
187 **/
Richard Hughescff38bc2016-12-12 12:03:37 +0000188FuPluginData *
189fu_plugin_get_data (FuPlugin *plugin)
190{
191 FuPluginPrivate *priv = GET_PRIVATE (plugin);
Richard Hughesccd78a92017-01-11 16:57:41 +0000192 g_return_val_if_fail (FU_IS_PLUGIN (plugin), NULL);
Richard Hughescff38bc2016-12-12 12:03:37 +0000193 return priv->data;
194}
195
Richard Hughes57d18222017-01-10 16:02:59 +0000196/**
197 * fu_plugin_alloc_data:
198 * @plugin: A #FuPlugin
199 * @data_sz: the size to allocate
200 *
201 * Allocates the per-plugin allocated private data.
202 *
203 * Returns: (transfer full): a pointer to a structure, or %NULL for unset.
204 *
205 * Since: 0.8.0
206 **/
Richard Hughescff38bc2016-12-12 12:03:37 +0000207FuPluginData *
208fu_plugin_alloc_data (FuPlugin *plugin, gsize data_sz)
209{
210 FuPluginPrivate *priv = GET_PRIVATE (plugin);
Richard Hughesccd78a92017-01-11 16:57:41 +0000211 g_return_val_if_fail (FU_IS_PLUGIN (plugin), NULL);
Richard Hughes44dee882017-01-11 08:31:10 +0000212 if (priv->data != NULL) {
213 g_critical ("fu_plugin_alloc_data() already used by plugin");
214 return priv->data;
215 }
Richard Hughescff38bc2016-12-12 12:03:37 +0000216 priv->data = g_malloc0 (data_sz);
217 return priv->data;
Richard Hughesd0905142016-03-13 09:46:49 +0000218}
219
Richard Hughes57d18222017-01-10 16:02:59 +0000220/**
221 * fu_plugin_get_usb_context:
222 * @plugin: A #FuPlugin
223 *
224 * Gets the shared USB context that all plugins can use.
225 *
226 * Returns: (transfer none): a #GUsbContext.
227 *
228 * Since: 0.8.0
229 **/
Richard Hughesbc93e4a2016-12-08 17:29:51 +0000230GUsbContext *
231fu_plugin_get_usb_context (FuPlugin *plugin)
232{
Richard Hughescff38bc2016-12-12 12:03:37 +0000233 FuPluginPrivate *priv = GET_PRIVATE (plugin);
Richard Hughesccd78a92017-01-11 16:57:41 +0000234 g_return_val_if_fail (FU_IS_PLUGIN (plugin), NULL);
Richard Hughescff38bc2016-12-12 12:03:37 +0000235 return priv->usb_ctx;
Richard Hughesbc93e4a2016-12-08 17:29:51 +0000236}
237
238void
239fu_plugin_set_usb_context (FuPlugin *plugin, GUsbContext *usb_ctx)
240{
Richard Hughescff38bc2016-12-12 12:03:37 +0000241 FuPluginPrivate *priv = GET_PRIVATE (plugin);
242 g_set_object (&priv->usb_ctx, usb_ctx);
243}
244
Richard Hughes57d18222017-01-10 16:02:59 +0000245/**
246 * fu_plugin_get_enabled:
247 * @plugin: A #FuPlugin
248 *
Richard Hughes4eada342017-10-03 21:20:32 +0100249 * Returns if the plugin is enabled. Plugins may self-disable using
250 * fu_plugin_set_enabled() or can be disabled by the daemon.
Richard Hughes57d18222017-01-10 16:02:59 +0000251 *
252 * Returns: %TRUE if the plugin is currently enabled.
253 *
254 * Since: 0.8.0
255 **/
Richard Hughescff38bc2016-12-12 12:03:37 +0000256gboolean
257fu_plugin_get_enabled (FuPlugin *plugin)
258{
259 FuPluginPrivate *priv = GET_PRIVATE (plugin);
Richard Hughesccd78a92017-01-11 16:57:41 +0000260 g_return_val_if_fail (FU_IS_PLUGIN (plugin), FALSE);
Richard Hughescff38bc2016-12-12 12:03:37 +0000261 return priv->enabled;
Richard Hughesbc93e4a2016-12-08 17:29:51 +0000262}
263
Richard Hughes57d18222017-01-10 16:02:59 +0000264/**
265 * fu_plugin_set_enabled:
266 * @plugin: A #FuPlugin
267 * @enabled: the enabled value
268 *
269 * Enables or disables a plugin. Plugins can self-disable at any point.
270 *
271 * Since: 0.8.0
272 **/
Richard Hughesd0905142016-03-13 09:46:49 +0000273void
Richard Hughescff38bc2016-12-12 12:03:37 +0000274fu_plugin_set_enabled (FuPlugin *plugin, gboolean enabled)
Richard Hughesd0905142016-03-13 09:46:49 +0000275{
Richard Hughescff38bc2016-12-12 12:03:37 +0000276 FuPluginPrivate *priv = GET_PRIVATE (plugin);
Richard Hughesccd78a92017-01-11 16:57:41 +0000277 g_return_if_fail (FU_IS_PLUGIN (plugin));
Richard Hughescff38bc2016-12-12 12:03:37 +0000278 priv->enabled = enabled;
279}
280
281gboolean
282fu_plugin_open (FuPlugin *plugin, const gchar *filename, GError **error)
283{
284 FuPluginPrivate *priv = GET_PRIVATE (plugin);
285 FuPluginInitFunc func = NULL;
286 gchar *str;
287
288 priv->module = g_module_open (filename, 0);
289 if (priv->module == NULL) {
290 g_set_error (error,
291 G_IO_ERROR,
292 G_IO_ERROR_FAILED,
293 "failed to open plugin: %s",
294 g_module_error ());
295 return FALSE;
296 }
297
298 /* set automatically */
299 str = g_strstr_len (filename, -1, "libfu_plugin_");
300 if (str != NULL) {
301 priv->name = g_strdup (str + 13);
302 g_strdelimit (priv->name, ".", '\0');
303 }
Richard Hughesd0905142016-03-13 09:46:49 +0000304
305 /* optional */
Richard Hughescff38bc2016-12-12 12:03:37 +0000306 g_module_symbol (priv->module, "fu_plugin_init", (gpointer *) &func);
307 if (func != NULL) {
308 g_debug ("performing init() on %s", filename);
Richard Hughesd0905142016-03-13 09:46:49 +0000309 func (plugin);
310 }
311
Richard Hughescff38bc2016-12-12 12:03:37 +0000312 return TRUE;
313}
314
Richard Hughes57d18222017-01-10 16:02:59 +0000315/**
316 * fu_plugin_device_add:
317 * @plugin: A #FuPlugin
318 * @device: A #FuDevice
319 *
320 * Asks the daemon to add a device to the exported list. If this device ID
321 * has already been added by a different plugin then this request will be
322 * ignored.
323 *
324 * Plugins should use fu_plugin_device_add_delay() if they are not capable of
325 * actually flashing an image to the hardware so that higher-priority plugins
326 * can add the device themselves.
327 *
328 * Since: 0.8.0
329 **/
Richard Hughescff38bc2016-12-12 12:03:37 +0000330void
331fu_plugin_device_add (FuPlugin *plugin, FuDevice *device)
332{
Richard Hughesccd78a92017-01-11 16:57:41 +0000333 g_return_if_fail (FU_IS_PLUGIN (plugin));
334 g_return_if_fail (FU_IS_DEVICE (device));
335
Richard Hughescff38bc2016-12-12 12:03:37 +0000336 g_debug ("emit added from %s: %s",
337 fu_plugin_get_name (plugin),
338 fu_device_get_id (device));
339 fu_device_set_created (device, (guint64) g_get_real_time () / G_USEC_PER_SEC);
340 fu_device_set_plugin (device, fu_plugin_get_name (plugin));
341 g_signal_emit (plugin, signals[SIGNAL_DEVICE_ADDED], 0, device);
342}
343
Richard Hughese1fd34d2017-08-24 14:19:51 +0100344/**
345 * fu_plugin_device_register:
346 * @plugin: A #FuPlugin
347 * @device: A #FuDevice
348 *
349 * Registers the device with other plugins so they can set metadata.
350 *
351 * Plugins do not have to call this manually as this is done automatically
352 * when using fu_plugin_device_add(). They may wish to use this manually
353 * if for intance the coldplug should be ignored based on the metadata
354 * set from other plugins.
355 *
356 * Since: 0.9.7
357 **/
358void
359fu_plugin_device_register (FuPlugin *plugin, FuDevice *device)
360{
361 g_return_if_fail (FU_IS_PLUGIN (plugin));
362 g_return_if_fail (FU_IS_DEVICE (device));
363
364 g_debug ("emit device-register from %s: %s",
365 fu_plugin_get_name (plugin),
366 fu_device_get_id (device));
367 g_signal_emit (plugin, signals[SIGNAL_DEVICE_REGISTER], 0, device);
368}
369
Richard Hughesae3d65f2016-12-16 09:38:01 +0000370typedef struct {
371 FuPlugin *plugin;
372 FuDevice *device;
373 guint timeout_id;
Richard Hughesd4184cf2016-12-21 16:05:17 +0000374 GHashTable *devices;
Richard Hughesae3d65f2016-12-16 09:38:01 +0000375} FuPluginHelper;
376
377static void
378fu_plugin_helper_free (FuPluginHelper *helper)
379{
380 g_object_unref (helper->plugin);
381 g_object_unref (helper->device);
Richard Hughesd4184cf2016-12-21 16:05:17 +0000382 g_hash_table_unref (helper->devices);
Richard Hughesae3d65f2016-12-16 09:38:01 +0000383 g_free (helper);
384}
385
386static gboolean
387fu_plugin_device_add_delay_cb (gpointer user_data)
388{
389 FuPluginHelper *helper = (FuPluginHelper *) user_data;
390 fu_plugin_device_add (helper->plugin, helper->device);
Richard Hughes0dec2742017-09-18 11:07:39 +0100391 g_hash_table_remove (helper->devices, helper->device);
Richard Hughesae3d65f2016-12-16 09:38:01 +0000392 fu_plugin_helper_free (helper);
393 return FALSE;
394}
395
Richard Hughes57d18222017-01-10 16:02:59 +0000396/**
Richard Hughesf0a799e2017-01-17 20:13:30 +0000397 * fu_plugin_has_device_delay:
398 * @plugin: A #FuPlugin
399 *
400 * Returns if the device has a pending device that is waiting to be added.
401 *
402 * Returns: %TRUE if a device is waiting to be added
403 *
404 * Since: 0.8.0
405 **/
406gboolean
407fu_plugin_has_device_delay (FuPlugin *plugin)
408{
409 FuPluginPrivate *priv = GET_PRIVATE (plugin);
410 return g_hash_table_size (priv->devices_delay) > 0;
411}
412
413/**
Richard Hughes57d18222017-01-10 16:02:59 +0000414 * fu_plugin_device_add_delay:
415 * @plugin: A #FuPlugin
416 * @device: A #FuDevice
417 *
418 * Asks the daemon to add a device to the exported list after a small delay.
419 *
420 * Since: 0.8.0
421 **/
Richard Hughesae3d65f2016-12-16 09:38:01 +0000422void
423fu_plugin_device_add_delay (FuPlugin *plugin, FuDevice *device)
424{
425 FuPluginPrivate *priv = GET_PRIVATE (plugin);
426 FuPluginHelper *helper;
Richard Hughesccd78a92017-01-11 16:57:41 +0000427
428 g_return_if_fail (FU_IS_PLUGIN (plugin));
429 g_return_if_fail (FU_IS_DEVICE (device));
430
Richard Hughes6ad951d2017-02-03 10:12:12 +0000431 /* already waiting for add */
432 helper = g_hash_table_lookup (priv->devices_delay, device);
433 if (helper != NULL) {
Richard Hughes3cca1c62017-07-21 13:38:20 +0100434 g_debug ("ignoring add-delay as device %s already pending",
435 fu_device_get_id (device));
Richard Hughes6ad951d2017-02-03 10:12:12 +0000436 return;
437 }
438
439 /* add after a small delay */
Richard Hughesae3d65f2016-12-16 09:38:01 +0000440 g_debug ("waiting a small time for other plugins");
441 helper = g_new0 (FuPluginHelper, 1);
442 helper->plugin = g_object_ref (plugin);
443 helper->device = g_object_ref (device);
444 helper->timeout_id = g_timeout_add (500, fu_plugin_device_add_delay_cb, helper);
Richard Hughesd4184cf2016-12-21 16:05:17 +0000445 helper->devices = g_hash_table_ref (priv->devices_delay);
446 g_hash_table_insert (helper->devices, device, helper);
Richard Hughesae3d65f2016-12-16 09:38:01 +0000447}
448
Richard Hughes57d18222017-01-10 16:02:59 +0000449/**
Richard Hughes4eada342017-10-03 21:20:32 +0100450 * fu_plugin_device_remove:
Richard Hughes57d18222017-01-10 16:02:59 +0000451 * @plugin: A #FuPlugin
452 * @device: A #FuDevice
453 *
454 * Asks the daemon to remove a device from the exported list.
455 *
456 * Since: 0.8.0
457 **/
Richard Hughescff38bc2016-12-12 12:03:37 +0000458void
459fu_plugin_device_remove (FuPlugin *plugin, FuDevice *device)
460{
Richard Hughesae3d65f2016-12-16 09:38:01 +0000461 FuPluginPrivate *priv = GET_PRIVATE (plugin);
462 FuPluginHelper *helper;
463
Richard Hughesccd78a92017-01-11 16:57:41 +0000464 g_return_if_fail (FU_IS_PLUGIN (plugin));
465 g_return_if_fail (FU_IS_DEVICE (device));
466
Richard Hughesae3d65f2016-12-16 09:38:01 +0000467 /* waiting for add */
468 helper = g_hash_table_lookup (priv->devices_delay, device);
469 if (helper != NULL) {
470 g_debug ("ignoring remove from delayed addition");
471 g_source_remove (helper->timeout_id);
Richard Hughesd4184cf2016-12-21 16:05:17 +0000472 g_hash_table_remove (priv->devices_delay, helper->device);
Richard Hughesae3d65f2016-12-16 09:38:01 +0000473 fu_plugin_helper_free (helper);
474 return;
475 }
476
Richard Hughescff38bc2016-12-12 12:03:37 +0000477 g_debug ("emit removed from %s: %s",
478 fu_plugin_get_name (plugin),
479 fu_device_get_id (device));
480 g_signal_emit (plugin, signals[SIGNAL_DEVICE_REMOVED], 0, device);
481}
482
Richard Hughes57d18222017-01-10 16:02:59 +0000483/**
484 * fu_plugin_set_status:
485 * @plugin: A #FuPlugin
486 * @status: A #FwupdStatus, e.g. #FWUPD_STATUS_DECOMPRESSING
487 *
488 * Sets the global state of the daemon according to the current plugin action.
489 *
490 * Since: 0.8.0
491 **/
Richard Hughescff38bc2016-12-12 12:03:37 +0000492void
493fu_plugin_set_status (FuPlugin *plugin, FwupdStatus status)
494{
Richard Hughesccd78a92017-01-11 16:57:41 +0000495 g_return_if_fail (FU_IS_PLUGIN (plugin));
Richard Hughescff38bc2016-12-12 12:03:37 +0000496 g_signal_emit (plugin, signals[SIGNAL_STATUS_CHANGED], 0, status);
497}
498
Richard Hughes57d18222017-01-10 16:02:59 +0000499/**
500 * fu_plugin_set_percentage:
501 * @plugin: A #FuPlugin
502 * @percentage: the percentage complete
503 *
504 * Sets the global completion of the daemon according to the current plugin
505 * action.
506 *
507 * Since: 0.8.0
508 **/
Richard Hughescff38bc2016-12-12 12:03:37 +0000509void
510fu_plugin_set_percentage (FuPlugin *plugin, guint percentage)
511{
Richard Hughesccd78a92017-01-11 16:57:41 +0000512 g_return_if_fail (FU_IS_PLUGIN (plugin));
513 g_return_if_fail (percentage <= 100);
Richard Hughescff38bc2016-12-12 12:03:37 +0000514 g_signal_emit (plugin, signals[SIGNAL_PERCENTAGE_CHANGED], 0,
515 percentage);
Richard Hughesd0905142016-03-13 09:46:49 +0000516}
517
Richard Hughes362d6d72017-01-07 21:42:14 +0000518/**
519 * fu_plugin_recoldplug:
520 * @plugin: A #FuPlugin
521 *
522 * Ask all the plugins to coldplug all devices, which will include the prepare()
523 * and cleanup() phases. Duplicate devices added will be ignored.
524 *
525 * Since: 0.8.0
526 **/
527void
528fu_plugin_recoldplug (FuPlugin *plugin)
529{
Richard Hughesccd78a92017-01-11 16:57:41 +0000530 g_return_if_fail (FU_IS_PLUGIN (plugin));
Richard Hughes362d6d72017-01-07 21:42:14 +0000531 g_signal_emit (plugin, signals[SIGNAL_RECOLDPLUG], 0);
532}
533
Richard Hughesb0829032017-01-10 09:27:08 +0000534/**
Richard Hughesb8f8db22017-04-25 15:56:00 +0100535 * fu_plugin_check_hwid:
536 * @plugin: A #FuPlugin
Richard Hughes4eada342017-10-03 21:20:32 +0100537 * @hwid: A Hardware ID GUID, e.g. `6de5d951-d755-576b-bd09-c5cf66b27234`
Richard Hughesb8f8db22017-04-25 15:56:00 +0100538 *
Richard Hughesd7704d42017-08-08 20:29:09 +0100539 * Checks to see if a specific GUID exists. All hardware IDs on a
Richard Hughesb8f8db22017-04-25 15:56:00 +0100540 * specific system can be shown using the `fwupdmgr hwids` command.
541 *
Richard Hughes4eada342017-10-03 21:20:32 +0100542 * Returns: %TRUE if the HwId is found on the system.
543 *
Richard Hughesb8f8db22017-04-25 15:56:00 +0100544 * Since: 0.9.1
545 **/
546gboolean
547fu_plugin_check_hwid (FuPlugin *plugin, const gchar *hwid)
548{
549 FuPluginPrivate *priv = GET_PRIVATE (plugin);
550 if (priv->hwids == NULL)
551 return FALSE;
Richard Hughesd7704d42017-08-08 20:29:09 +0100552 return fu_hwids_has_guid (priv->hwids, hwid);
553}
554
555/**
Richard Hughes1354ea92017-09-19 15:58:31 +0100556 * fu_plugin_check_supported:
557 * @plugin: A #FuPlugin
Richard Hughes4eada342017-10-03 21:20:32 +0100558 * @guid: A Hardware ID GUID, e.g. `6de5d951-d755-576b-bd09-c5cf66b27234`
Richard Hughes1354ea92017-09-19 15:58:31 +0100559 *
560 * Checks to see if a specific device GUID is supported, i.e. available in the
561 * AppStream metadata.
562 *
Richard Hughes4eada342017-10-03 21:20:32 +0100563 * Returns: %TRUE if the device is supported.
564 *
Richard Hughes1354ea92017-09-19 15:58:31 +0100565 * Since: 1.0.0
566 **/
567gboolean
568fu_plugin_check_supported (FuPlugin *plugin, const gchar *guid)
569{
570 FuPluginPrivate *priv = GET_PRIVATE (plugin);
571 if (priv->supported_guids == NULL)
572 return FALSE;
573 for (guint i = 0; i < priv->supported_guids->len; i++) {
574 const gchar *guid_tmp = g_ptr_array_index (priv->supported_guids, i);
575 if (g_strcmp0 (guid, guid_tmp) == 0)
576 return TRUE;
577 }
578 return FALSE;
579}
580
581/**
Richard Hughesd7704d42017-08-08 20:29:09 +0100582 * fu_plugin_get_dmi_value:
583 * @plugin: A #FuPlugin
Richard Hughes4eada342017-10-03 21:20:32 +0100584 * @dmi_id: A DMI ID, e.g. `BiosVersion`
Richard Hughesd7704d42017-08-08 20:29:09 +0100585 *
586 * Gets a hardware DMI value.
587 *
Richard Hughes4eada342017-10-03 21:20:32 +0100588 * Returns: The string, or %NULL
589 *
Richard Hughesd7704d42017-08-08 20:29:09 +0100590 * Since: 0.9.7
591 **/
592const gchar *
593fu_plugin_get_dmi_value (FuPlugin *plugin, const gchar *dmi_id)
594{
595 FuPluginPrivate *priv = GET_PRIVATE (plugin);
596 if (priv->hwids == NULL)
Richard Hughes7ef96b82017-08-23 18:28:24 +0100597 return NULL;
Richard Hughesd7704d42017-08-08 20:29:09 +0100598 return fu_hwids_get_value (priv->hwids, dmi_id);
Richard Hughesb8f8db22017-04-25 15:56:00 +0100599}
600
Richard Hughes49e5e052017-09-03 12:15:41 +0100601/**
602 * fu_plugin_get_smbios_string:
603 * @plugin: A #FuPlugin
604 * @structure_type: A SMBIOS structure type, e.g. %FU_SMBIOS_STRUCTURE_TYPE_BIOS
605 * @offset: A SMBIOS offset
606 *
607 * Gets a hardware SMBIOS string.
608 *
609 * The @type and @offset can be referenced from the DMTF SMBIOS specification:
610 * https://www.dmtf.org/sites/default/files/standards/documents/DSP0134_3.1.1.pdf
611 *
Richard Hughes4eada342017-10-03 21:20:32 +0100612 * Returns: A string, or %NULL
613 *
Richard Hughes49e5e052017-09-03 12:15:41 +0100614 * Since: 0.9.8
615 **/
616const gchar *
617fu_plugin_get_smbios_string (FuPlugin *plugin, guint8 structure_type, guint8 offset)
618{
619 FuPluginPrivate *priv = GET_PRIVATE (plugin);
620 if (priv->smbios == NULL)
621 return NULL;
622 return fu_smbios_get_string (priv->smbios, structure_type, offset, NULL);
623}
624
625/**
626 * fu_plugin_get_smbios_data:
627 * @plugin: A #FuPlugin
628 * @structure_type: A SMBIOS structure type, e.g. %FU_SMBIOS_STRUCTURE_TYPE_BIOS
629 *
630 * Gets a hardware SMBIOS data.
631 *
Richard Hughes4eada342017-10-03 21:20:32 +0100632 * Returns: (transfer none): A #GBytes, or %NULL
633 *
Richard Hughes49e5e052017-09-03 12:15:41 +0100634 * Since: 0.9.8
635 **/
636GBytes *
637fu_plugin_get_smbios_data (FuPlugin *plugin, guint8 structure_type)
638{
639 FuPluginPrivate *priv = GET_PRIVATE (plugin);
640 if (priv->smbios == NULL)
641 return NULL;
642 return fu_smbios_get_data (priv->smbios, structure_type, NULL);
643}
644
Richard Hughesb8f8db22017-04-25 15:56:00 +0100645void
Richard Hughesd7704d42017-08-08 20:29:09 +0100646fu_plugin_set_hwids (FuPlugin *plugin, FuHwids *hwids)
Richard Hughesb8f8db22017-04-25 15:56:00 +0100647{
648 FuPluginPrivate *priv = GET_PRIVATE (plugin);
Richard Hughesd7704d42017-08-08 20:29:09 +0100649 g_set_object (&priv->hwids, hwids);
Richard Hughesb8f8db22017-04-25 15:56:00 +0100650}
651
Richard Hughes49e5e052017-09-03 12:15:41 +0100652void
Richard Hughes1354ea92017-09-19 15:58:31 +0100653fu_plugin_set_supported (FuPlugin *plugin, GPtrArray *supported_guids)
654{
655 FuPluginPrivate *priv = GET_PRIVATE (plugin);
656 if (priv->supported_guids != NULL)
657 g_ptr_array_unref (priv->supported_guids);
658 priv->supported_guids = g_ptr_array_ref (supported_guids);
659}
660
Richard Hughes9c028f02017-10-28 21:14:28 +0100661void
662fu_plugin_set_quirks (FuPlugin *plugin, FuQuirks *quirks)
663{
664 FuPluginPrivate *priv = GET_PRIVATE (plugin);
665 g_set_object (&priv->quirks, quirks);
666}
667
668/**
669 * fu_plugin_get_quirks:
670 * @plugin: A #FuPlugin
671 *
672 * Returns the hardware database object. This can be used to discover device
673 * quirks or other device-specific settings.
674 *
675 * Returns: (transfer none): a #FuQuirks, or %NULL if not set
676 *
677 * Since: 1.0.1
678 **/
679FuQuirks *
680fu_plugin_get_quirks (FuPlugin *plugin)
681{
682 FuPluginPrivate *priv = GET_PRIVATE (plugin);
683 return priv->quirks;
684}
685
686/**
687 * fu_plugin_lookup_quirk_by_id:
688 * @plugin: A #FuPlugin
689 * @prefix: A string prefix that matches the quirks file basename, e.g. "dfu-quirks"
690 * @id: An ID to match the entry, e.g. "012345"
691 *
692 * Looks up an entry in the hardware database using a string value.
693 *
694 * Returns: (transfer none): values from the database, or %NULL if not found
695 *
696 * Since: 1.0.1
697 **/
698const gchar *
699fu_plugin_lookup_quirk_by_id (FuPlugin *plugin, const gchar *prefix, const gchar *id)
700{
701 FuPluginPrivate *priv = GET_PRIVATE (plugin);
702 g_return_val_if_fail (FU_IS_PLUGIN (plugin), NULL);
703
704 /* wildcard */
705 if (g_strstr_len (id, -1, "*") != NULL)
706 return fu_quirks_lookup_by_glob (priv->quirks, prefix, id);
707
708 /* exact ID */
709 return fu_quirks_lookup_by_id (priv->quirks, prefix, id);
710}
711
712/**
713 * fu_plugin_lookup_quirk_by_usb_device:
714 * @plugin: A #FuPlugin
715 * @prefix: A string prefix that matches the quirks file basename, e.g. "dfu-quirks"
716 * @dev: A #GUsbDevice
717 *
718 * Looks up an entry in the hardware database using various keys generated
719 * from @dev.
720 *
721 * Returns: (transfer none): values from the database, or %NULL if not found
722 *
723 * Since: 1.0.1
724 **/
725const gchar *
726fu_plugin_lookup_quirk_by_usb_device (FuPlugin *plugin, const gchar *prefix, GUsbDevice *dev)
727{
728 FuPluginPrivate *priv = GET_PRIVATE (plugin);
729 g_return_val_if_fail (FU_IS_PLUGIN (plugin), NULL);
730 return fu_quirks_lookup_by_usb_device (priv->quirks, prefix, dev);
731}
732
Richard Hughes1354ea92017-09-19 15:58:31 +0100733/**
734 * fu_plugin_get_supported:
735 * @plugin: A #FuPlugin
736 *
737 * Gets all the device GUIDs supported by the daemon.
738 *
Richard Hughes4eada342017-10-03 21:20:32 +0100739 * Returns: (element-type utf8) (transfer none): GUIDs
740 *
Richard Hughes1354ea92017-09-19 15:58:31 +0100741 * Since: 1.0.0
742 **/
743GPtrArray *
744fu_plugin_get_supported (FuPlugin *plugin)
745{
746 FuPluginPrivate *priv = GET_PRIVATE (plugin);
747 return priv->supported_guids;
748}
749
750void
Richard Hughes49e5e052017-09-03 12:15:41 +0100751fu_plugin_set_smbios (FuPlugin *plugin, FuSmbios *smbios)
752{
753 FuPluginPrivate *priv = GET_PRIVATE (plugin);
754 g_set_object (&priv->smbios, smbios);
755}
756
Richard Hughesb8f8db22017-04-25 15:56:00 +0100757/**
Richard Hughesb0829032017-01-10 09:27:08 +0000758 * fu_plugin_set_coldplug_delay:
759 * @plugin: A #FuPlugin
760 * @duration: A delay in milliseconds
761 *
762 * Set the minimum time that should be waited inbetween the call to
763 * fu_plugin_coldplug_prepare() and fu_plugin_coldplug(). This is usually going
764 * to be the minimum hardware initialisation time from a datasheet.
765 *
766 * It is better to use this function rather than using a sleep() in the plugin
767 * itself as then only one delay is done in the daemon rather than waiting for
768 * each coldplug prepare in a serial way.
769 *
770 * Additionally, very long delays should be avoided as the daemon will be
771 * blocked from processing requests whilst the coldplug delay is being
772 * performed.
773 *
774 * Since: 0.8.0
775 **/
776void
777fu_plugin_set_coldplug_delay (FuPlugin *plugin, guint duration)
778{
779 g_return_if_fail (FU_IS_PLUGIN (plugin));
780 g_return_if_fail (duration > 0);
781
782 /* check sanity */
783 if (duration > FU_PLUGIN_COLDPLUG_DELAY_MAXIMUM) {
784 g_warning ("duration of %ums is crazy, truncating to %ums",
785 duration,
786 FU_PLUGIN_COLDPLUG_DELAY_MAXIMUM);
787 duration = FU_PLUGIN_COLDPLUG_DELAY_MAXIMUM;
788 }
789
790 /* emit */
791 g_signal_emit (plugin, signals[SIGNAL_SET_COLDPLUG_DELAY], 0, duration);
792}
793
Richard Hughesd0905142016-03-13 09:46:49 +0000794gboolean
Richard Hughescff38bc2016-12-12 12:03:37 +0000795fu_plugin_runner_startup (FuPlugin *plugin, GError **error)
Richard Hughesd0905142016-03-13 09:46:49 +0000796{
Richard Hughescff38bc2016-12-12 12:03:37 +0000797 FuPluginPrivate *priv = GET_PRIVATE (plugin);
Richard Hughes7b8b2022016-12-12 16:15:03 +0000798 FuPluginStartupFunc func = NULL;
Richard Hughesd0905142016-03-13 09:46:49 +0000799
800 /* not enabled */
Richard Hughescff38bc2016-12-12 12:03:37 +0000801 if (!priv->enabled)
Richard Hughesd0905142016-03-13 09:46:49 +0000802 return TRUE;
803
804 /* optional */
Richard Hughescff38bc2016-12-12 12:03:37 +0000805 g_module_symbol (priv->module, "fu_plugin_startup", (gpointer *) &func);
806 if (func == NULL)
Richard Hughesd0905142016-03-13 09:46:49 +0000807 return TRUE;
Richard Hughescff38bc2016-12-12 12:03:37 +0000808 g_debug ("performing startup() on %s", priv->name);
Richard Hughesd0905142016-03-13 09:46:49 +0000809 if (!func (plugin, error)) {
Richard Hughescff38bc2016-12-12 12:03:37 +0000810 g_prefix_error (error, "failed to startup %s: ", priv->name);
811 return FALSE;
812 }
813 return TRUE;
814}
815
816static gboolean
817fu_plugin_runner_offline_invalidate (GError **error)
818{
819 g_autoptr(GError) error_local = NULL;
820 g_autoptr(GFile) file1 = NULL;
821
822 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
823
824 file1 = g_file_new_for_path (FU_OFFLINE_TRIGGER_FILENAME);
825 if (!g_file_query_exists (file1, NULL))
826 return TRUE;
827 if (!g_file_delete (file1, NULL, &error_local)) {
828 g_set_error (error,
829 FWUPD_ERROR,
830 FWUPD_ERROR_INTERNAL,
831 "Cannot delete %s: %s",
832 FU_OFFLINE_TRIGGER_FILENAME,
833 error_local->message);
834 return FALSE;
835 }
836 return TRUE;
837}
838
839static gboolean
840fu_plugin_runner_offline_setup (GError **error)
841{
842 gint rc;
843
844 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
845
846 /* create symlink for the systemd-system-update-generator */
847 rc = symlink ("/var/lib/fwupd", FU_OFFLINE_TRIGGER_FILENAME);
848 if (rc < 0) {
849 g_set_error (error,
850 FWUPD_ERROR,
851 FWUPD_ERROR_INTERNAL,
852 "Failed to create symlink %s to %s: %s",
853 FU_OFFLINE_TRIGGER_FILENAME,
854 "/var/lib", strerror (errno));
Richard Hughesd0905142016-03-13 09:46:49 +0000855 return FALSE;
856 }
857 return TRUE;
858}
859
Richard Hughes0d7fdb32017-11-11 20:23:14 +0000860static gboolean
861fu_plugin_runner_device_generic (FuPlugin *plugin, FuDevice *device,
862 const gchar *symbol_name, GError **error)
863{
864 FuPluginPrivate *priv = GET_PRIVATE (plugin);
865 FuPluginDeviceFunc func = NULL;
866
867 /* not enabled */
868 if (!priv->enabled)
869 return TRUE;
870
871 /* optional */
872 g_module_symbol (priv->module, symbol_name, (gpointer *) &func);
873 if (func == NULL)
874 return TRUE;
875 g_debug ("performing %s() on %s", symbol_name + 10, priv->name);
876 if (!func (plugin, device, error)) {
877 g_prefix_error (error, "failed to run %s(%s) on %s: ",
878 symbol_name + 10,
879 fu_device_get_id (device),
880 priv->name);
881 return FALSE;
882 }
883 return TRUE;
884}
885
Richard Hughesd0905142016-03-13 09:46:49 +0000886gboolean
Richard Hughescff38bc2016-12-12 12:03:37 +0000887fu_plugin_runner_coldplug (FuPlugin *plugin, GError **error)
Richard Hughesd0905142016-03-13 09:46:49 +0000888{
Richard Hughescff38bc2016-12-12 12:03:37 +0000889 FuPluginPrivate *priv = GET_PRIVATE (plugin);
Richard Hughes7b8b2022016-12-12 16:15:03 +0000890 FuPluginStartupFunc func = NULL;
Richard Hughesd0905142016-03-13 09:46:49 +0000891
892 /* not enabled */
Richard Hughescff38bc2016-12-12 12:03:37 +0000893 if (!priv->enabled)
Richard Hughesd0905142016-03-13 09:46:49 +0000894 return TRUE;
895
896 /* optional */
Richard Hughescff38bc2016-12-12 12:03:37 +0000897 g_module_symbol (priv->module, "fu_plugin_coldplug", (gpointer *) &func);
898 if (func == NULL)
Richard Hughesd0905142016-03-13 09:46:49 +0000899 return TRUE;
Richard Hughescff38bc2016-12-12 12:03:37 +0000900 g_debug ("performing coldplug() on %s", priv->name);
901 if (!func (plugin, error)) {
902 g_prefix_error (error, "failed to coldplug %s: ", priv->name);
903 return FALSE;
904 }
905 return TRUE;
906}
907
Richard Hughes7b8b2022016-12-12 16:15:03 +0000908gboolean
Richard Hughes46487c92017-01-07 21:26:34 +0000909fu_plugin_runner_coldplug_prepare (FuPlugin *plugin, GError **error)
910{
911 FuPluginPrivate *priv = GET_PRIVATE (plugin);
912 FuPluginStartupFunc func = NULL;
913
914 /* not enabled */
915 if (!priv->enabled)
916 return TRUE;
917
918 /* optional */
919 g_module_symbol (priv->module, "fu_plugin_coldplug_prepare", (gpointer *) &func);
920 if (func == NULL)
921 return TRUE;
922 g_debug ("performing coldplug_prepare() on %s", priv->name);
923 if (!func (plugin, error)) {
924 g_prefix_error (error, "failed to prepare for coldplug %s: ", priv->name);
925 return FALSE;
926 }
927 return TRUE;
928}
929
930gboolean
931fu_plugin_runner_coldplug_cleanup (FuPlugin *plugin, GError **error)
932{
933 FuPluginPrivate *priv = GET_PRIVATE (plugin);
934 FuPluginStartupFunc func = NULL;
935
936 /* not enabled */
937 if (!priv->enabled)
938 return TRUE;
939
940 /* optional */
941 g_module_symbol (priv->module, "fu_plugin_coldplug_cleanup", (gpointer *) &func);
942 if (func == NULL)
943 return TRUE;
944 g_debug ("performing coldplug_cleanup() on %s", priv->name);
945 if (!func (plugin, error)) {
946 g_prefix_error (error, "failed to cleanup coldplug %s: ", priv->name);
947 return FALSE;
948 }
949 return TRUE;
950}
951
952gboolean
Richard Hughes7b8b2022016-12-12 16:15:03 +0000953fu_plugin_runner_update_prepare (FuPlugin *plugin, FuDevice *device, GError **error)
954{
Richard Hughes0d7fdb32017-11-11 20:23:14 +0000955 return fu_plugin_runner_device_generic (plugin, device,
956 "fu_plugin_update_prepare", error);
Richard Hughes7b8b2022016-12-12 16:15:03 +0000957}
958
959gboolean
960fu_plugin_runner_update_cleanup (FuPlugin *plugin, FuDevice *device, GError **error)
961{
Richard Hughes0d7fdb32017-11-11 20:23:14 +0000962 return fu_plugin_runner_device_generic (plugin, device,
963 "fu_plugin_update_cleanup", error);
964}
Richard Hughes7b8b2022016-12-12 16:15:03 +0000965
Richard Hughes0d7fdb32017-11-11 20:23:14 +0000966gboolean
967fu_plugin_runner_update_attach (FuPlugin *plugin, FuDevice *device, GError **error)
968{
969 return fu_plugin_runner_device_generic (plugin, device,
970 "fu_plugin_update_attach", error);
971}
Richard Hughes7b8b2022016-12-12 16:15:03 +0000972
Richard Hughes0d7fdb32017-11-11 20:23:14 +0000973gboolean
974fu_plugin_runner_update_detach (FuPlugin *plugin, FuDevice *device, GError **error)
975{
976 return fu_plugin_runner_device_generic (plugin, device,
977 "fu_plugin_update_detach", error);
978}
979
980gboolean
981fu_plugin_runner_update_reload (FuPlugin *plugin, FuDevice *device, GError **error)
982{
983 return fu_plugin_runner_device_generic (plugin, device,
984 "fu_plugin_update_reload", error);
Richard Hughes7b8b2022016-12-12 16:15:03 +0000985}
986
Richard Hughese1fd34d2017-08-24 14:19:51 +0100987void
988fu_plugin_runner_device_register (FuPlugin *plugin, FuDevice *device)
989{
990 FuPluginPrivate *priv = GET_PRIVATE (plugin);
991 FuPluginDeviceRegisterFunc func = NULL;
992
993 /* not enabled */
994 if (!priv->enabled)
995 return;
996
997 /* optional */
998 g_module_symbol (priv->module, "fu_plugin_device_registered", (gpointer *) &func);
999 if (func != NULL) {
1000 g_debug ("performing device_added() on %s", priv->name);
1001 func (plugin, device);
1002 }
1003}
1004
Richard Hughescff38bc2016-12-12 12:03:37 +00001005static gboolean
1006fu_plugin_runner_schedule_update (FuPlugin *plugin,
1007 FuDevice *device,
1008 GBytes *blob_cab,
1009 GError **error)
1010{
1011 gchar tmpname[] = {"XXXXXX.cap"};
1012 g_autofree gchar *dirname = NULL;
1013 g_autofree gchar *filename = NULL;
Richard Hughes68982c62017-09-13 15:40:14 +01001014 g_autoptr(FuDevice) res_tmp = NULL;
Richard Hughescff38bc2016-12-12 12:03:37 +00001015 g_autoptr(FuPending) pending = NULL;
1016 g_autoptr(GFile) file = NULL;
1017
1018 /* id already exists */
1019 pending = fu_pending_new ();
1020 res_tmp = fu_pending_get_device (pending, fu_device_get_id (device), NULL);
1021 if (res_tmp != NULL) {
1022 g_set_error (error,
1023 FWUPD_ERROR,
1024 FWUPD_ERROR_ALREADY_PENDING,
1025 "%s is already scheduled to be updated",
1026 fu_device_get_id (device));
1027 return FALSE;
1028 }
1029
1030 /* create directory */
1031 dirname = g_build_filename (LOCALSTATEDIR, "lib", "fwupd", NULL);
1032 file = g_file_new_for_path (dirname);
1033 if (!g_file_query_exists (file, NULL)) {
1034 if (!g_file_make_directory_with_parents (file, NULL, error))
1035 return FALSE;
1036 }
1037
1038 /* get a random filename */
1039 for (guint i = 0; i < 6; i++)
1040 tmpname[i] = (gchar) g_random_int_range ('A', 'Z');
1041 filename = g_build_filename (dirname, tmpname, NULL);
1042
1043 /* just copy to the temp file */
1044 fu_plugin_set_status (plugin, FWUPD_STATUS_SCHEDULING);
1045 if (!g_file_set_contents (filename,
1046 g_bytes_get_data (blob_cab, NULL),
1047 (gssize) g_bytes_get_size (blob_cab),
1048 error))
1049 return FALSE;
1050
1051 /* schedule for next boot */
1052 g_debug ("schedule %s to be installed to %s on next boot",
1053 filename, fu_device_get_id (device));
Richard Hughescc3de2e2017-09-13 19:28:17 +01001054 fu_device_set_filename_pending (device, filename);
Richard Hughescff38bc2016-12-12 12:03:37 +00001055
1056 /* add to database */
Richard Hughes68982c62017-09-13 15:40:14 +01001057 if (!fu_pending_add_device (pending, device, error))
Richard Hughescff38bc2016-12-12 12:03:37 +00001058 return FALSE;
1059
1060 /* next boot we run offline */
1061 return fu_plugin_runner_offline_setup (error);
1062}
1063
1064gboolean
1065fu_plugin_runner_verify (FuPlugin *plugin,
1066 FuDevice *device,
1067 FuPluginVerifyFlags flags,
1068 GError **error)
1069{
1070 FuPluginPrivate *priv = GET_PRIVATE (plugin);
Richard Hughes7b8b2022016-12-12 16:15:03 +00001071 FuPluginVerifyFunc func = NULL;
Richard Hughesababbb72017-06-15 20:18:36 +01001072 GPtrArray *checksums;
Richard Hughescff38bc2016-12-12 12:03:37 +00001073
1074 /* not enabled */
1075 if (!priv->enabled)
1076 return TRUE;
1077
Richard Hughesababbb72017-06-15 20:18:36 +01001078 /* clear any existing verification checksums */
1079 checksums = fu_device_get_checksums (device);
1080 g_ptr_array_set_size (checksums, 0);
1081
Richard Hughescff38bc2016-12-12 12:03:37 +00001082 /* optional */
1083 g_module_symbol (priv->module, "fu_plugin_verify", (gpointer *) &func);
1084 if (func == NULL)
1085 return TRUE;
1086 g_debug ("performing verify() on %s", priv->name);
1087 if (!func (plugin, device, flags, error)) {
1088 g_prefix_error (error, "failed to verify %s: ", priv->name);
Richard Hughesd0905142016-03-13 09:46:49 +00001089 return FALSE;
1090 }
1091 return TRUE;
1092}
1093
Richard Hughesd0905142016-03-13 09:46:49 +00001094gboolean
Richard Hughescff38bc2016-12-12 12:03:37 +00001095fu_plugin_runner_unlock (FuPlugin *plugin, FuDevice *device, GError **error)
Richard Hughesd0905142016-03-13 09:46:49 +00001096{
Richard Hughescff38bc2016-12-12 12:03:37 +00001097 guint64 flags;
1098 FuPluginPrivate *priv = GET_PRIVATE (plugin);
Richard Hughes7b8b2022016-12-12 16:15:03 +00001099 FuPluginDeviceFunc func = NULL;
Richard Hughesd0905142016-03-13 09:46:49 +00001100
1101 /* not enabled */
Richard Hughescff38bc2016-12-12 12:03:37 +00001102 if (!priv->enabled)
1103 return TRUE;
1104
1105 /* final check */
1106 flags = fu_device_get_flags (device);
1107 if ((flags & FWUPD_DEVICE_FLAG_LOCKED) == 0) {
1108 g_set_error (error,
1109 FWUPD_ERROR,
1110 FWUPD_ERROR_NOT_SUPPORTED,
1111 "Device %s is not locked",
1112 fu_device_get_id (device));
1113 return FALSE;
1114 }
1115
1116 /* optional */
1117 g_module_symbol (priv->module, "fu_plugin_unlock", (gpointer *) &func);
1118 if (func != NULL) {
1119 g_debug ("performing unlock() on %s", priv->name);
1120 if (!func (plugin, device, error)) {
Richard Hughes7b8b2022016-12-12 16:15:03 +00001121 g_prefix_error (error, "failed to unlock %s: ", priv->name);
Richard Hughescff38bc2016-12-12 12:03:37 +00001122 return FALSE;
1123 }
1124 }
1125
1126 /* update with correct flags */
1127 flags = fu_device_get_flags (device);
1128 fu_device_set_flags (device, flags &= ~FWUPD_DEVICE_FLAG_LOCKED);
1129 fu_device_set_modified (device, (guint64) g_get_real_time () / G_USEC_PER_SEC);
1130 return TRUE;
1131}
1132
1133gboolean
1134fu_plugin_runner_update (FuPlugin *plugin,
Richard Hughesa785a1c2017-08-25 16:00:58 +01001135 FuDevice *device,
1136 GBytes *blob_cab,
1137 GBytes *blob_fw,
1138 FwupdInstallFlags flags,
1139 GError **error)
Richard Hughescff38bc2016-12-12 12:03:37 +00001140{
1141 FuPluginPrivate *priv = GET_PRIVATE (plugin);
Richard Hughesa785a1c2017-08-25 16:00:58 +01001142 FuPluginUpdateFunc update_func;
Richard Hughescff38bc2016-12-12 12:03:37 +00001143 g_autoptr(FuPending) pending = NULL;
Richard Hughes68982c62017-09-13 15:40:14 +01001144 g_autoptr(FuDevice) device_pending = NULL;
Richard Hughescff38bc2016-12-12 12:03:37 +00001145 GError *error_update = NULL;
Richard Hughesf556d372017-06-15 19:49:18 +01001146 GPtrArray *checksums;
Richard Hughescff38bc2016-12-12 12:03:37 +00001147
1148 /* not enabled */
1149 if (!priv->enabled)
Richard Hughesd0905142016-03-13 09:46:49 +00001150 return TRUE;
1151
1152 /* optional */
Richard Hughesa785a1c2017-08-25 16:00:58 +01001153 g_module_symbol (priv->module, "fu_plugin_update", (gpointer *) &update_func);
1154 if (update_func == NULL) {
1155 g_set_error_literal (error,
1156 FWUPD_ERROR,
1157 FWUPD_ERROR_NOT_SUPPORTED,
1158 "No update possible");
1159 return FALSE;
1160 }
Richard Hughesd0905142016-03-13 09:46:49 +00001161
Richard Hughesa785a1c2017-08-25 16:00:58 +01001162 /* just schedule this for the next reboot */
Richard Hughescff38bc2016-12-12 12:03:37 +00001163 if (flags & FWUPD_INSTALL_FLAG_OFFLINE) {
Richard Hughesa785a1c2017-08-25 16:00:58 +01001164 return fu_plugin_runner_schedule_update (plugin,
1165 device,
1166 blob_cab,
1167 error);
Richard Hughescff38bc2016-12-12 12:03:37 +00001168 }
1169
1170 /* cancel the pending action */
1171 if (!fu_plugin_runner_offline_invalidate (error))
1172 return FALSE;
1173
1174 /* online */
Richard Hughescff38bc2016-12-12 12:03:37 +00001175 pending = fu_pending_new ();
Richard Hughes68982c62017-09-13 15:40:14 +01001176 device_pending = fu_pending_get_device (pending, fu_device_get_id (device), NULL);
Richard Hughesa785a1c2017-08-25 16:00:58 +01001177 if (!update_func (plugin, device, blob_fw, flags, &error_update)) {
Richard Hughescff38bc2016-12-12 12:03:37 +00001178 /* save the error to the database */
Richard Hughes68982c62017-09-13 15:40:14 +01001179 if (device_pending != NULL) {
1180 fu_pending_set_error_msg (pending, device,
Richard Hughescff38bc2016-12-12 12:03:37 +00001181 error_update->message, NULL);
1182 }
1183 g_propagate_error (error, error_update);
1184 return FALSE;
1185 }
1186
Richard Hughesf556d372017-06-15 19:49:18 +01001187 /* no longer valid */
1188 checksums = fu_device_get_checksums (device);
1189 g_ptr_array_set_size (checksums, 0);
1190
Richard Hughescff38bc2016-12-12 12:03:37 +00001191 /* cleanup */
Richard Hughes68982c62017-09-13 15:40:14 +01001192 if (device_pending != NULL) {
Richard Hughescff38bc2016-12-12 12:03:37 +00001193 const gchar *tmp;
1194
1195 /* update pending database */
Richard Hughes68982c62017-09-13 15:40:14 +01001196 fu_pending_set_state (pending, device,
Richard Hughescff38bc2016-12-12 12:03:37 +00001197 FWUPD_UPDATE_STATE_SUCCESS, NULL);
1198
1199 /* delete cab file */
Richard Hughescc3de2e2017-09-13 19:28:17 +01001200 tmp = fu_device_get_filename_pending (device_pending);
Richard Hughescff38bc2016-12-12 12:03:37 +00001201 if (tmp != NULL && g_str_has_prefix (tmp, LIBEXECDIR)) {
1202 g_autoptr(GError) error_local = NULL;
1203 g_autoptr(GFile) file = NULL;
1204 file = g_file_new_for_path (tmp);
1205 if (!g_file_delete (file, NULL, &error_local)) {
1206 g_set_error (error,
1207 FWUPD_ERROR,
1208 FWUPD_ERROR_INVALID_FILE,
1209 "Failed to delete %s: %s",
1210 tmp, error_local->message);
1211 return FALSE;
1212 }
1213 }
1214 }
Richard Hughesd0905142016-03-13 09:46:49 +00001215 return TRUE;
1216}
Richard Hughescff38bc2016-12-12 12:03:37 +00001217
1218gboolean
1219fu_plugin_runner_clear_results (FuPlugin *plugin, FuDevice *device, GError **error)
1220{
1221 FuPluginPrivate *priv = GET_PRIVATE (plugin);
Richard Hughes7b8b2022016-12-12 16:15:03 +00001222 FuPluginDeviceFunc func = NULL;
Richard Hughescff38bc2016-12-12 12:03:37 +00001223 g_autoptr(GError) error_local = NULL;
Richard Hughes68982c62017-09-13 15:40:14 +01001224 g_autoptr(FuDevice) device_pending = NULL;
Richard Hughescff38bc2016-12-12 12:03:37 +00001225 g_autoptr(FuPending) pending = NULL;
1226
1227 /* not enabled */
1228 if (!priv->enabled)
1229 return TRUE;
1230
1231 /* use the plugin if the vfunc is provided */
1232 g_module_symbol (priv->module, "fu_plugin_clear_result", (gpointer *) &func);
1233 if (func != NULL) {
1234 g_debug ("performing clear_result() on %s", priv->name);
1235 if (!func (plugin, device, error)) {
1236 g_prefix_error (error, "failed to clear_result %s: ", priv->name);
1237 return FALSE;
1238 }
1239 return TRUE;
1240 }
1241
1242 /* handled using the database */
1243 pending = fu_pending_new ();
Richard Hughes68982c62017-09-13 15:40:14 +01001244 device_pending = fu_pending_get_device (pending,
Richard Hughescff38bc2016-12-12 12:03:37 +00001245 fu_device_get_id (device),
1246 &error_local);
Richard Hughes68982c62017-09-13 15:40:14 +01001247 if (device_pending == NULL) {
Richard Hughescff38bc2016-12-12 12:03:37 +00001248 g_set_error (error,
1249 FWUPD_ERROR,
1250 FWUPD_ERROR_INVALID_FILE,
1251 "Failed to find %s in pending database: %s",
1252 fu_device_get_id (device),
1253 error_local->message);
1254 return FALSE;
1255 }
1256
1257 /* remove from pending database */
Richard Hughes68982c62017-09-13 15:40:14 +01001258 return fu_pending_remove_device (pending, device, error);
Richard Hughescff38bc2016-12-12 12:03:37 +00001259}
1260
1261gboolean
1262fu_plugin_runner_get_results (FuPlugin *plugin, FuDevice *device, GError **error)
1263{
1264 FuPluginPrivate *priv = GET_PRIVATE (plugin);
Richard Hughes7b8b2022016-12-12 16:15:03 +00001265 FuPluginDeviceFunc func = NULL;
Richard Hughescff38bc2016-12-12 12:03:37 +00001266 FwupdUpdateState update_state;
1267 const gchar *tmp;
1268 g_autoptr(GError) error_local = NULL;
Richard Hughes68982c62017-09-13 15:40:14 +01001269 g_autoptr(FuDevice) device_pending = NULL;
Richard Hughescff38bc2016-12-12 12:03:37 +00001270 g_autoptr(FuPending) pending = NULL;
1271
1272 /* not enabled */
1273 if (!priv->enabled)
1274 return TRUE;
1275
1276 /* use the plugin if the vfunc is provided */
1277 g_module_symbol (priv->module, "fu_plugin_get_results", (gpointer *) &func);
1278 if (func != NULL) {
1279 g_debug ("performing get_results() on %s", priv->name);
1280 if (!func (plugin, device, error)) {
1281 g_prefix_error (error, "failed to get_results %s: ", priv->name);
1282 return FALSE;
1283 }
1284 return TRUE;
1285 }
1286
1287 /* handled using the database */
1288 pending = fu_pending_new ();
Richard Hughes68982c62017-09-13 15:40:14 +01001289 device_pending = fu_pending_get_device (pending,
Richard Hughescff38bc2016-12-12 12:03:37 +00001290 fu_device_get_id (device),
1291 &error_local);
Richard Hughes68982c62017-09-13 15:40:14 +01001292 if (device_pending == NULL) {
Richard Hughescff38bc2016-12-12 12:03:37 +00001293 g_set_error (error,
1294 FWUPD_ERROR,
1295 FWUPD_ERROR_NOTHING_TO_DO,
1296 "Failed to find %s in pending database: %s",
1297 fu_device_get_id (device),
1298 error_local->message);
1299 return FALSE;
1300 }
1301
1302 /* copy the important parts from the pending device to the real one */
Richard Hughescc3de2e2017-09-13 19:28:17 +01001303 update_state = fu_device_get_update_state (device_pending);
Richard Hughescff38bc2016-12-12 12:03:37 +00001304 if (update_state == FWUPD_UPDATE_STATE_UNKNOWN ||
1305 update_state == FWUPD_UPDATE_STATE_PENDING) {
1306 g_set_error (error,
1307 FWUPD_ERROR,
1308 FWUPD_ERROR_NOTHING_TO_DO,
1309 "Device %s has not been updated offline yet",
1310 fu_device_get_id (device));
1311 return FALSE;
1312 }
1313
1314 /* copy */
1315 fu_device_set_update_state (device, update_state);
Richard Hughescc3de2e2017-09-13 19:28:17 +01001316 tmp = fu_device_get_update_error (device_pending);
Richard Hughescff38bc2016-12-12 12:03:37 +00001317 if (tmp != NULL)
1318 fu_device_set_update_error (device, tmp);
Richard Hughescc3de2e2017-09-13 19:28:17 +01001319 tmp = fu_device_get_version (device_pending);
Richard Hughescff38bc2016-12-12 12:03:37 +00001320 if (tmp != NULL)
1321 fu_device_set_version (device, tmp);
Richard Hughescc3de2e2017-09-13 19:28:17 +01001322 tmp = fu_device_get_version_new (device_pending);
Richard Hughescff38bc2016-12-12 12:03:37 +00001323 if (tmp != NULL)
Richard Hughescc3de2e2017-09-13 19:28:17 +01001324 fu_device_set_version_new (device, tmp);
Richard Hughescff38bc2016-12-12 12:03:37 +00001325 return TRUE;
1326}
1327
Richard Hughes08a37992017-09-12 12:57:43 +01001328/**
1329 * fu_plugin_get_order:
1330 * @plugin: a #FuPlugin
1331 *
1332 * Gets the plugin order, where higher numbers are run after lower
1333 * numbers.
1334 *
1335 * Returns: the integer value
1336 **/
1337guint
1338fu_plugin_get_order (FuPlugin *plugin)
1339{
1340 FuPluginPrivate *priv = fu_plugin_get_instance_private (plugin);
1341 return priv->order;
1342}
1343
1344/**
1345 * fu_plugin_set_order:
1346 * @plugin: a #FuPlugin
1347 * @order: a integer value
1348 *
1349 * Sets the plugin order, where higher numbers are run after lower
1350 * numbers.
1351 **/
1352void
1353fu_plugin_set_order (FuPlugin *plugin, guint order)
1354{
1355 FuPluginPrivate *priv = fu_plugin_get_instance_private (plugin);
1356 priv->order = order;
1357}
1358
1359/**
1360 * fu_plugin_add_rule:
1361 * @plugin: a #FuPlugin
1362 * @rule: a #FuPluginRule, e.g. %FU_PLUGIN_RULE_CONFLICTS
Richard Hughes4eada342017-10-03 21:20:32 +01001363 * @name: a plugin name, e.g. `upower`
Richard Hughes08a37992017-09-12 12:57:43 +01001364 *
1365 * If the plugin name is found, the rule will be used to sort the plugin list,
1366 * for example the plugin specified by @name will be ordered after this plugin
1367 * when %FU_PLUGIN_RULE_RUN_AFTER is used.
1368 *
1369 * NOTE: The depsolver is iterative and may not solve overly-complicated rules;
1370 * If depsolving fails then fwupd will not start.
1371 **/
1372void
1373fu_plugin_add_rule (FuPlugin *plugin, FuPluginRule rule, const gchar *name)
1374{
1375 FuPluginPrivate *priv = fu_plugin_get_instance_private (plugin);
1376 g_ptr_array_add (priv->rules[rule], g_strdup (name));
1377}
1378
1379/**
1380 * fu_plugin_get_rules:
1381 * @plugin: a #FuPlugin
1382 * @rule: a #FuPluginRule, e.g. %FU_PLUGIN_RULE_CONFLICTS
1383 *
1384 * Gets the plugin IDs that should be run after this plugin.
1385 *
1386 * Returns: (element-type utf8) (transfer none): the list of plugin names, e.g. ['appstream']
1387 **/
1388GPtrArray *
1389fu_plugin_get_rules (FuPlugin *plugin, FuPluginRule rule)
1390{
1391 FuPluginPrivate *priv = fu_plugin_get_instance_private (plugin);
1392 return priv->rules[rule];
1393}
1394
Richard Hughescff38bc2016-12-12 12:03:37 +00001395static void
1396fu_plugin_class_init (FuPluginClass *klass)
1397{
1398 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1399 object_class->finalize = fu_plugin_finalize;
1400 signals[SIGNAL_DEVICE_ADDED] =
1401 g_signal_new ("device-added",
1402 G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
1403 G_STRUCT_OFFSET (FuPluginClass, device_added),
1404 NULL, NULL, g_cclosure_marshal_VOID__OBJECT,
1405 G_TYPE_NONE, 1, FU_TYPE_DEVICE);
1406 signals[SIGNAL_DEVICE_REMOVED] =
1407 g_signal_new ("device-removed",
1408 G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
1409 G_STRUCT_OFFSET (FuPluginClass, device_removed),
1410 NULL, NULL, g_cclosure_marshal_VOID__OBJECT,
1411 G_TYPE_NONE, 1, FU_TYPE_DEVICE);
Richard Hughese1fd34d2017-08-24 14:19:51 +01001412 signals[SIGNAL_DEVICE_REGISTER] =
1413 g_signal_new ("device-register",
1414 G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
1415 G_STRUCT_OFFSET (FuPluginClass, device_register),
1416 NULL, NULL, g_cclosure_marshal_VOID__OBJECT,
1417 G_TYPE_NONE, 1, FU_TYPE_DEVICE);
Richard Hughescff38bc2016-12-12 12:03:37 +00001418 signals[SIGNAL_STATUS_CHANGED] =
1419 g_signal_new ("status-changed",
1420 G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
1421 G_STRUCT_OFFSET (FuPluginClass, status_changed),
1422 NULL, NULL, g_cclosure_marshal_VOID__UINT,
1423 G_TYPE_NONE, 1, G_TYPE_UINT);
1424 signals[SIGNAL_PERCENTAGE_CHANGED] =
1425 g_signal_new ("percentage-changed",
1426 G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
1427 G_STRUCT_OFFSET (FuPluginClass, percentage_changed),
1428 NULL, NULL, g_cclosure_marshal_VOID__UINT,
1429 G_TYPE_NONE, 1, G_TYPE_UINT);
Richard Hughes362d6d72017-01-07 21:42:14 +00001430 signals[SIGNAL_RECOLDPLUG] =
1431 g_signal_new ("recoldplug",
1432 G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
1433 G_STRUCT_OFFSET (FuPluginClass, recoldplug),
1434 NULL, NULL, g_cclosure_marshal_VOID__VOID,
1435 G_TYPE_NONE, 0);
Richard Hughesb0829032017-01-10 09:27:08 +00001436 signals[SIGNAL_SET_COLDPLUG_DELAY] =
1437 g_signal_new ("set-coldplug-delay",
1438 G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
1439 G_STRUCT_OFFSET (FuPluginClass, set_coldplug_delay),
1440 NULL, NULL, g_cclosure_marshal_VOID__UINT,
1441 G_TYPE_NONE, 1, G_TYPE_UINT);
Richard Hughescff38bc2016-12-12 12:03:37 +00001442}
1443
1444static void
1445fu_plugin_init (FuPlugin *plugin)
1446{
1447 FuPluginPrivate *priv = GET_PRIVATE (plugin);
1448 priv->enabled = TRUE;
1449 priv->devices = g_hash_table_new_full (g_str_hash, g_str_equal,
1450 g_free, (GDestroyNotify) g_object_unref);
Richard Hughese8b5db62017-07-17 14:18:22 +01001451 priv->devices_delay = g_hash_table_new (g_direct_hash, g_direct_equal);
Richard Hughes08a37992017-09-12 12:57:43 +01001452 for (guint i = 0; i < FU_PLUGIN_RULE_LAST; i++)
1453 priv->rules[i] = g_ptr_array_new_with_free_func (g_free);
Richard Hughescff38bc2016-12-12 12:03:37 +00001454}
1455
1456static void
1457fu_plugin_finalize (GObject *object)
1458{
1459 FuPlugin *plugin = FU_PLUGIN (object);
1460 FuPluginPrivate *priv = GET_PRIVATE (plugin);
1461 FuPluginInitFunc func = NULL;
1462
1463 /* optional */
1464 if (priv->module != NULL) {
1465 g_module_symbol (priv->module, "fu_plugin_destroy", (gpointer *) &func);
1466 if (func != NULL) {
1467 g_debug ("performing destroy() on %s", priv->name);
1468 func (plugin);
1469 }
1470 }
1471
Richard Hughes08a37992017-09-12 12:57:43 +01001472 for (guint i = 0; i < FU_PLUGIN_RULE_LAST; i++)
1473 g_ptr_array_unref (priv->rules[i]);
1474
Richard Hughescff38bc2016-12-12 12:03:37 +00001475 if (priv->usb_ctx != NULL)
1476 g_object_unref (priv->usb_ctx);
Richard Hughesb8f8db22017-04-25 15:56:00 +01001477 if (priv->hwids != NULL)
Richard Hughesd7704d42017-08-08 20:29:09 +01001478 g_object_unref (priv->hwids);
Richard Hughes9c028f02017-10-28 21:14:28 +01001479 if (priv->quirks != NULL)
1480 g_object_unref (priv->quirks);
Richard Hughes1354ea92017-09-19 15:58:31 +01001481 if (priv->supported_guids != NULL)
1482 g_ptr_array_unref (priv->supported_guids);
Richard Hughes49e5e052017-09-03 12:15:41 +01001483 if (priv->smbios != NULL)
1484 g_object_unref (priv->smbios);
Richard Hughes576c0122017-02-24 09:47:00 +00001485#ifndef RUNNING_ON_VALGRIND
Richard Hughescff38bc2016-12-12 12:03:37 +00001486 if (priv->module != NULL)
1487 g_module_close (priv->module);
Richard Hughes576c0122017-02-24 09:47:00 +00001488#endif
Richard Hughescff38bc2016-12-12 12:03:37 +00001489 g_hash_table_unref (priv->devices);
Richard Hughesae3d65f2016-12-16 09:38:01 +00001490 g_hash_table_unref (priv->devices_delay);
Richard Hughescff38bc2016-12-12 12:03:37 +00001491 g_free (priv->name);
1492 g_free (priv->data);
1493
1494 G_OBJECT_CLASS (fu_plugin_parent_class)->finalize (object);
1495}
1496
1497FuPlugin *
1498fu_plugin_new (void)
1499{
1500 FuPlugin *plugin;
1501 plugin = g_object_new (FU_TYPE_PLUGIN, NULL);
1502 return plugin;
1503}