blob: fe5712e15e68ef0ba48041a44a1ce5ad563d5fd9 [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
Richard Hughesd3d96cc2017-11-14 11:34:33 +0000871 /* no object loaded */
872 if (priv->module == NULL)
873 return TRUE;
874
Richard Hughes0d7fdb32017-11-11 20:23:14 +0000875 /* optional */
876 g_module_symbol (priv->module, symbol_name, (gpointer *) &func);
877 if (func == NULL)
878 return TRUE;
879 g_debug ("performing %s() on %s", symbol_name + 10, priv->name);
880 if (!func (plugin, device, error)) {
881 g_prefix_error (error, "failed to run %s(%s) on %s: ",
882 symbol_name + 10,
883 fu_device_get_id (device),
884 priv->name);
885 return FALSE;
886 }
887 return TRUE;
888}
889
Richard Hughesd0905142016-03-13 09:46:49 +0000890gboolean
Richard Hughescff38bc2016-12-12 12:03:37 +0000891fu_plugin_runner_coldplug (FuPlugin *plugin, GError **error)
Richard Hughesd0905142016-03-13 09:46:49 +0000892{
Richard Hughescff38bc2016-12-12 12:03:37 +0000893 FuPluginPrivate *priv = GET_PRIVATE (plugin);
Richard Hughes7b8b2022016-12-12 16:15:03 +0000894 FuPluginStartupFunc func = NULL;
Richard Hughesd0905142016-03-13 09:46:49 +0000895
896 /* not enabled */
Richard Hughescff38bc2016-12-12 12:03:37 +0000897 if (!priv->enabled)
Richard Hughesd0905142016-03-13 09:46:49 +0000898 return TRUE;
899
900 /* optional */
Richard Hughescff38bc2016-12-12 12:03:37 +0000901 g_module_symbol (priv->module, "fu_plugin_coldplug", (gpointer *) &func);
902 if (func == NULL)
Richard Hughesd0905142016-03-13 09:46:49 +0000903 return TRUE;
Richard Hughescff38bc2016-12-12 12:03:37 +0000904 g_debug ("performing coldplug() on %s", priv->name);
905 if (!func (plugin, error)) {
906 g_prefix_error (error, "failed to coldplug %s: ", priv->name);
907 return FALSE;
908 }
909 return TRUE;
910}
911
Richard Hughes7b8b2022016-12-12 16:15:03 +0000912gboolean
Richard Hughes46487c92017-01-07 21:26:34 +0000913fu_plugin_runner_coldplug_prepare (FuPlugin *plugin, GError **error)
914{
915 FuPluginPrivate *priv = GET_PRIVATE (plugin);
916 FuPluginStartupFunc func = NULL;
917
918 /* not enabled */
919 if (!priv->enabled)
920 return TRUE;
921
922 /* optional */
923 g_module_symbol (priv->module, "fu_plugin_coldplug_prepare", (gpointer *) &func);
924 if (func == NULL)
925 return TRUE;
926 g_debug ("performing coldplug_prepare() on %s", priv->name);
927 if (!func (plugin, error)) {
928 g_prefix_error (error, "failed to prepare for coldplug %s: ", priv->name);
929 return FALSE;
930 }
931 return TRUE;
932}
933
934gboolean
935fu_plugin_runner_coldplug_cleanup (FuPlugin *plugin, GError **error)
936{
937 FuPluginPrivate *priv = GET_PRIVATE (plugin);
938 FuPluginStartupFunc func = NULL;
939
940 /* not enabled */
941 if (!priv->enabled)
942 return TRUE;
943
944 /* optional */
945 g_module_symbol (priv->module, "fu_plugin_coldplug_cleanup", (gpointer *) &func);
946 if (func == NULL)
947 return TRUE;
948 g_debug ("performing coldplug_cleanup() on %s", priv->name);
949 if (!func (plugin, error)) {
950 g_prefix_error (error, "failed to cleanup coldplug %s: ", priv->name);
951 return FALSE;
952 }
953 return TRUE;
954}
955
956gboolean
Richard Hughes7b8b2022016-12-12 16:15:03 +0000957fu_plugin_runner_update_prepare (FuPlugin *plugin, FuDevice *device, GError **error)
958{
Richard Hughes0d7fdb32017-11-11 20:23:14 +0000959 return fu_plugin_runner_device_generic (plugin, device,
960 "fu_plugin_update_prepare", error);
Richard Hughes7b8b2022016-12-12 16:15:03 +0000961}
962
963gboolean
964fu_plugin_runner_update_cleanup (FuPlugin *plugin, FuDevice *device, GError **error)
965{
Richard Hughes0d7fdb32017-11-11 20:23:14 +0000966 return fu_plugin_runner_device_generic (plugin, device,
967 "fu_plugin_update_cleanup", error);
968}
Richard Hughes7b8b2022016-12-12 16:15:03 +0000969
Richard Hughes0d7fdb32017-11-11 20:23:14 +0000970gboolean
971fu_plugin_runner_update_attach (FuPlugin *plugin, FuDevice *device, GError **error)
972{
973 return fu_plugin_runner_device_generic (plugin, device,
974 "fu_plugin_update_attach", error);
975}
Richard Hughes7b8b2022016-12-12 16:15:03 +0000976
Richard Hughes0d7fdb32017-11-11 20:23:14 +0000977gboolean
978fu_plugin_runner_update_detach (FuPlugin *plugin, FuDevice *device, GError **error)
979{
980 return fu_plugin_runner_device_generic (plugin, device,
981 "fu_plugin_update_detach", error);
982}
983
984gboolean
985fu_plugin_runner_update_reload (FuPlugin *plugin, FuDevice *device, GError **error)
986{
987 return fu_plugin_runner_device_generic (plugin, device,
988 "fu_plugin_update_reload", error);
Richard Hughes7b8b2022016-12-12 16:15:03 +0000989}
990
Richard Hughese1fd34d2017-08-24 14:19:51 +0100991void
992fu_plugin_runner_device_register (FuPlugin *plugin, FuDevice *device)
993{
994 FuPluginPrivate *priv = GET_PRIVATE (plugin);
995 FuPluginDeviceRegisterFunc func = NULL;
996
997 /* not enabled */
998 if (!priv->enabled)
999 return;
1000
1001 /* optional */
1002 g_module_symbol (priv->module, "fu_plugin_device_registered", (gpointer *) &func);
1003 if (func != NULL) {
1004 g_debug ("performing device_added() on %s", priv->name);
1005 func (plugin, device);
1006 }
1007}
1008
Richard Hughescff38bc2016-12-12 12:03:37 +00001009static gboolean
1010fu_plugin_runner_schedule_update (FuPlugin *plugin,
1011 FuDevice *device,
1012 GBytes *blob_cab,
1013 GError **error)
1014{
1015 gchar tmpname[] = {"XXXXXX.cap"};
1016 g_autofree gchar *dirname = NULL;
1017 g_autofree gchar *filename = NULL;
Richard Hughes68982c62017-09-13 15:40:14 +01001018 g_autoptr(FuDevice) res_tmp = NULL;
Richard Hughescff38bc2016-12-12 12:03:37 +00001019 g_autoptr(FuPending) pending = NULL;
1020 g_autoptr(GFile) file = NULL;
1021
1022 /* id already exists */
1023 pending = fu_pending_new ();
1024 res_tmp = fu_pending_get_device (pending, fu_device_get_id (device), NULL);
1025 if (res_tmp != NULL) {
1026 g_set_error (error,
1027 FWUPD_ERROR,
1028 FWUPD_ERROR_ALREADY_PENDING,
1029 "%s is already scheduled to be updated",
1030 fu_device_get_id (device));
1031 return FALSE;
1032 }
1033
1034 /* create directory */
1035 dirname = g_build_filename (LOCALSTATEDIR, "lib", "fwupd", NULL);
1036 file = g_file_new_for_path (dirname);
1037 if (!g_file_query_exists (file, NULL)) {
1038 if (!g_file_make_directory_with_parents (file, NULL, error))
1039 return FALSE;
1040 }
1041
1042 /* get a random filename */
1043 for (guint i = 0; i < 6; i++)
1044 tmpname[i] = (gchar) g_random_int_range ('A', 'Z');
1045 filename = g_build_filename (dirname, tmpname, NULL);
1046
1047 /* just copy to the temp file */
1048 fu_plugin_set_status (plugin, FWUPD_STATUS_SCHEDULING);
1049 if (!g_file_set_contents (filename,
1050 g_bytes_get_data (blob_cab, NULL),
1051 (gssize) g_bytes_get_size (blob_cab),
1052 error))
1053 return FALSE;
1054
1055 /* schedule for next boot */
1056 g_debug ("schedule %s to be installed to %s on next boot",
1057 filename, fu_device_get_id (device));
Richard Hughescc3de2e2017-09-13 19:28:17 +01001058 fu_device_set_filename_pending (device, filename);
Richard Hughescff38bc2016-12-12 12:03:37 +00001059
1060 /* add to database */
Richard Hughes68982c62017-09-13 15:40:14 +01001061 if (!fu_pending_add_device (pending, device, error))
Richard Hughescff38bc2016-12-12 12:03:37 +00001062 return FALSE;
1063
1064 /* next boot we run offline */
1065 return fu_plugin_runner_offline_setup (error);
1066}
1067
1068gboolean
1069fu_plugin_runner_verify (FuPlugin *plugin,
1070 FuDevice *device,
1071 FuPluginVerifyFlags flags,
1072 GError **error)
1073{
1074 FuPluginPrivate *priv = GET_PRIVATE (plugin);
Richard Hughes7b8b2022016-12-12 16:15:03 +00001075 FuPluginVerifyFunc func = NULL;
Richard Hughesababbb72017-06-15 20:18:36 +01001076 GPtrArray *checksums;
Richard Hughescff38bc2016-12-12 12:03:37 +00001077
1078 /* not enabled */
1079 if (!priv->enabled)
1080 return TRUE;
1081
Richard Hughesababbb72017-06-15 20:18:36 +01001082 /* clear any existing verification checksums */
1083 checksums = fu_device_get_checksums (device);
1084 g_ptr_array_set_size (checksums, 0);
1085
Richard Hughescff38bc2016-12-12 12:03:37 +00001086 /* optional */
1087 g_module_symbol (priv->module, "fu_plugin_verify", (gpointer *) &func);
1088 if (func == NULL)
1089 return TRUE;
1090 g_debug ("performing verify() on %s", priv->name);
1091 if (!func (plugin, device, flags, error)) {
1092 g_prefix_error (error, "failed to verify %s: ", priv->name);
Richard Hughesd0905142016-03-13 09:46:49 +00001093 return FALSE;
1094 }
1095 return TRUE;
1096}
1097
Richard Hughesd0905142016-03-13 09:46:49 +00001098gboolean
Richard Hughescff38bc2016-12-12 12:03:37 +00001099fu_plugin_runner_unlock (FuPlugin *plugin, FuDevice *device, GError **error)
Richard Hughesd0905142016-03-13 09:46:49 +00001100{
Richard Hughescff38bc2016-12-12 12:03:37 +00001101 guint64 flags;
1102 FuPluginPrivate *priv = GET_PRIVATE (plugin);
Richard Hughes7b8b2022016-12-12 16:15:03 +00001103 FuPluginDeviceFunc func = NULL;
Richard Hughesd0905142016-03-13 09:46:49 +00001104
1105 /* not enabled */
Richard Hughescff38bc2016-12-12 12:03:37 +00001106 if (!priv->enabled)
1107 return TRUE;
1108
1109 /* final check */
1110 flags = fu_device_get_flags (device);
1111 if ((flags & FWUPD_DEVICE_FLAG_LOCKED) == 0) {
1112 g_set_error (error,
1113 FWUPD_ERROR,
1114 FWUPD_ERROR_NOT_SUPPORTED,
1115 "Device %s is not locked",
1116 fu_device_get_id (device));
1117 return FALSE;
1118 }
1119
1120 /* optional */
1121 g_module_symbol (priv->module, "fu_plugin_unlock", (gpointer *) &func);
1122 if (func != NULL) {
1123 g_debug ("performing unlock() on %s", priv->name);
1124 if (!func (plugin, device, error)) {
Richard Hughes7b8b2022016-12-12 16:15:03 +00001125 g_prefix_error (error, "failed to unlock %s: ", priv->name);
Richard Hughescff38bc2016-12-12 12:03:37 +00001126 return FALSE;
1127 }
1128 }
1129
1130 /* update with correct flags */
1131 flags = fu_device_get_flags (device);
1132 fu_device_set_flags (device, flags &= ~FWUPD_DEVICE_FLAG_LOCKED);
1133 fu_device_set_modified (device, (guint64) g_get_real_time () / G_USEC_PER_SEC);
1134 return TRUE;
1135}
1136
1137gboolean
1138fu_plugin_runner_update (FuPlugin *plugin,
Richard Hughesa785a1c2017-08-25 16:00:58 +01001139 FuDevice *device,
1140 GBytes *blob_cab,
1141 GBytes *blob_fw,
1142 FwupdInstallFlags flags,
1143 GError **error)
Richard Hughescff38bc2016-12-12 12:03:37 +00001144{
1145 FuPluginPrivate *priv = GET_PRIVATE (plugin);
Richard Hughesa785a1c2017-08-25 16:00:58 +01001146 FuPluginUpdateFunc update_func;
Richard Hughescff38bc2016-12-12 12:03:37 +00001147 g_autoptr(FuPending) pending = NULL;
Richard Hughes68982c62017-09-13 15:40:14 +01001148 g_autoptr(FuDevice) device_pending = NULL;
Richard Hughescff38bc2016-12-12 12:03:37 +00001149 GError *error_update = NULL;
Richard Hughesf556d372017-06-15 19:49:18 +01001150 GPtrArray *checksums;
Richard Hughescff38bc2016-12-12 12:03:37 +00001151
1152 /* not enabled */
1153 if (!priv->enabled)
Richard Hughesd0905142016-03-13 09:46:49 +00001154 return TRUE;
1155
1156 /* optional */
Richard Hughesa785a1c2017-08-25 16:00:58 +01001157 g_module_symbol (priv->module, "fu_plugin_update", (gpointer *) &update_func);
1158 if (update_func == NULL) {
1159 g_set_error_literal (error,
1160 FWUPD_ERROR,
1161 FWUPD_ERROR_NOT_SUPPORTED,
1162 "No update possible");
1163 return FALSE;
1164 }
Richard Hughesd0905142016-03-13 09:46:49 +00001165
Richard Hughesa785a1c2017-08-25 16:00:58 +01001166 /* just schedule this for the next reboot */
Richard Hughescff38bc2016-12-12 12:03:37 +00001167 if (flags & FWUPD_INSTALL_FLAG_OFFLINE) {
Richard Hughesa785a1c2017-08-25 16:00:58 +01001168 return fu_plugin_runner_schedule_update (plugin,
1169 device,
1170 blob_cab,
1171 error);
Richard Hughescff38bc2016-12-12 12:03:37 +00001172 }
1173
1174 /* cancel the pending action */
1175 if (!fu_plugin_runner_offline_invalidate (error))
1176 return FALSE;
1177
1178 /* online */
Richard Hughescff38bc2016-12-12 12:03:37 +00001179 pending = fu_pending_new ();
Richard Hughes68982c62017-09-13 15:40:14 +01001180 device_pending = fu_pending_get_device (pending, fu_device_get_id (device), NULL);
Richard Hughesa785a1c2017-08-25 16:00:58 +01001181 if (!update_func (plugin, device, blob_fw, flags, &error_update)) {
Richard Hughescff38bc2016-12-12 12:03:37 +00001182 /* save the error to the database */
Richard Hughes68982c62017-09-13 15:40:14 +01001183 if (device_pending != NULL) {
1184 fu_pending_set_error_msg (pending, device,
Richard Hughescff38bc2016-12-12 12:03:37 +00001185 error_update->message, NULL);
1186 }
1187 g_propagate_error (error, error_update);
1188 return FALSE;
1189 }
1190
Richard Hughesf556d372017-06-15 19:49:18 +01001191 /* no longer valid */
1192 checksums = fu_device_get_checksums (device);
1193 g_ptr_array_set_size (checksums, 0);
1194
Richard Hughescff38bc2016-12-12 12:03:37 +00001195 /* cleanup */
Richard Hughes68982c62017-09-13 15:40:14 +01001196 if (device_pending != NULL) {
Richard Hughescff38bc2016-12-12 12:03:37 +00001197 const gchar *tmp;
1198
1199 /* update pending database */
Richard Hughes68982c62017-09-13 15:40:14 +01001200 fu_pending_set_state (pending, device,
Richard Hughescff38bc2016-12-12 12:03:37 +00001201 FWUPD_UPDATE_STATE_SUCCESS, NULL);
1202
1203 /* delete cab file */
Richard Hughescc3de2e2017-09-13 19:28:17 +01001204 tmp = fu_device_get_filename_pending (device_pending);
Richard Hughescff38bc2016-12-12 12:03:37 +00001205 if (tmp != NULL && g_str_has_prefix (tmp, LIBEXECDIR)) {
1206 g_autoptr(GError) error_local = NULL;
1207 g_autoptr(GFile) file = NULL;
1208 file = g_file_new_for_path (tmp);
1209 if (!g_file_delete (file, NULL, &error_local)) {
1210 g_set_error (error,
1211 FWUPD_ERROR,
1212 FWUPD_ERROR_INVALID_FILE,
1213 "Failed to delete %s: %s",
1214 tmp, error_local->message);
1215 return FALSE;
1216 }
1217 }
1218 }
Richard Hughesd0905142016-03-13 09:46:49 +00001219 return TRUE;
1220}
Richard Hughescff38bc2016-12-12 12:03:37 +00001221
1222gboolean
1223fu_plugin_runner_clear_results (FuPlugin *plugin, FuDevice *device, GError **error)
1224{
1225 FuPluginPrivate *priv = GET_PRIVATE (plugin);
Richard Hughes7b8b2022016-12-12 16:15:03 +00001226 FuPluginDeviceFunc func = NULL;
Richard Hughescff38bc2016-12-12 12:03:37 +00001227 g_autoptr(GError) error_local = NULL;
Richard Hughes68982c62017-09-13 15:40:14 +01001228 g_autoptr(FuDevice) device_pending = NULL;
Richard Hughescff38bc2016-12-12 12:03:37 +00001229 g_autoptr(FuPending) pending = NULL;
1230
1231 /* not enabled */
1232 if (!priv->enabled)
1233 return TRUE;
1234
1235 /* use the plugin if the vfunc is provided */
1236 g_module_symbol (priv->module, "fu_plugin_clear_result", (gpointer *) &func);
1237 if (func != NULL) {
1238 g_debug ("performing clear_result() on %s", priv->name);
1239 if (!func (plugin, device, error)) {
1240 g_prefix_error (error, "failed to clear_result %s: ", priv->name);
1241 return FALSE;
1242 }
1243 return TRUE;
1244 }
1245
1246 /* handled using the database */
1247 pending = fu_pending_new ();
Richard Hughes68982c62017-09-13 15:40:14 +01001248 device_pending = fu_pending_get_device (pending,
Richard Hughescff38bc2016-12-12 12:03:37 +00001249 fu_device_get_id (device),
1250 &error_local);
Richard Hughes68982c62017-09-13 15:40:14 +01001251 if (device_pending == NULL) {
Richard Hughescff38bc2016-12-12 12:03:37 +00001252 g_set_error (error,
1253 FWUPD_ERROR,
1254 FWUPD_ERROR_INVALID_FILE,
1255 "Failed to find %s in pending database: %s",
1256 fu_device_get_id (device),
1257 error_local->message);
1258 return FALSE;
1259 }
1260
1261 /* remove from pending database */
Richard Hughes68982c62017-09-13 15:40:14 +01001262 return fu_pending_remove_device (pending, device, error);
Richard Hughescff38bc2016-12-12 12:03:37 +00001263}
1264
1265gboolean
1266fu_plugin_runner_get_results (FuPlugin *plugin, FuDevice *device, GError **error)
1267{
1268 FuPluginPrivate *priv = GET_PRIVATE (plugin);
Richard Hughes7b8b2022016-12-12 16:15:03 +00001269 FuPluginDeviceFunc func = NULL;
Richard Hughescff38bc2016-12-12 12:03:37 +00001270 FwupdUpdateState update_state;
1271 const gchar *tmp;
1272 g_autoptr(GError) error_local = NULL;
Richard Hughes68982c62017-09-13 15:40:14 +01001273 g_autoptr(FuDevice) device_pending = NULL;
Richard Hughescff38bc2016-12-12 12:03:37 +00001274 g_autoptr(FuPending) pending = NULL;
1275
1276 /* not enabled */
1277 if (!priv->enabled)
1278 return TRUE;
1279
1280 /* use the plugin if the vfunc is provided */
1281 g_module_symbol (priv->module, "fu_plugin_get_results", (gpointer *) &func);
1282 if (func != NULL) {
1283 g_debug ("performing get_results() on %s", priv->name);
1284 if (!func (plugin, device, error)) {
1285 g_prefix_error (error, "failed to get_results %s: ", priv->name);
1286 return FALSE;
1287 }
1288 return TRUE;
1289 }
1290
1291 /* handled using the database */
1292 pending = fu_pending_new ();
Richard Hughes68982c62017-09-13 15:40:14 +01001293 device_pending = fu_pending_get_device (pending,
Richard Hughescff38bc2016-12-12 12:03:37 +00001294 fu_device_get_id (device),
1295 &error_local);
Richard Hughes68982c62017-09-13 15:40:14 +01001296 if (device_pending == NULL) {
Richard Hughescff38bc2016-12-12 12:03:37 +00001297 g_set_error (error,
1298 FWUPD_ERROR,
1299 FWUPD_ERROR_NOTHING_TO_DO,
1300 "Failed to find %s in pending database: %s",
1301 fu_device_get_id (device),
1302 error_local->message);
1303 return FALSE;
1304 }
1305
1306 /* copy the important parts from the pending device to the real one */
Richard Hughescc3de2e2017-09-13 19:28:17 +01001307 update_state = fu_device_get_update_state (device_pending);
Richard Hughescff38bc2016-12-12 12:03:37 +00001308 if (update_state == FWUPD_UPDATE_STATE_UNKNOWN ||
1309 update_state == FWUPD_UPDATE_STATE_PENDING) {
1310 g_set_error (error,
1311 FWUPD_ERROR,
1312 FWUPD_ERROR_NOTHING_TO_DO,
1313 "Device %s has not been updated offline yet",
1314 fu_device_get_id (device));
1315 return FALSE;
1316 }
1317
1318 /* copy */
1319 fu_device_set_update_state (device, update_state);
Richard Hughescc3de2e2017-09-13 19:28:17 +01001320 tmp = fu_device_get_update_error (device_pending);
Richard Hughescff38bc2016-12-12 12:03:37 +00001321 if (tmp != NULL)
1322 fu_device_set_update_error (device, tmp);
Richard Hughescc3de2e2017-09-13 19:28:17 +01001323 tmp = fu_device_get_version (device_pending);
Richard Hughescff38bc2016-12-12 12:03:37 +00001324 if (tmp != NULL)
1325 fu_device_set_version (device, tmp);
Richard Hughescc3de2e2017-09-13 19:28:17 +01001326 tmp = fu_device_get_version_new (device_pending);
Richard Hughescff38bc2016-12-12 12:03:37 +00001327 if (tmp != NULL)
Richard Hughescc3de2e2017-09-13 19:28:17 +01001328 fu_device_set_version_new (device, tmp);
Richard Hughescff38bc2016-12-12 12:03:37 +00001329 return TRUE;
1330}
1331
Richard Hughes08a37992017-09-12 12:57:43 +01001332/**
1333 * fu_plugin_get_order:
1334 * @plugin: a #FuPlugin
1335 *
1336 * Gets the plugin order, where higher numbers are run after lower
1337 * numbers.
1338 *
1339 * Returns: the integer value
1340 **/
1341guint
1342fu_plugin_get_order (FuPlugin *plugin)
1343{
1344 FuPluginPrivate *priv = fu_plugin_get_instance_private (plugin);
1345 return priv->order;
1346}
1347
1348/**
1349 * fu_plugin_set_order:
1350 * @plugin: a #FuPlugin
1351 * @order: a integer value
1352 *
1353 * Sets the plugin order, where higher numbers are run after lower
1354 * numbers.
1355 **/
1356void
1357fu_plugin_set_order (FuPlugin *plugin, guint order)
1358{
1359 FuPluginPrivate *priv = fu_plugin_get_instance_private (plugin);
1360 priv->order = order;
1361}
1362
1363/**
1364 * fu_plugin_add_rule:
1365 * @plugin: a #FuPlugin
1366 * @rule: a #FuPluginRule, e.g. %FU_PLUGIN_RULE_CONFLICTS
Richard Hughes4eada342017-10-03 21:20:32 +01001367 * @name: a plugin name, e.g. `upower`
Richard Hughes08a37992017-09-12 12:57:43 +01001368 *
1369 * If the plugin name is found, the rule will be used to sort the plugin list,
1370 * for example the plugin specified by @name will be ordered after this plugin
1371 * when %FU_PLUGIN_RULE_RUN_AFTER is used.
1372 *
1373 * NOTE: The depsolver is iterative and may not solve overly-complicated rules;
1374 * If depsolving fails then fwupd will not start.
1375 **/
1376void
1377fu_plugin_add_rule (FuPlugin *plugin, FuPluginRule rule, const gchar *name)
1378{
1379 FuPluginPrivate *priv = fu_plugin_get_instance_private (plugin);
1380 g_ptr_array_add (priv->rules[rule], g_strdup (name));
1381}
1382
1383/**
1384 * fu_plugin_get_rules:
1385 * @plugin: a #FuPlugin
1386 * @rule: a #FuPluginRule, e.g. %FU_PLUGIN_RULE_CONFLICTS
1387 *
1388 * Gets the plugin IDs that should be run after this plugin.
1389 *
1390 * Returns: (element-type utf8) (transfer none): the list of plugin names, e.g. ['appstream']
1391 **/
1392GPtrArray *
1393fu_plugin_get_rules (FuPlugin *plugin, FuPluginRule rule)
1394{
1395 FuPluginPrivate *priv = fu_plugin_get_instance_private (plugin);
1396 return priv->rules[rule];
1397}
1398
Richard Hughescff38bc2016-12-12 12:03:37 +00001399static void
1400fu_plugin_class_init (FuPluginClass *klass)
1401{
1402 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1403 object_class->finalize = fu_plugin_finalize;
1404 signals[SIGNAL_DEVICE_ADDED] =
1405 g_signal_new ("device-added",
1406 G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
1407 G_STRUCT_OFFSET (FuPluginClass, device_added),
1408 NULL, NULL, g_cclosure_marshal_VOID__OBJECT,
1409 G_TYPE_NONE, 1, FU_TYPE_DEVICE);
1410 signals[SIGNAL_DEVICE_REMOVED] =
1411 g_signal_new ("device-removed",
1412 G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
1413 G_STRUCT_OFFSET (FuPluginClass, device_removed),
1414 NULL, NULL, g_cclosure_marshal_VOID__OBJECT,
1415 G_TYPE_NONE, 1, FU_TYPE_DEVICE);
Richard Hughese1fd34d2017-08-24 14:19:51 +01001416 signals[SIGNAL_DEVICE_REGISTER] =
1417 g_signal_new ("device-register",
1418 G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
1419 G_STRUCT_OFFSET (FuPluginClass, device_register),
1420 NULL, NULL, g_cclosure_marshal_VOID__OBJECT,
1421 G_TYPE_NONE, 1, FU_TYPE_DEVICE);
Richard Hughescff38bc2016-12-12 12:03:37 +00001422 signals[SIGNAL_STATUS_CHANGED] =
1423 g_signal_new ("status-changed",
1424 G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
1425 G_STRUCT_OFFSET (FuPluginClass, status_changed),
1426 NULL, NULL, g_cclosure_marshal_VOID__UINT,
1427 G_TYPE_NONE, 1, G_TYPE_UINT);
1428 signals[SIGNAL_PERCENTAGE_CHANGED] =
1429 g_signal_new ("percentage-changed",
1430 G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
1431 G_STRUCT_OFFSET (FuPluginClass, percentage_changed),
1432 NULL, NULL, g_cclosure_marshal_VOID__UINT,
1433 G_TYPE_NONE, 1, G_TYPE_UINT);
Richard Hughes362d6d72017-01-07 21:42:14 +00001434 signals[SIGNAL_RECOLDPLUG] =
1435 g_signal_new ("recoldplug",
1436 G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
1437 G_STRUCT_OFFSET (FuPluginClass, recoldplug),
1438 NULL, NULL, g_cclosure_marshal_VOID__VOID,
1439 G_TYPE_NONE, 0);
Richard Hughesb0829032017-01-10 09:27:08 +00001440 signals[SIGNAL_SET_COLDPLUG_DELAY] =
1441 g_signal_new ("set-coldplug-delay",
1442 G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
1443 G_STRUCT_OFFSET (FuPluginClass, set_coldplug_delay),
1444 NULL, NULL, g_cclosure_marshal_VOID__UINT,
1445 G_TYPE_NONE, 1, G_TYPE_UINT);
Richard Hughescff38bc2016-12-12 12:03:37 +00001446}
1447
1448static void
1449fu_plugin_init (FuPlugin *plugin)
1450{
1451 FuPluginPrivate *priv = GET_PRIVATE (plugin);
1452 priv->enabled = TRUE;
1453 priv->devices = g_hash_table_new_full (g_str_hash, g_str_equal,
1454 g_free, (GDestroyNotify) g_object_unref);
Richard Hughese8b5db62017-07-17 14:18:22 +01001455 priv->devices_delay = g_hash_table_new (g_direct_hash, g_direct_equal);
Richard Hughes08a37992017-09-12 12:57:43 +01001456 for (guint i = 0; i < FU_PLUGIN_RULE_LAST; i++)
1457 priv->rules[i] = g_ptr_array_new_with_free_func (g_free);
Richard Hughescff38bc2016-12-12 12:03:37 +00001458}
1459
1460static void
1461fu_plugin_finalize (GObject *object)
1462{
1463 FuPlugin *plugin = FU_PLUGIN (object);
1464 FuPluginPrivate *priv = GET_PRIVATE (plugin);
1465 FuPluginInitFunc func = NULL;
1466
1467 /* optional */
1468 if (priv->module != NULL) {
1469 g_module_symbol (priv->module, "fu_plugin_destroy", (gpointer *) &func);
1470 if (func != NULL) {
1471 g_debug ("performing destroy() on %s", priv->name);
1472 func (plugin);
1473 }
1474 }
1475
Richard Hughes08a37992017-09-12 12:57:43 +01001476 for (guint i = 0; i < FU_PLUGIN_RULE_LAST; i++)
1477 g_ptr_array_unref (priv->rules[i]);
1478
Richard Hughescff38bc2016-12-12 12:03:37 +00001479 if (priv->usb_ctx != NULL)
1480 g_object_unref (priv->usb_ctx);
Richard Hughesb8f8db22017-04-25 15:56:00 +01001481 if (priv->hwids != NULL)
Richard Hughesd7704d42017-08-08 20:29:09 +01001482 g_object_unref (priv->hwids);
Richard Hughes9c028f02017-10-28 21:14:28 +01001483 if (priv->quirks != NULL)
1484 g_object_unref (priv->quirks);
Richard Hughes1354ea92017-09-19 15:58:31 +01001485 if (priv->supported_guids != NULL)
1486 g_ptr_array_unref (priv->supported_guids);
Richard Hughes49e5e052017-09-03 12:15:41 +01001487 if (priv->smbios != NULL)
1488 g_object_unref (priv->smbios);
Richard Hughes576c0122017-02-24 09:47:00 +00001489#ifndef RUNNING_ON_VALGRIND
Richard Hughescff38bc2016-12-12 12:03:37 +00001490 if (priv->module != NULL)
1491 g_module_close (priv->module);
Richard Hughes576c0122017-02-24 09:47:00 +00001492#endif
Richard Hughescff38bc2016-12-12 12:03:37 +00001493 g_hash_table_unref (priv->devices);
Richard Hughesae3d65f2016-12-16 09:38:01 +00001494 g_hash_table_unref (priv->devices_delay);
Richard Hughescff38bc2016-12-12 12:03:37 +00001495 g_free (priv->name);
1496 g_free (priv->data);
1497
1498 G_OBJECT_CLASS (fu_plugin_parent_class)->finalize (object);
1499}
1500
1501FuPlugin *
1502fu_plugin_new (void)
1503{
1504 FuPlugin *plugin;
1505 plugin = g_object_new (FU_TYPE_PLUGIN, NULL);
1506 return plugin;
1507}