Richard Hughes | 02c90d8 | 2018-08-09 12:13:03 +0100 | [diff] [blame] | 1 | /* |
Richard Hughes | 2de8f13 | 2018-01-17 09:12:02 +0000 | [diff] [blame] | 2 | * Copyright (C) 2016-2018 Richard Hughes <richard@hughsie.com> |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 3 | * |
Mario Limonciello | 51308e6 | 2018-05-28 20:05:46 -0500 | [diff] [blame] | 4 | * SPDX-License-Identifier: LGPL-2.1+ |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
Richard Hughes | b08e7bc | 2018-09-11 10:51:13 +0100 | [diff] [blame] | 7 | #define G_LOG_DOMAIN "FuPlugin" |
| 8 | |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 9 | #include "config.h" |
| 10 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 11 | #include <fwupd.h> |
| 12 | #include <gmodule.h> |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 13 | #include <errno.h> |
| 14 | #include <string.h> |
Richard Hughes | 68f12dd | 2018-08-09 14:43:31 +0100 | [diff] [blame] | 15 | #include <unistd.h> |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 16 | #include <gio/gunixinputstream.h> |
Mario Limonciello | 6d0aa3d | 2017-02-28 08:22:27 -0600 | [diff] [blame] | 17 | #ifdef HAVE_VALGRIND |
Richard Hughes | 576c012 | 2017-02-24 09:47:00 +0000 | [diff] [blame] | 18 | #include <valgrind.h> |
Mario Limonciello | 6d0aa3d | 2017-02-28 08:22:27 -0600 | [diff] [blame] | 19 | #endif /* HAVE_VALGRIND */ |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 20 | |
Richard Hughes | 9dde04f | 2017-09-13 12:07:15 +0100 | [diff] [blame] | 21 | #include "fu-device-private.h" |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 22 | #include "fu-plugin-private.h" |
Richard Hughes | bc3a4e1 | 2018-01-06 22:41:47 +0000 | [diff] [blame] | 23 | #include "fu-history.h" |
Richard Hughes | 37d0943 | 2018-09-09 10:39:45 +0100 | [diff] [blame] | 24 | #include "fu-mutex.h" |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 25 | |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 26 | /** |
| 27 | * SECTION:fu-plugin |
| 28 | * @short_description: a daemon plugin |
| 29 | * |
| 30 | * An object that represents a plugin run by the daemon. |
| 31 | * |
| 32 | * See also: #FuDevice |
| 33 | */ |
| 34 | |
Richard Hughes | b082903 | 2017-01-10 09:27:08 +0000 | [diff] [blame] | 35 | #define FU_PLUGIN_COLDPLUG_DELAY_MAXIMUM 3000u /* ms */ |
| 36 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 37 | static void fu_plugin_finalize (GObject *object); |
| 38 | |
| 39 | typedef struct { |
| 40 | GModule *module; |
| 41 | GUsbContext *usb_ctx; |
| 42 | gboolean enabled; |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 43 | guint order; |
Richard Hughes | 81c427c | 2018-08-06 15:20:17 +0100 | [diff] [blame] | 44 | guint priority; |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 45 | GPtrArray *rules[FU_PLUGIN_RULE_LAST]; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 46 | gchar *name; |
Richard Hughes | d7704d4 | 2017-08-08 20:29:09 +0100 | [diff] [blame] | 47 | FuHwids *hwids; |
Richard Hughes | 9c028f0 | 2017-10-28 21:14:28 +0100 | [diff] [blame] | 48 | FuQuirks *quirks; |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 49 | GHashTable *runtime_versions; |
Richard Hughes | 34e0dab | 2018-04-20 16:43:00 +0100 | [diff] [blame] | 50 | GHashTable *compile_versions; |
Richard Hughes | 1354ea9 | 2017-09-19 15:58:31 +0100 | [diff] [blame] | 51 | GPtrArray *supported_guids; |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 52 | GPtrArray *udev_subsystems; |
Richard Hughes | 1354ea9 | 2017-09-19 15:58:31 +0100 | [diff] [blame] | 53 | FuSmbios *smbios; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 54 | GHashTable *devices; /* platform_id:GObject */ |
Richard Hughes | 37d0943 | 2018-09-09 10:39:45 +0100 | [diff] [blame] | 55 | FuMutex *devices_mutex; |
Richard Hughes | 80b79bb | 2018-01-11 21:11:06 +0000 | [diff] [blame] | 56 | GHashTable *report_metadata; /* key:value */ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 57 | FuPluginData *data; |
| 58 | } FuPluginPrivate; |
| 59 | |
| 60 | enum { |
| 61 | SIGNAL_DEVICE_ADDED, |
| 62 | SIGNAL_DEVICE_REMOVED, |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 63 | SIGNAL_DEVICE_REGISTER, |
Richard Hughes | 362d6d7 | 2017-01-07 21:42:14 +0000 | [diff] [blame] | 64 | SIGNAL_RECOLDPLUG, |
Richard Hughes | b082903 | 2017-01-10 09:27:08 +0000 | [diff] [blame] | 65 | SIGNAL_SET_COLDPLUG_DELAY, |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 66 | SIGNAL_LAST |
| 67 | }; |
| 68 | |
| 69 | static guint signals[SIGNAL_LAST] = { 0 }; |
| 70 | |
| 71 | G_DEFINE_TYPE_WITH_PRIVATE (FuPlugin, fu_plugin, G_TYPE_OBJECT) |
| 72 | #define GET_PRIVATE(o) (fu_plugin_get_instance_private (o)) |
| 73 | |
| 74 | typedef const gchar *(*FuPluginGetNameFunc) (void); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 75 | typedef void (*FuPluginInitFunc) (FuPlugin *self); |
| 76 | typedef gboolean (*FuPluginStartupFunc) (FuPlugin *self, |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 77 | GError **error); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 78 | typedef void (*FuPluginDeviceRegisterFunc) (FuPlugin *self, |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 79 | FuDevice *device); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 80 | typedef gboolean (*FuPluginDeviceFunc) (FuPlugin *self, |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 81 | FuDevice *device, |
| 82 | GError **error); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 83 | typedef gboolean (*FuPluginFlaggedDeviceFunc) (FuPlugin *self, |
Mario Limonciello | e3b1a3f | 2018-08-21 13:01:45 -0500 | [diff] [blame] | 84 | FwupdInstallFlags flags, |
| 85 | FuDevice *device, |
| 86 | GError **error); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 87 | typedef gboolean (*FuPluginDeviceArrayFunc) (FuPlugin *self, |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 88 | GPtrArray *devices, |
| 89 | GError **error); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 90 | typedef gboolean (*FuPluginVerifyFunc) (FuPlugin *self, |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 91 | FuDevice *device, |
| 92 | FuPluginVerifyFlags flags, |
| 93 | GError **error); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 94 | typedef gboolean (*FuPluginUpdateFunc) (FuPlugin *self, |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 95 | FuDevice *device, |
| 96 | GBytes *blob_fw, |
| 97 | FwupdInstallFlags flags, |
| 98 | GError **error); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 99 | typedef gboolean (*FuPluginUsbDeviceAddedFunc) (FuPlugin *self, |
Richard Hughes | ff70441 | 2018-09-04 11:28:32 +0100 | [diff] [blame] | 100 | FuUsbDevice *device, |
Richard Hughes | 104f651 | 2017-11-24 11:44:57 +0000 | [diff] [blame] | 101 | GError **error); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 102 | typedef gboolean (*FuPluginUdevDeviceAddedFunc) (FuPlugin *self, |
Richard Hughes | ff70441 | 2018-09-04 11:28:32 +0100 | [diff] [blame] | 103 | FuUdevDevice *device, |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 104 | GError **error); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 105 | |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 106 | /** |
| 107 | * fu_plugin_get_name: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 108 | * @self: A #FuPlugin |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 109 | * |
| 110 | * Gets the plugin name. |
| 111 | * |
| 112 | * Returns: a plugin name, or %NULL for unknown. |
| 113 | * |
| 114 | * Since: 0.8.0 |
| 115 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 116 | const gchar * |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 117 | fu_plugin_get_name (FuPlugin *self) |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 118 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 119 | FuPluginPrivate *priv = GET_PRIVATE (self); |
| 120 | g_return_val_if_fail (FU_IS_PLUGIN (self), NULL); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 121 | return priv->name; |
| 122 | } |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 123 | |
Richard Hughes | 3483410 | 2017-11-21 21:55:00 +0000 | [diff] [blame] | 124 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 125 | fu_plugin_set_name (FuPlugin *self, const gchar *name) |
Richard Hughes | 3483410 | 2017-11-21 21:55:00 +0000 | [diff] [blame] | 126 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 127 | FuPluginPrivate *priv = GET_PRIVATE (self); |
| 128 | g_return_if_fail (FU_IS_PLUGIN (self)); |
Richard Hughes | 3483410 | 2017-11-21 21:55:00 +0000 | [diff] [blame] | 129 | g_return_if_fail (name != NULL); |
| 130 | g_free (priv->name); |
| 131 | priv->name = g_strdup (name); |
| 132 | } |
| 133 | |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 134 | /** |
| 135 | * fu_plugin_cache_lookup: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 136 | * @self: A #FuPlugin |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 137 | * @id: the key |
| 138 | * |
| 139 | * Finds an object in the per-plugin cache. |
| 140 | * |
| 141 | * Returns: (transfer none): a #GObject, or %NULL for unfound. |
| 142 | * |
| 143 | * Since: 0.8.0 |
| 144 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 145 | gpointer |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 146 | fu_plugin_cache_lookup (FuPlugin *self, const gchar *id) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 147 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 148 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 37d0943 | 2018-09-09 10:39:45 +0100 | [diff] [blame] | 149 | g_autoptr(FuMutexLocker) locker = fu_mutex_read_locker_new (priv->devices_mutex); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 150 | g_return_val_if_fail (FU_IS_PLUGIN (self), NULL); |
Richard Hughes | ccd78a9 | 2017-01-11 16:57:41 +0000 | [diff] [blame] | 151 | g_return_val_if_fail (id != NULL, NULL); |
Richard Hughes | 37d0943 | 2018-09-09 10:39:45 +0100 | [diff] [blame] | 152 | g_return_val_if_fail (locker != NULL, NULL); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 153 | return g_hash_table_lookup (priv->devices, id); |
| 154 | } |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 155 | |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 156 | /** |
| 157 | * fu_plugin_cache_add: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 158 | * @self: A #FuPlugin |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 159 | * @id: the key |
| 160 | * @dev: a #GObject, typically a #FuDevice |
| 161 | * |
| 162 | * Adds an object to the per-plugin cache. |
| 163 | * |
| 164 | * Since: 0.8.0 |
| 165 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 166 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 167 | fu_plugin_cache_add (FuPlugin *self, const gchar *id, gpointer dev) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 168 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 169 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 37d0943 | 2018-09-09 10:39:45 +0100 | [diff] [blame] | 170 | g_autoptr(FuMutexLocker) locker = fu_mutex_write_locker_new (priv->devices_mutex); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 171 | g_return_if_fail (FU_IS_PLUGIN (self)); |
Richard Hughes | ccd78a9 | 2017-01-11 16:57:41 +0000 | [diff] [blame] | 172 | g_return_if_fail (id != NULL); |
Richard Hughes | 37d0943 | 2018-09-09 10:39:45 +0100 | [diff] [blame] | 173 | g_return_if_fail (locker != NULL); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 174 | g_hash_table_insert (priv->devices, g_strdup (id), g_object_ref (dev)); |
| 175 | } |
| 176 | |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 177 | /** |
| 178 | * fu_plugin_cache_remove: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 179 | * @self: A #FuPlugin |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 180 | * @id: the key |
| 181 | * |
| 182 | * Removes an object from the per-plugin cache. |
| 183 | * |
| 184 | * Since: 0.8.0 |
| 185 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 186 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 187 | fu_plugin_cache_remove (FuPlugin *self, const gchar *id) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 188 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 189 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 37d0943 | 2018-09-09 10:39:45 +0100 | [diff] [blame] | 190 | g_autoptr(FuMutexLocker) locker = fu_mutex_write_locker_new (priv->devices_mutex); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 191 | g_return_if_fail (FU_IS_PLUGIN (self)); |
Richard Hughes | ccd78a9 | 2017-01-11 16:57:41 +0000 | [diff] [blame] | 192 | g_return_if_fail (id != NULL); |
Richard Hughes | 37d0943 | 2018-09-09 10:39:45 +0100 | [diff] [blame] | 193 | g_return_if_fail (locker != NULL); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 194 | g_hash_table_remove (priv->devices, id); |
| 195 | } |
| 196 | |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 197 | /** |
| 198 | * fu_plugin_get_data: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 199 | * @self: A #FuPlugin |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 200 | * |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 201 | * Gets the per-plugin allocated private data. This will return %NULL unless |
| 202 | * fu_plugin_alloc_data() has been called by the plugin. |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 203 | * |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 204 | * Returns: (transfer none): a pointer to a structure, or %NULL for unset. |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 205 | * |
| 206 | * Since: 0.8.0 |
| 207 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 208 | FuPluginData * |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 209 | fu_plugin_get_data (FuPlugin *self) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 210 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 211 | FuPluginPrivate *priv = GET_PRIVATE (self); |
| 212 | g_return_val_if_fail (FU_IS_PLUGIN (self), NULL); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 213 | return priv->data; |
| 214 | } |
| 215 | |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 216 | /** |
| 217 | * fu_plugin_alloc_data: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 218 | * @self: A #FuPlugin |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 219 | * @data_sz: the size to allocate |
| 220 | * |
| 221 | * Allocates the per-plugin allocated private data. |
| 222 | * |
| 223 | * Returns: (transfer full): a pointer to a structure, or %NULL for unset. |
| 224 | * |
| 225 | * Since: 0.8.0 |
| 226 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 227 | FuPluginData * |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 228 | fu_plugin_alloc_data (FuPlugin *self, gsize data_sz) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 229 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 230 | FuPluginPrivate *priv = GET_PRIVATE (self); |
| 231 | g_return_val_if_fail (FU_IS_PLUGIN (self), NULL); |
Richard Hughes | 44dee88 | 2017-01-11 08:31:10 +0000 | [diff] [blame] | 232 | if (priv->data != NULL) { |
| 233 | g_critical ("fu_plugin_alloc_data() already used by plugin"); |
| 234 | return priv->data; |
| 235 | } |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 236 | priv->data = g_malloc0 (data_sz); |
| 237 | return priv->data; |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 238 | } |
| 239 | |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 240 | /** |
| 241 | * fu_plugin_get_usb_context: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 242 | * @self: A #FuPlugin |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 243 | * |
| 244 | * Gets the shared USB context that all plugins can use. |
| 245 | * |
| 246 | * Returns: (transfer none): a #GUsbContext. |
| 247 | * |
| 248 | * Since: 0.8.0 |
| 249 | **/ |
Richard Hughes | bc93e4a | 2016-12-08 17:29:51 +0000 | [diff] [blame] | 250 | GUsbContext * |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 251 | fu_plugin_get_usb_context (FuPlugin *self) |
Richard Hughes | bc93e4a | 2016-12-08 17:29:51 +0000 | [diff] [blame] | 252 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 253 | FuPluginPrivate *priv = GET_PRIVATE (self); |
| 254 | g_return_val_if_fail (FU_IS_PLUGIN (self), NULL); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 255 | return priv->usb_ctx; |
Richard Hughes | bc93e4a | 2016-12-08 17:29:51 +0000 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 259 | fu_plugin_set_usb_context (FuPlugin *self, GUsbContext *usb_ctx) |
Richard Hughes | bc93e4a | 2016-12-08 17:29:51 +0000 | [diff] [blame] | 260 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 261 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 262 | g_set_object (&priv->usb_ctx, usb_ctx); |
| 263 | } |
| 264 | |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 265 | /** |
| 266 | * fu_plugin_get_enabled: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 267 | * @self: A #FuPlugin |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 268 | * |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 269 | * Returns if the plugin is enabled. Plugins may self-disable using |
| 270 | * fu_plugin_set_enabled() or can be disabled by the daemon. |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 271 | * |
| 272 | * Returns: %TRUE if the plugin is currently enabled. |
| 273 | * |
| 274 | * Since: 0.8.0 |
| 275 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 276 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 277 | fu_plugin_get_enabled (FuPlugin *self) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 278 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 279 | FuPluginPrivate *priv = GET_PRIVATE (self); |
| 280 | g_return_val_if_fail (FU_IS_PLUGIN (self), FALSE); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 281 | return priv->enabled; |
Richard Hughes | bc93e4a | 2016-12-08 17:29:51 +0000 | [diff] [blame] | 282 | } |
| 283 | |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 284 | /** |
| 285 | * fu_plugin_set_enabled: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 286 | * @self: A #FuPlugin |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 287 | * @enabled: the enabled value |
| 288 | * |
| 289 | * Enables or disables a plugin. Plugins can self-disable at any point. |
| 290 | * |
| 291 | * Since: 0.8.0 |
| 292 | **/ |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 293 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 294 | fu_plugin_set_enabled (FuPlugin *self, gboolean enabled) |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 295 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 296 | FuPluginPrivate *priv = GET_PRIVATE (self); |
| 297 | g_return_if_fail (FU_IS_PLUGIN (self)); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 298 | priv->enabled = enabled; |
| 299 | } |
| 300 | |
Richard Hughes | 1e456bc | 2018-05-10 20:16:16 +0100 | [diff] [blame] | 301 | gchar * |
| 302 | fu_plugin_guess_name_from_fn (const gchar *filename) |
| 303 | { |
| 304 | const gchar *prefix = "libfu_plugin_"; |
| 305 | gchar *name; |
| 306 | gchar *str = g_strstr_len (filename, -1, prefix); |
| 307 | if (str == NULL) |
| 308 | return NULL; |
| 309 | name = g_strdup (str + strlen (prefix)); |
| 310 | g_strdelimit (name, ".", '\0'); |
| 311 | return name; |
| 312 | } |
| 313 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 314 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 315 | fu_plugin_open (FuPlugin *self, const gchar *filename, GError **error) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 316 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 317 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 318 | FuPluginInitFunc func = NULL; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 319 | |
| 320 | priv->module = g_module_open (filename, 0); |
| 321 | if (priv->module == NULL) { |
| 322 | g_set_error (error, |
| 323 | G_IO_ERROR, |
| 324 | G_IO_ERROR_FAILED, |
| 325 | "failed to open plugin: %s", |
| 326 | g_module_error ()); |
| 327 | return FALSE; |
| 328 | } |
| 329 | |
| 330 | /* set automatically */ |
Richard Hughes | 1e456bc | 2018-05-10 20:16:16 +0100 | [diff] [blame] | 331 | if (priv->name == NULL) |
| 332 | priv->name = fu_plugin_guess_name_from_fn (filename); |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 333 | |
| 334 | /* optional */ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 335 | g_module_symbol (priv->module, "fu_plugin_init", (gpointer *) &func); |
| 336 | if (func != NULL) { |
| 337 | g_debug ("performing init() on %s", filename); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 338 | func (self); |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 339 | } |
| 340 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 341 | return TRUE; |
| 342 | } |
| 343 | |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 344 | /** |
| 345 | * fu_plugin_device_add: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 346 | * @self: A #FuPlugin |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 347 | * @device: A #FuDevice |
| 348 | * |
| 349 | * Asks the daemon to add a device to the exported list. If this device ID |
| 350 | * has already been added by a different plugin then this request will be |
| 351 | * ignored. |
| 352 | * |
| 353 | * Plugins should use fu_plugin_device_add_delay() if they are not capable of |
| 354 | * actually flashing an image to the hardware so that higher-priority plugins |
| 355 | * can add the device themselves. |
| 356 | * |
| 357 | * Since: 0.8.0 |
| 358 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 359 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 360 | fu_plugin_device_add (FuPlugin *self, FuDevice *device) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 361 | { |
Richard Hughes | 5e44729 | 2018-04-27 14:25:54 +0100 | [diff] [blame] | 362 | GPtrArray *children; |
Richard Hughes | c125ec0 | 2018-09-05 19:35:17 +0100 | [diff] [blame] | 363 | g_autoptr(GError) error = NULL; |
Richard Hughes | 5e44729 | 2018-04-27 14:25:54 +0100 | [diff] [blame] | 364 | |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 365 | g_return_if_fail (FU_IS_PLUGIN (self)); |
Richard Hughes | ccd78a9 | 2017-01-11 16:57:41 +0000 | [diff] [blame] | 366 | g_return_if_fail (FU_IS_DEVICE (device)); |
| 367 | |
Richard Hughes | c125ec0 | 2018-09-05 19:35:17 +0100 | [diff] [blame] | 368 | /* ensure the device ID is set from the physical and logical IDs */ |
| 369 | if (!fu_device_ensure_id (device, &error)) { |
| 370 | g_warning ("ignoring add: %s", error->message); |
| 371 | return; |
| 372 | } |
| 373 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 374 | g_debug ("emit added from %s: %s", |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 375 | fu_plugin_get_name (self), |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 376 | fu_device_get_id (device)); |
| 377 | fu_device_set_created (device, (guint64) g_get_real_time () / G_USEC_PER_SEC); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 378 | fu_device_set_plugin (device, fu_plugin_get_name (self)); |
| 379 | g_signal_emit (self, signals[SIGNAL_DEVICE_ADDED], 0, device); |
Richard Hughes | 5e44729 | 2018-04-27 14:25:54 +0100 | [diff] [blame] | 380 | |
Richard Hughes | 128c016 | 2018-08-10 11:00:29 +0100 | [diff] [blame] | 381 | /* add children if they have not already been added */ |
Richard Hughes | 5e44729 | 2018-04-27 14:25:54 +0100 | [diff] [blame] | 382 | children = fu_device_get_children (device); |
| 383 | for (guint i = 0; i < children->len; i++) { |
| 384 | FuDevice *child = g_ptr_array_index (children, i); |
Richard Hughes | 128c016 | 2018-08-10 11:00:29 +0100 | [diff] [blame] | 385 | if (fu_device_get_created (child) == 0) |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 386 | fu_plugin_device_add (self, child); |
Richard Hughes | 5e44729 | 2018-04-27 14:25:54 +0100 | [diff] [blame] | 387 | } |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 388 | } |
| 389 | |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 390 | /** |
| 391 | * fu_plugin_device_register: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 392 | * @self: A #FuPlugin |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 393 | * @device: A #FuDevice |
| 394 | * |
| 395 | * Registers the device with other plugins so they can set metadata. |
| 396 | * |
| 397 | * Plugins do not have to call this manually as this is done automatically |
| 398 | * when using fu_plugin_device_add(). They may wish to use this manually |
| 399 | * if for intance the coldplug should be ignored based on the metadata |
| 400 | * set from other plugins. |
| 401 | * |
| 402 | * Since: 0.9.7 |
| 403 | **/ |
| 404 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 405 | fu_plugin_device_register (FuPlugin *self, FuDevice *device) |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 406 | { |
Richard Hughes | c125ec0 | 2018-09-05 19:35:17 +0100 | [diff] [blame] | 407 | g_autoptr(GError) error = NULL; |
| 408 | |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 409 | g_return_if_fail (FU_IS_PLUGIN (self)); |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 410 | g_return_if_fail (FU_IS_DEVICE (device)); |
| 411 | |
Richard Hughes | c125ec0 | 2018-09-05 19:35:17 +0100 | [diff] [blame] | 412 | /* ensure the device ID is set from the physical and logical IDs */ |
| 413 | if (!fu_device_ensure_id (device, &error)) { |
| 414 | g_warning ("ignoring registration: %s", error->message); |
| 415 | return; |
| 416 | } |
| 417 | |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 418 | g_debug ("emit device-register from %s: %s", |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 419 | fu_plugin_get_name (self), |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 420 | fu_device_get_id (device)); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 421 | g_signal_emit (self, signals[SIGNAL_DEVICE_REGISTER], 0, device); |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 422 | } |
| 423 | |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 424 | /** |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 425 | * fu_plugin_device_remove: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 426 | * @self: A #FuPlugin |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 427 | * @device: A #FuDevice |
| 428 | * |
| 429 | * Asks the daemon to remove a device from the exported list. |
| 430 | * |
| 431 | * Since: 0.8.0 |
| 432 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 433 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 434 | fu_plugin_device_remove (FuPlugin *self, FuDevice *device) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 435 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 436 | g_return_if_fail (FU_IS_PLUGIN (self)); |
Richard Hughes | ccd78a9 | 2017-01-11 16:57:41 +0000 | [diff] [blame] | 437 | g_return_if_fail (FU_IS_DEVICE (device)); |
| 438 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 439 | g_debug ("emit removed from %s: %s", |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 440 | fu_plugin_get_name (self), |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 441 | fu_device_get_id (device)); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 442 | g_signal_emit (self, signals[SIGNAL_DEVICE_REMOVED], 0, device); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 443 | } |
| 444 | |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 445 | /** |
Richard Hughes | 2de8f13 | 2018-01-17 09:12:02 +0000 | [diff] [blame] | 446 | * fu_plugin_request_recoldplug: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 447 | * @self: A #FuPlugin |
Richard Hughes | 362d6d7 | 2017-01-07 21:42:14 +0000 | [diff] [blame] | 448 | * |
| 449 | * Ask all the plugins to coldplug all devices, which will include the prepare() |
| 450 | * and cleanup() phases. Duplicate devices added will be ignored. |
| 451 | * |
| 452 | * Since: 0.8.0 |
| 453 | **/ |
| 454 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 455 | fu_plugin_request_recoldplug (FuPlugin *self) |
Richard Hughes | 362d6d7 | 2017-01-07 21:42:14 +0000 | [diff] [blame] | 456 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 457 | g_return_if_fail (FU_IS_PLUGIN (self)); |
| 458 | g_signal_emit (self, signals[SIGNAL_RECOLDPLUG], 0); |
Richard Hughes | 362d6d7 | 2017-01-07 21:42:14 +0000 | [diff] [blame] | 459 | } |
| 460 | |
Richard Hughes | b082903 | 2017-01-10 09:27:08 +0000 | [diff] [blame] | 461 | /** |
Richard Hughes | b8f8db2 | 2017-04-25 15:56:00 +0100 | [diff] [blame] | 462 | * fu_plugin_check_hwid: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 463 | * @self: A #FuPlugin |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 464 | * @hwid: A Hardware ID GUID, e.g. `6de5d951-d755-576b-bd09-c5cf66b27234` |
Richard Hughes | b8f8db2 | 2017-04-25 15:56:00 +0100 | [diff] [blame] | 465 | * |
Richard Hughes | d7704d4 | 2017-08-08 20:29:09 +0100 | [diff] [blame] | 466 | * Checks to see if a specific GUID exists. All hardware IDs on a |
Richard Hughes | b8f8db2 | 2017-04-25 15:56:00 +0100 | [diff] [blame] | 467 | * specific system can be shown using the `fwupdmgr hwids` command. |
| 468 | * |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 469 | * Returns: %TRUE if the HwId is found on the system. |
| 470 | * |
Richard Hughes | b8f8db2 | 2017-04-25 15:56:00 +0100 | [diff] [blame] | 471 | * Since: 0.9.1 |
| 472 | **/ |
| 473 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 474 | fu_plugin_check_hwid (FuPlugin *self, const gchar *hwid) |
Richard Hughes | b8f8db2 | 2017-04-25 15:56:00 +0100 | [diff] [blame] | 475 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 476 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | b8f8db2 | 2017-04-25 15:56:00 +0100 | [diff] [blame] | 477 | if (priv->hwids == NULL) |
| 478 | return FALSE; |
Richard Hughes | d7704d4 | 2017-08-08 20:29:09 +0100 | [diff] [blame] | 479 | return fu_hwids_has_guid (priv->hwids, hwid); |
| 480 | } |
| 481 | |
| 482 | /** |
Richard Hughes | 69a5f35 | 2018-08-08 11:58:15 +0100 | [diff] [blame] | 483 | * fu_plugin_get_hwids: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 484 | * @self: A #FuPlugin |
Richard Hughes | 69a5f35 | 2018-08-08 11:58:15 +0100 | [diff] [blame] | 485 | * |
| 486 | * Returns all the HWIDs defined in the system. All hardware IDs on a |
| 487 | * specific system can be shown using the `fwupdmgr hwids` command. |
| 488 | * |
| 489 | * Returns: (transfer none) (element-type utf-8): An array of GUIDs |
| 490 | * |
| 491 | * Since: 1.1.1 |
| 492 | **/ |
| 493 | GPtrArray * |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 494 | fu_plugin_get_hwids (FuPlugin *self) |
Richard Hughes | 69a5f35 | 2018-08-08 11:58:15 +0100 | [diff] [blame] | 495 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 496 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 69a5f35 | 2018-08-08 11:58:15 +0100 | [diff] [blame] | 497 | if (priv->hwids == NULL) |
| 498 | return NULL; |
| 499 | return fu_hwids_get_guids (priv->hwids); |
| 500 | } |
| 501 | |
| 502 | /** |
Richard Hughes | 1354ea9 | 2017-09-19 15:58:31 +0100 | [diff] [blame] | 503 | * fu_plugin_check_supported: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 504 | * @self: A #FuPlugin |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 505 | * @guid: A Hardware ID GUID, e.g. `6de5d951-d755-576b-bd09-c5cf66b27234` |
Richard Hughes | 1354ea9 | 2017-09-19 15:58:31 +0100 | [diff] [blame] | 506 | * |
| 507 | * Checks to see if a specific device GUID is supported, i.e. available in the |
| 508 | * AppStream metadata. |
| 509 | * |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 510 | * Returns: %TRUE if the device is supported. |
| 511 | * |
Richard Hughes | 1354ea9 | 2017-09-19 15:58:31 +0100 | [diff] [blame] | 512 | * Since: 1.0.0 |
| 513 | **/ |
| 514 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 515 | fu_plugin_check_supported (FuPlugin *self, const gchar *guid) |
Richard Hughes | 1354ea9 | 2017-09-19 15:58:31 +0100 | [diff] [blame] | 516 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 517 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 1354ea9 | 2017-09-19 15:58:31 +0100 | [diff] [blame] | 518 | if (priv->supported_guids == NULL) |
| 519 | return FALSE; |
| 520 | for (guint i = 0; i < priv->supported_guids->len; i++) { |
| 521 | const gchar *guid_tmp = g_ptr_array_index (priv->supported_guids, i); |
| 522 | if (g_strcmp0 (guid, guid_tmp) == 0) |
| 523 | return TRUE; |
| 524 | } |
| 525 | return FALSE; |
| 526 | } |
| 527 | |
| 528 | /** |
Richard Hughes | d7704d4 | 2017-08-08 20:29:09 +0100 | [diff] [blame] | 529 | * fu_plugin_get_dmi_value: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 530 | * @self: A #FuPlugin |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 531 | * @dmi_id: A DMI ID, e.g. `BiosVersion` |
Richard Hughes | d7704d4 | 2017-08-08 20:29:09 +0100 | [diff] [blame] | 532 | * |
| 533 | * Gets a hardware DMI value. |
| 534 | * |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 535 | * Returns: The string, or %NULL |
| 536 | * |
Richard Hughes | d7704d4 | 2017-08-08 20:29:09 +0100 | [diff] [blame] | 537 | * Since: 0.9.7 |
| 538 | **/ |
| 539 | const gchar * |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 540 | fu_plugin_get_dmi_value (FuPlugin *self, const gchar *dmi_id) |
Richard Hughes | d7704d4 | 2017-08-08 20:29:09 +0100 | [diff] [blame] | 541 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 542 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | d7704d4 | 2017-08-08 20:29:09 +0100 | [diff] [blame] | 543 | if (priv->hwids == NULL) |
Richard Hughes | 7ef96b8 | 2017-08-23 18:28:24 +0100 | [diff] [blame] | 544 | return NULL; |
Richard Hughes | d7704d4 | 2017-08-08 20:29:09 +0100 | [diff] [blame] | 545 | return fu_hwids_get_value (priv->hwids, dmi_id); |
Richard Hughes | b8f8db2 | 2017-04-25 15:56:00 +0100 | [diff] [blame] | 546 | } |
| 547 | |
Richard Hughes | 49e5e05 | 2017-09-03 12:15:41 +0100 | [diff] [blame] | 548 | /** |
| 549 | * fu_plugin_get_smbios_string: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 550 | * @self: A #FuPlugin |
Richard Hughes | 49e5e05 | 2017-09-03 12:15:41 +0100 | [diff] [blame] | 551 | * @structure_type: A SMBIOS structure type, e.g. %FU_SMBIOS_STRUCTURE_TYPE_BIOS |
| 552 | * @offset: A SMBIOS offset |
| 553 | * |
| 554 | * Gets a hardware SMBIOS string. |
| 555 | * |
| 556 | * The @type and @offset can be referenced from the DMTF SMBIOS specification: |
| 557 | * https://www.dmtf.org/sites/default/files/standards/documents/DSP0134_3.1.1.pdf |
| 558 | * |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 559 | * Returns: A string, or %NULL |
| 560 | * |
Richard Hughes | 49e5e05 | 2017-09-03 12:15:41 +0100 | [diff] [blame] | 561 | * Since: 0.9.8 |
| 562 | **/ |
| 563 | const gchar * |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 564 | fu_plugin_get_smbios_string (FuPlugin *self, guint8 structure_type, guint8 offset) |
Richard Hughes | 49e5e05 | 2017-09-03 12:15:41 +0100 | [diff] [blame] | 565 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 566 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 49e5e05 | 2017-09-03 12:15:41 +0100 | [diff] [blame] | 567 | if (priv->smbios == NULL) |
| 568 | return NULL; |
| 569 | return fu_smbios_get_string (priv->smbios, structure_type, offset, NULL); |
| 570 | } |
| 571 | |
| 572 | /** |
| 573 | * fu_plugin_get_smbios_data: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 574 | * @self: A #FuPlugin |
Richard Hughes | 49e5e05 | 2017-09-03 12:15:41 +0100 | [diff] [blame] | 575 | * @structure_type: A SMBIOS structure type, e.g. %FU_SMBIOS_STRUCTURE_TYPE_BIOS |
| 576 | * |
| 577 | * Gets a hardware SMBIOS data. |
| 578 | * |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 579 | * Returns: (transfer none): A #GBytes, or %NULL |
| 580 | * |
Richard Hughes | 49e5e05 | 2017-09-03 12:15:41 +0100 | [diff] [blame] | 581 | * Since: 0.9.8 |
| 582 | **/ |
| 583 | GBytes * |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 584 | fu_plugin_get_smbios_data (FuPlugin *self, guint8 structure_type) |
Richard Hughes | 49e5e05 | 2017-09-03 12:15:41 +0100 | [diff] [blame] | 585 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 586 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 49e5e05 | 2017-09-03 12:15:41 +0100 | [diff] [blame] | 587 | if (priv->smbios == NULL) |
| 588 | return NULL; |
| 589 | return fu_smbios_get_data (priv->smbios, structure_type, NULL); |
| 590 | } |
| 591 | |
Richard Hughes | b8f8db2 | 2017-04-25 15:56:00 +0100 | [diff] [blame] | 592 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 593 | fu_plugin_set_hwids (FuPlugin *self, FuHwids *hwids) |
Richard Hughes | b8f8db2 | 2017-04-25 15:56:00 +0100 | [diff] [blame] | 594 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 595 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | d7704d4 | 2017-08-08 20:29:09 +0100 | [diff] [blame] | 596 | g_set_object (&priv->hwids, hwids); |
Richard Hughes | b8f8db2 | 2017-04-25 15:56:00 +0100 | [diff] [blame] | 597 | } |
| 598 | |
Richard Hughes | 49e5e05 | 2017-09-03 12:15:41 +0100 | [diff] [blame] | 599 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 600 | fu_plugin_set_supported (FuPlugin *self, GPtrArray *supported_guids) |
Richard Hughes | 1354ea9 | 2017-09-19 15:58:31 +0100 | [diff] [blame] | 601 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 602 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 1354ea9 | 2017-09-19 15:58:31 +0100 | [diff] [blame] | 603 | if (priv->supported_guids != NULL) |
| 604 | g_ptr_array_unref (priv->supported_guids); |
| 605 | priv->supported_guids = g_ptr_array_ref (supported_guids); |
| 606 | } |
| 607 | |
Richard Hughes | 9c028f0 | 2017-10-28 21:14:28 +0100 | [diff] [blame] | 608 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 609 | fu_plugin_set_udev_subsystems (FuPlugin *self, GPtrArray *udev_subsystems) |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 610 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 611 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 612 | if (priv->udev_subsystems != NULL) |
| 613 | g_ptr_array_unref (priv->udev_subsystems); |
| 614 | priv->udev_subsystems = g_ptr_array_ref (udev_subsystems); |
| 615 | } |
| 616 | |
| 617 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 618 | fu_plugin_set_quirks (FuPlugin *self, FuQuirks *quirks) |
Richard Hughes | 9c028f0 | 2017-10-28 21:14:28 +0100 | [diff] [blame] | 619 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 620 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 9c028f0 | 2017-10-28 21:14:28 +0100 | [diff] [blame] | 621 | g_set_object (&priv->quirks, quirks); |
| 622 | } |
| 623 | |
| 624 | /** |
| 625 | * fu_plugin_get_quirks: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 626 | * @self: A #FuPlugin |
Richard Hughes | 9c028f0 | 2017-10-28 21:14:28 +0100 | [diff] [blame] | 627 | * |
| 628 | * Returns the hardware database object. This can be used to discover device |
| 629 | * quirks or other device-specific settings. |
| 630 | * |
| 631 | * Returns: (transfer none): a #FuQuirks, or %NULL if not set |
| 632 | * |
| 633 | * Since: 1.0.1 |
| 634 | **/ |
| 635 | FuQuirks * |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 636 | fu_plugin_get_quirks (FuPlugin *self) |
Richard Hughes | 9c028f0 | 2017-10-28 21:14:28 +0100 | [diff] [blame] | 637 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 638 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 9c028f0 | 2017-10-28 21:14:28 +0100 | [diff] [blame] | 639 | return priv->quirks; |
| 640 | } |
| 641 | |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 642 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 643 | fu_plugin_set_runtime_versions (FuPlugin *self, GHashTable *runtime_versions) |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 644 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 645 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 646 | priv->runtime_versions = g_hash_table_ref (runtime_versions); |
| 647 | } |
| 648 | |
| 649 | /** |
| 650 | * fu_plugin_add_runtime_version: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 651 | * @self: A #FuPlugin |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 652 | * @component_id: An AppStream component id, e.g. "org.gnome.Software" |
| 653 | * @version: A version string, e.g. "1.2.3" |
| 654 | * |
| 655 | * Sets a runtime version of a specific dependancy. |
| 656 | * |
| 657 | * Since: 1.0.7 |
| 658 | **/ |
| 659 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 660 | fu_plugin_add_runtime_version (FuPlugin *self, |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 661 | const gchar *component_id, |
| 662 | const gchar *version) |
| 663 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 664 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | b01b486 | 2018-04-20 16:39:48 +0100 | [diff] [blame] | 665 | if (priv->runtime_versions == NULL) |
| 666 | return; |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 667 | g_hash_table_insert (priv->runtime_versions, |
| 668 | g_strdup (component_id), |
| 669 | g_strdup (version)); |
| 670 | } |
| 671 | |
Richard Hughes | 34e0dab | 2018-04-20 16:43:00 +0100 | [diff] [blame] | 672 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 673 | fu_plugin_set_compile_versions (FuPlugin *self, GHashTable *compile_versions) |
Richard Hughes | 34e0dab | 2018-04-20 16:43:00 +0100 | [diff] [blame] | 674 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 675 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 34e0dab | 2018-04-20 16:43:00 +0100 | [diff] [blame] | 676 | priv->compile_versions = g_hash_table_ref (compile_versions); |
| 677 | } |
| 678 | |
| 679 | /** |
| 680 | * fu_plugin_add_compile_version: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 681 | * @self: A #FuPlugin |
Richard Hughes | 34e0dab | 2018-04-20 16:43:00 +0100 | [diff] [blame] | 682 | * @component_id: An AppStream component id, e.g. "org.gnome.Software" |
| 683 | * @version: A version string, e.g. "1.2.3" |
| 684 | * |
| 685 | * Sets a compile-time version of a specific dependancy. |
| 686 | * |
| 687 | * Since: 1.0.7 |
| 688 | **/ |
| 689 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 690 | fu_plugin_add_compile_version (FuPlugin *self, |
Richard Hughes | 34e0dab | 2018-04-20 16:43:00 +0100 | [diff] [blame] | 691 | const gchar *component_id, |
| 692 | const gchar *version) |
| 693 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 694 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 34e0dab | 2018-04-20 16:43:00 +0100 | [diff] [blame] | 695 | if (priv->compile_versions == NULL) |
| 696 | return; |
| 697 | g_hash_table_insert (priv->compile_versions, |
| 698 | g_strdup (component_id), |
| 699 | g_strdup (version)); |
| 700 | } |
| 701 | |
Richard Hughes | 9c028f0 | 2017-10-28 21:14:28 +0100 | [diff] [blame] | 702 | /** |
| 703 | * fu_plugin_lookup_quirk_by_id: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 704 | * @self: A #FuPlugin |
Richard Hughes | 87fb9ff | 2018-06-28 12:55:59 +0100 | [diff] [blame] | 705 | * @group: A string, e.g. "DfuFlags" |
| 706 | * @key: An ID to match the entry, e.g. "Summary" |
Richard Hughes | 9c028f0 | 2017-10-28 21:14:28 +0100 | [diff] [blame] | 707 | * |
| 708 | * Looks up an entry in the hardware database using a string value. |
| 709 | * |
| 710 | * Returns: (transfer none): values from the database, or %NULL if not found |
| 711 | * |
| 712 | * Since: 1.0.1 |
| 713 | **/ |
| 714 | const gchar * |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 715 | fu_plugin_lookup_quirk_by_id (FuPlugin *self, const gchar *group, const gchar *key) |
Richard Hughes | 9c028f0 | 2017-10-28 21:14:28 +0100 | [diff] [blame] | 716 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 717 | FuPluginPrivate *priv = GET_PRIVATE (self); |
| 718 | g_return_val_if_fail (FU_IS_PLUGIN (self), NULL); |
Richard Hughes | 9c028f0 | 2017-10-28 21:14:28 +0100 | [diff] [blame] | 719 | |
Richard Hughes | 9c028f0 | 2017-10-28 21:14:28 +0100 | [diff] [blame] | 720 | /* exact ID */ |
Richard Hughes | 87fb9ff | 2018-06-28 12:55:59 +0100 | [diff] [blame] | 721 | return fu_quirks_lookup_by_id (priv->quirks, group, key); |
Richard Hughes | 9c028f0 | 2017-10-28 21:14:28 +0100 | [diff] [blame] | 722 | } |
| 723 | |
| 724 | /** |
Richard Hughes | 8fe7cdd | 2018-08-23 10:02:44 +0100 | [diff] [blame] | 725 | * fu_plugin_lookup_quirk_by_id_as_uint64: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 726 | * @self: A #FuPlugin |
Richard Hughes | 8fe7cdd | 2018-08-23 10:02:44 +0100 | [diff] [blame] | 727 | * @group: A string, e.g. "DfuFlags" |
| 728 | * @key: An ID to match the entry, e.g. "Size" |
| 729 | * |
| 730 | * Looks up an entry in the hardware database using a string key, returning |
| 731 | * an integer value. Values are assumed base 10, unless prefixed with "0x" |
| 732 | * where they are parsed as base 16. |
| 733 | * |
| 734 | * Returns: (transfer none): value from the database, or 0 if not found |
| 735 | * |
| 736 | * Since: 1.1.2 |
| 737 | **/ |
| 738 | guint64 |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 739 | fu_plugin_lookup_quirk_by_id_as_uint64 (FuPlugin *self, const gchar *group, const gchar *key) |
Richard Hughes | 8fe7cdd | 2018-08-23 10:02:44 +0100 | [diff] [blame] | 740 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 741 | return fu_common_strtoull (fu_plugin_lookup_quirk_by_id (self, group, key)); |
Richard Hughes | 8fe7cdd | 2018-08-23 10:02:44 +0100 | [diff] [blame] | 742 | } |
| 743 | |
| 744 | /** |
Richard Hughes | 1354ea9 | 2017-09-19 15:58:31 +0100 | [diff] [blame] | 745 | * fu_plugin_get_supported: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 746 | * @self: A #FuPlugin |
Richard Hughes | 1354ea9 | 2017-09-19 15:58:31 +0100 | [diff] [blame] | 747 | * |
| 748 | * Gets all the device GUIDs supported by the daemon. |
| 749 | * |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 750 | * Returns: (element-type utf8) (transfer none): GUIDs |
| 751 | * |
Richard Hughes | 1354ea9 | 2017-09-19 15:58:31 +0100 | [diff] [blame] | 752 | * Since: 1.0.0 |
| 753 | **/ |
| 754 | GPtrArray * |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 755 | fu_plugin_get_supported (FuPlugin *self) |
Richard Hughes | 1354ea9 | 2017-09-19 15:58:31 +0100 | [diff] [blame] | 756 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 757 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 1354ea9 | 2017-09-19 15:58:31 +0100 | [diff] [blame] | 758 | return priv->supported_guids; |
| 759 | } |
| 760 | |
| 761 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 762 | fu_plugin_set_smbios (FuPlugin *self, FuSmbios *smbios) |
Richard Hughes | 49e5e05 | 2017-09-03 12:15:41 +0100 | [diff] [blame] | 763 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 764 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 49e5e05 | 2017-09-03 12:15:41 +0100 | [diff] [blame] | 765 | g_set_object (&priv->smbios, smbios); |
| 766 | } |
| 767 | |
Richard Hughes | b8f8db2 | 2017-04-25 15:56:00 +0100 | [diff] [blame] | 768 | /** |
Richard Hughes | b082903 | 2017-01-10 09:27:08 +0000 | [diff] [blame] | 769 | * fu_plugin_set_coldplug_delay: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 770 | * @self: A #FuPlugin |
Richard Hughes | b082903 | 2017-01-10 09:27:08 +0000 | [diff] [blame] | 771 | * @duration: A delay in milliseconds |
| 772 | * |
| 773 | * Set the minimum time that should be waited inbetween the call to |
| 774 | * fu_plugin_coldplug_prepare() and fu_plugin_coldplug(). This is usually going |
| 775 | * to be the minimum hardware initialisation time from a datasheet. |
| 776 | * |
| 777 | * It is better to use this function rather than using a sleep() in the plugin |
| 778 | * itself as then only one delay is done in the daemon rather than waiting for |
| 779 | * each coldplug prepare in a serial way. |
| 780 | * |
| 781 | * Additionally, very long delays should be avoided as the daemon will be |
| 782 | * blocked from processing requests whilst the coldplug delay is being |
| 783 | * performed. |
| 784 | * |
| 785 | * Since: 0.8.0 |
| 786 | **/ |
| 787 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 788 | fu_plugin_set_coldplug_delay (FuPlugin *self, guint duration) |
Richard Hughes | b082903 | 2017-01-10 09:27:08 +0000 | [diff] [blame] | 789 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 790 | g_return_if_fail (FU_IS_PLUGIN (self)); |
Richard Hughes | b082903 | 2017-01-10 09:27:08 +0000 | [diff] [blame] | 791 | g_return_if_fail (duration > 0); |
| 792 | |
| 793 | /* check sanity */ |
| 794 | if (duration > FU_PLUGIN_COLDPLUG_DELAY_MAXIMUM) { |
| 795 | g_warning ("duration of %ums is crazy, truncating to %ums", |
| 796 | duration, |
| 797 | FU_PLUGIN_COLDPLUG_DELAY_MAXIMUM); |
| 798 | duration = FU_PLUGIN_COLDPLUG_DELAY_MAXIMUM; |
| 799 | } |
| 800 | |
| 801 | /* emit */ |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 802 | g_signal_emit (self, signals[SIGNAL_SET_COLDPLUG_DELAY], 0, duration); |
Richard Hughes | b082903 | 2017-01-10 09:27:08 +0000 | [diff] [blame] | 803 | } |
| 804 | |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 805 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 806 | fu_plugin_runner_startup (FuPlugin *self, GError **error) |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 807 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 808 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 809 | FuPluginStartupFunc func = NULL; |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 810 | |
| 811 | /* not enabled */ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 812 | if (!priv->enabled) |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 813 | return TRUE; |
| 814 | |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 815 | /* no object loaded */ |
| 816 | if (priv->module == NULL) |
| 817 | return TRUE; |
| 818 | |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 819 | /* optional */ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 820 | g_module_symbol (priv->module, "fu_plugin_startup", (gpointer *) &func); |
| 821 | if (func == NULL) |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 822 | return TRUE; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 823 | g_debug ("performing startup() on %s", priv->name); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 824 | if (!func (self, error)) { |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 825 | g_prefix_error (error, "failed to startup %s: ", priv->name); |
| 826 | return FALSE; |
| 827 | } |
| 828 | return TRUE; |
| 829 | } |
| 830 | |
| 831 | static gboolean |
| 832 | fu_plugin_runner_offline_invalidate (GError **error) |
| 833 | { |
| 834 | g_autoptr(GError) error_local = NULL; |
| 835 | g_autoptr(GFile) file1 = NULL; |
| 836 | |
| 837 | g_return_val_if_fail (error == NULL || *error == NULL, FALSE); |
| 838 | |
| 839 | file1 = g_file_new_for_path (FU_OFFLINE_TRIGGER_FILENAME); |
| 840 | if (!g_file_query_exists (file1, NULL)) |
| 841 | return TRUE; |
| 842 | if (!g_file_delete (file1, NULL, &error_local)) { |
| 843 | g_set_error (error, |
| 844 | FWUPD_ERROR, |
| 845 | FWUPD_ERROR_INTERNAL, |
| 846 | "Cannot delete %s: %s", |
| 847 | FU_OFFLINE_TRIGGER_FILENAME, |
| 848 | error_local->message); |
| 849 | return FALSE; |
| 850 | } |
| 851 | return TRUE; |
| 852 | } |
| 853 | |
| 854 | static gboolean |
| 855 | fu_plugin_runner_offline_setup (GError **error) |
| 856 | { |
| 857 | gint rc; |
| 858 | |
| 859 | g_return_val_if_fail (error == NULL || *error == NULL, FALSE); |
| 860 | |
| 861 | /* create symlink for the systemd-system-update-generator */ |
| 862 | rc = symlink ("/var/lib/fwupd", FU_OFFLINE_TRIGGER_FILENAME); |
| 863 | if (rc < 0) { |
| 864 | g_set_error (error, |
| 865 | FWUPD_ERROR, |
| 866 | FWUPD_ERROR_INTERNAL, |
| 867 | "Failed to create symlink %s to %s: %s", |
| 868 | FU_OFFLINE_TRIGGER_FILENAME, |
| 869 | "/var/lib", strerror (errno)); |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 870 | return FALSE; |
| 871 | } |
| 872 | return TRUE; |
| 873 | } |
| 874 | |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 875 | static gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 876 | fu_plugin_runner_device_generic (FuPlugin *self, FuDevice *device, |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 877 | const gchar *symbol_name, GError **error) |
| 878 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 879 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 880 | FuPluginDeviceFunc func = NULL; |
| 881 | |
| 882 | /* not enabled */ |
| 883 | if (!priv->enabled) |
| 884 | return TRUE; |
| 885 | |
Richard Hughes | d3d96cc | 2017-11-14 11:34:33 +0000 | [diff] [blame] | 886 | /* no object loaded */ |
| 887 | if (priv->module == NULL) |
| 888 | return TRUE; |
| 889 | |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 890 | /* optional */ |
| 891 | g_module_symbol (priv->module, symbol_name, (gpointer *) &func); |
| 892 | if (func == NULL) |
| 893 | return TRUE; |
| 894 | g_debug ("performing %s() on %s", symbol_name + 10, priv->name); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 895 | if (!func (self, device, error)) { |
Richard Hughes | 83e54e4 | 2018-01-31 23:27:30 +0000 | [diff] [blame] | 896 | g_prefix_error (error, "failed to run %s() on %s: ", |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 897 | symbol_name + 10, |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 898 | priv->name); |
| 899 | return FALSE; |
| 900 | } |
| 901 | return TRUE; |
| 902 | } |
| 903 | |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 904 | static gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 905 | fu_plugin_runner_flagged_device_generic (FuPlugin *self, FwupdInstallFlags flags, |
Mario Limonciello | e3b1a3f | 2018-08-21 13:01:45 -0500 | [diff] [blame] | 906 | FuDevice *device, |
| 907 | const gchar *symbol_name, GError **error) |
| 908 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 909 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Mario Limonciello | e3b1a3f | 2018-08-21 13:01:45 -0500 | [diff] [blame] | 910 | FuPluginFlaggedDeviceFunc func = NULL; |
| 911 | |
| 912 | /* not enabled */ |
| 913 | if (!priv->enabled) |
| 914 | return TRUE; |
| 915 | |
| 916 | /* no object loaded */ |
| 917 | if (priv->module == NULL) |
| 918 | return TRUE; |
| 919 | |
| 920 | /* optional */ |
| 921 | g_module_symbol (priv->module, symbol_name, (gpointer *) &func); |
| 922 | if (func == NULL) |
| 923 | return TRUE; |
| 924 | g_debug ("performing %s() on %s", symbol_name + 10, priv->name); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 925 | if (!func (self, flags, device, error)) { |
Mario Limonciello | e3b1a3f | 2018-08-21 13:01:45 -0500 | [diff] [blame] | 926 | g_prefix_error (error, "failed to run %s() on %s: ", |
| 927 | symbol_name + 10, |
| 928 | priv->name); |
| 929 | return FALSE; |
| 930 | } |
| 931 | return TRUE; |
| 932 | |
| 933 | } |
| 934 | |
| 935 | static gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 936 | fu_plugin_runner_device_array_generic (FuPlugin *self, GPtrArray *devices, |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 937 | const gchar *symbol_name, GError **error) |
| 938 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 939 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 940 | FuPluginDeviceArrayFunc func = NULL; |
| 941 | |
| 942 | /* not enabled */ |
| 943 | if (!priv->enabled) |
| 944 | return TRUE; |
| 945 | |
| 946 | /* no object loaded */ |
| 947 | if (priv->module == NULL) |
| 948 | return TRUE; |
| 949 | |
| 950 | /* optional */ |
| 951 | g_module_symbol (priv->module, symbol_name, (gpointer *) &func); |
| 952 | if (func == NULL) |
| 953 | return TRUE; |
| 954 | g_debug ("performing %s() on %s", symbol_name + 10, priv->name); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 955 | if (!func (self, devices, error)) { |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 956 | g_prefix_error (error, "failed to run %s() on %s: ", |
| 957 | symbol_name + 10, |
| 958 | priv->name); |
| 959 | return FALSE; |
| 960 | } |
| 961 | return TRUE; |
| 962 | } |
| 963 | |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 964 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 965 | fu_plugin_runner_coldplug (FuPlugin *self, GError **error) |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 966 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 967 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 968 | FuPluginStartupFunc func = NULL; |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 969 | |
| 970 | /* not enabled */ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 971 | if (!priv->enabled) |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 972 | return TRUE; |
| 973 | |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 974 | /* no object loaded */ |
| 975 | if (priv->module == NULL) |
| 976 | return TRUE; |
| 977 | |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 978 | /* optional */ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 979 | g_module_symbol (priv->module, "fu_plugin_coldplug", (gpointer *) &func); |
| 980 | if (func == NULL) |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 981 | return TRUE; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 982 | g_debug ("performing coldplug() on %s", priv->name); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 983 | if (!func (self, error)) { |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 984 | g_prefix_error (error, "failed to coldplug %s: ", priv->name); |
| 985 | return FALSE; |
| 986 | } |
| 987 | return TRUE; |
| 988 | } |
| 989 | |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 990 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 991 | fu_plugin_runner_recoldplug (FuPlugin *self, GError **error) |
Richard Hughes | 2de8f13 | 2018-01-17 09:12:02 +0000 | [diff] [blame] | 992 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 993 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 2de8f13 | 2018-01-17 09:12:02 +0000 | [diff] [blame] | 994 | FuPluginStartupFunc func = NULL; |
| 995 | |
| 996 | /* not enabled */ |
| 997 | if (!priv->enabled) |
| 998 | return TRUE; |
| 999 | |
| 1000 | /* no object loaded */ |
| 1001 | if (priv->module == NULL) |
| 1002 | return TRUE; |
| 1003 | |
| 1004 | /* optional */ |
| 1005 | g_module_symbol (priv->module, "fu_plugin_recoldplug", (gpointer *) &func); |
| 1006 | if (func == NULL) |
| 1007 | return TRUE; |
| 1008 | g_debug ("performing recoldplug() on %s", priv->name); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1009 | if (!func (self, error)) { |
Richard Hughes | 2de8f13 | 2018-01-17 09:12:02 +0000 | [diff] [blame] | 1010 | g_prefix_error (error, "failed to recoldplug %s: ", priv->name); |
| 1011 | return FALSE; |
| 1012 | } |
| 1013 | return TRUE; |
| 1014 | } |
| 1015 | |
| 1016 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1017 | fu_plugin_runner_coldplug_prepare (FuPlugin *self, GError **error) |
Richard Hughes | 46487c9 | 2017-01-07 21:26:34 +0000 | [diff] [blame] | 1018 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1019 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 46487c9 | 2017-01-07 21:26:34 +0000 | [diff] [blame] | 1020 | FuPluginStartupFunc func = NULL; |
| 1021 | |
| 1022 | /* not enabled */ |
| 1023 | if (!priv->enabled) |
| 1024 | return TRUE; |
| 1025 | |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 1026 | /* no object loaded */ |
| 1027 | if (priv->module == NULL) |
| 1028 | return TRUE; |
| 1029 | |
Richard Hughes | 46487c9 | 2017-01-07 21:26:34 +0000 | [diff] [blame] | 1030 | /* optional */ |
| 1031 | g_module_symbol (priv->module, "fu_plugin_coldplug_prepare", (gpointer *) &func); |
| 1032 | if (func == NULL) |
| 1033 | return TRUE; |
| 1034 | g_debug ("performing coldplug_prepare() on %s", priv->name); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1035 | if (!func (self, error)) { |
Richard Hughes | 46487c9 | 2017-01-07 21:26:34 +0000 | [diff] [blame] | 1036 | g_prefix_error (error, "failed to prepare for coldplug %s: ", priv->name); |
| 1037 | return FALSE; |
| 1038 | } |
| 1039 | return TRUE; |
| 1040 | } |
| 1041 | |
| 1042 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1043 | fu_plugin_runner_coldplug_cleanup (FuPlugin *self, GError **error) |
Richard Hughes | 46487c9 | 2017-01-07 21:26:34 +0000 | [diff] [blame] | 1044 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1045 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 46487c9 | 2017-01-07 21:26:34 +0000 | [diff] [blame] | 1046 | FuPluginStartupFunc func = NULL; |
| 1047 | |
| 1048 | /* not enabled */ |
| 1049 | if (!priv->enabled) |
| 1050 | return TRUE; |
| 1051 | |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 1052 | /* no object loaded */ |
| 1053 | if (priv->module == NULL) |
| 1054 | return TRUE; |
| 1055 | |
Richard Hughes | 46487c9 | 2017-01-07 21:26:34 +0000 | [diff] [blame] | 1056 | /* optional */ |
| 1057 | g_module_symbol (priv->module, "fu_plugin_coldplug_cleanup", (gpointer *) &func); |
| 1058 | if (func == NULL) |
| 1059 | return TRUE; |
| 1060 | g_debug ("performing coldplug_cleanup() on %s", priv->name); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1061 | if (!func (self, error)) { |
Richard Hughes | 46487c9 | 2017-01-07 21:26:34 +0000 | [diff] [blame] | 1062 | g_prefix_error (error, "failed to cleanup coldplug %s: ", priv->name); |
| 1063 | return FALSE; |
| 1064 | } |
| 1065 | return TRUE; |
| 1066 | } |
| 1067 | |
| 1068 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1069 | fu_plugin_runner_composite_prepare (FuPlugin *self, GPtrArray *devices, GError **error) |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 1070 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1071 | return fu_plugin_runner_device_array_generic (self, devices, |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 1072 | "fu_plugin_composite_prepare", |
| 1073 | error); |
| 1074 | } |
| 1075 | |
| 1076 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1077 | fu_plugin_runner_composite_cleanup (FuPlugin *self, GPtrArray *devices, GError **error) |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 1078 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1079 | return fu_plugin_runner_device_array_generic (self, devices, |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 1080 | "fu_plugin_composite_cleanup", |
| 1081 | error); |
| 1082 | } |
| 1083 | |
| 1084 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1085 | fu_plugin_runner_update_prepare (FuPlugin *self, FwupdInstallFlags flags, FuDevice *device, |
Mario Limonciello | e3b1a3f | 2018-08-21 13:01:45 -0500 | [diff] [blame] | 1086 | GError **error) |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 1087 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1088 | return fu_plugin_runner_flagged_device_generic (self, flags, device, |
Mario Limonciello | e3b1a3f | 2018-08-21 13:01:45 -0500 | [diff] [blame] | 1089 | "fu_plugin_update_prepare", |
| 1090 | error); |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 1091 | } |
| 1092 | |
| 1093 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1094 | fu_plugin_runner_update_cleanup (FuPlugin *self, FwupdInstallFlags flags, FuDevice *device, |
Mario Limonciello | e3b1a3f | 2018-08-21 13:01:45 -0500 | [diff] [blame] | 1095 | GError **error) |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 1096 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1097 | return fu_plugin_runner_flagged_device_generic (self, flags, device, |
Mario Limonciello | e3b1a3f | 2018-08-21 13:01:45 -0500 | [diff] [blame] | 1098 | "fu_plugin_update_cleanup", |
| 1099 | error); |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1100 | } |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 1101 | |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1102 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1103 | fu_plugin_runner_update_attach (FuPlugin *self, FuDevice *device, GError **error) |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1104 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1105 | return fu_plugin_runner_device_generic (self, device, |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1106 | "fu_plugin_update_attach", error); |
| 1107 | } |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 1108 | |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1109 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1110 | fu_plugin_runner_update_detach (FuPlugin *self, FuDevice *device, GError **error) |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1111 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1112 | return fu_plugin_runner_device_generic (self, device, |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1113 | "fu_plugin_update_detach", error); |
| 1114 | } |
| 1115 | |
| 1116 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1117 | fu_plugin_runner_update_reload (FuPlugin *self, FuDevice *device, GError **error) |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1118 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1119 | return fu_plugin_runner_device_generic (self, device, |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1120 | "fu_plugin_update_reload", error); |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 1121 | } |
| 1122 | |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 1123 | /** |
| 1124 | * fu_plugin_add_udev_subsystem: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 1125 | * @self: a #FuPlugin |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 1126 | * @subsystem: a subsystem name, e.g. `pciport` |
| 1127 | * |
| 1128 | * Registers the udev subsystem to be watched by the daemon. |
| 1129 | * |
| 1130 | * Plugins can use this method only in fu_plugin_init() |
| 1131 | **/ |
| 1132 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1133 | fu_plugin_add_udev_subsystem (FuPlugin *self, const gchar *subsystem) |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 1134 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1135 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 1136 | for (guint i = 0; i < priv->udev_subsystems->len; i++) { |
| 1137 | const gchar *subsystem_tmp = g_ptr_array_index (priv->udev_subsystems, i); |
| 1138 | if (g_strcmp0 (subsystem_tmp, subsystem) == 0) |
| 1139 | return; |
| 1140 | } |
| 1141 | g_debug ("added udev subsystem watch of %s", subsystem); |
| 1142 | g_ptr_array_add (priv->udev_subsystems, g_strdup (subsystem)); |
| 1143 | } |
| 1144 | |
Richard Hughes | 104f651 | 2017-11-24 11:44:57 +0000 | [diff] [blame] | 1145 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1146 | fu_plugin_runner_usb_device_added (FuPlugin *self, FuUsbDevice *device, GError **error) |
Richard Hughes | 104f651 | 2017-11-24 11:44:57 +0000 | [diff] [blame] | 1147 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1148 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 104f651 | 2017-11-24 11:44:57 +0000 | [diff] [blame] | 1149 | FuPluginUsbDeviceAddedFunc func = NULL; |
| 1150 | |
| 1151 | /* not enabled */ |
| 1152 | if (!priv->enabled) |
| 1153 | return TRUE; |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 1154 | |
| 1155 | /* no object loaded */ |
Richard Hughes | 104f651 | 2017-11-24 11:44:57 +0000 | [diff] [blame] | 1156 | if (priv->module == NULL) |
| 1157 | return TRUE; |
| 1158 | |
| 1159 | /* optional */ |
| 1160 | g_module_symbol (priv->module, "fu_plugin_usb_device_added", (gpointer *) &func); |
| 1161 | if (func != NULL) { |
| 1162 | g_debug ("performing usb_device_added() on %s", priv->name); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1163 | return func (self, device, error); |
Richard Hughes | 104f651 | 2017-11-24 11:44:57 +0000 | [diff] [blame] | 1164 | } |
| 1165 | return TRUE; |
| 1166 | } |
| 1167 | |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 1168 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1169 | fu_plugin_runner_udev_device_added (FuPlugin *self, FuUdevDevice *device, GError **error) |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 1170 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1171 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 1172 | FuPluginUdevDeviceAddedFunc func = NULL; |
| 1173 | |
| 1174 | /* not enabled */ |
| 1175 | if (!priv->enabled) |
| 1176 | return TRUE; |
| 1177 | |
| 1178 | /* no object loaded */ |
| 1179 | if (priv->module == NULL) |
| 1180 | return TRUE; |
| 1181 | |
| 1182 | /* optional */ |
| 1183 | g_module_symbol (priv->module, "fu_plugin_udev_device_added", (gpointer *) &func); |
| 1184 | if (func != NULL) { |
| 1185 | g_debug ("performing udev_device_added() on %s", priv->name); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1186 | return func (self, device, error); |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 1187 | } |
| 1188 | return TRUE; |
| 1189 | } |
| 1190 | |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 1191 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1192 | fu_plugin_runner_device_removed (FuPlugin *self, FuDevice *device) |
Mario Limonciello | e260ead | 2018-09-01 09:19:24 -0500 | [diff] [blame] | 1193 | { |
| 1194 | g_autoptr(GError) error_local= NULL; |
| 1195 | |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1196 | if (!fu_plugin_runner_device_generic (self, device, |
Mario Limonciello | e260ead | 2018-09-01 09:19:24 -0500 | [diff] [blame] | 1197 | "fu_plugin_device_removed", |
| 1198 | &error_local)) |
| 1199 | g_warning ("%s", error_local->message); |
| 1200 | } |
| 1201 | |
| 1202 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1203 | fu_plugin_runner_device_register (FuPlugin *self, FuDevice *device) |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 1204 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1205 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 1206 | FuPluginDeviceRegisterFunc func = NULL; |
| 1207 | |
| 1208 | /* not enabled */ |
| 1209 | if (!priv->enabled) |
| 1210 | return; |
Richard Hughes | 3483410 | 2017-11-21 21:55:00 +0000 | [diff] [blame] | 1211 | if (priv->module == NULL) |
| 1212 | return; |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 1213 | |
Mario Limonciello | 4910b24 | 2018-06-22 15:04:21 -0500 | [diff] [blame] | 1214 | /* don't notify plugins on their own devices */ |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1215 | if (g_strcmp0 (fu_device_get_plugin (device), fu_plugin_get_name (self)) == 0) |
Mario Limonciello | 4910b24 | 2018-06-22 15:04:21 -0500 | [diff] [blame] | 1216 | return; |
| 1217 | |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 1218 | /* optional */ |
| 1219 | g_module_symbol (priv->module, "fu_plugin_device_registered", (gpointer *) &func); |
| 1220 | if (func != NULL) { |
Richard Hughes | 1bf7ff9 | 2018-08-24 20:21:35 +0100 | [diff] [blame] | 1221 | g_debug ("performing fu_plugin_device_registered() on %s", priv->name); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1222 | func (self, device); |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 1223 | } |
| 1224 | } |
| 1225 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1226 | static gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1227 | fu_plugin_runner_schedule_update (FuPlugin *self, |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1228 | FuDevice *device, |
| 1229 | GBytes *blob_cab, |
| 1230 | GError **error) |
| 1231 | { |
Richard Hughes | 38fb56c | 2018-02-01 22:07:52 +0000 | [diff] [blame] | 1232 | FwupdRelease *release; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1233 | gchar tmpname[] = {"XXXXXX.cap"}; |
| 1234 | g_autofree gchar *dirname = NULL; |
| 1235 | g_autofree gchar *filename = NULL; |
Richard Hughes | 68982c6 | 2017-09-13 15:40:14 +0100 | [diff] [blame] | 1236 | g_autoptr(FuDevice) res_tmp = NULL; |
Richard Hughes | 780ef3f | 2018-01-12 16:20:31 +0000 | [diff] [blame] | 1237 | g_autoptr(FuHistory) history = NULL; |
Richard Hughes | 38fb56c | 2018-02-01 22:07:52 +0000 | [diff] [blame] | 1238 | g_autoptr(FwupdRelease) release_tmp = fwupd_release_new (); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1239 | g_autoptr(GFile) file = NULL; |
| 1240 | |
| 1241 | /* id already exists */ |
Richard Hughes | 780ef3f | 2018-01-12 16:20:31 +0000 | [diff] [blame] | 1242 | history = fu_history_new (); |
Richard Hughes | 0b9d996 | 2018-01-12 16:31:28 +0000 | [diff] [blame] | 1243 | res_tmp = fu_history_get_device_by_id (history, fu_device_get_id (device), NULL); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1244 | if (res_tmp != NULL) { |
| 1245 | g_set_error (error, |
| 1246 | FWUPD_ERROR, |
| 1247 | FWUPD_ERROR_ALREADY_PENDING, |
| 1248 | "%s is already scheduled to be updated", |
| 1249 | fu_device_get_id (device)); |
| 1250 | return FALSE; |
| 1251 | } |
| 1252 | |
| 1253 | /* create directory */ |
Richard Hughes | 4be17d1 | 2018-05-30 20:36:29 +0100 | [diff] [blame] | 1254 | dirname = fu_common_get_path (FU_PATH_KIND_LOCALSTATEDIR_PKG); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1255 | file = g_file_new_for_path (dirname); |
| 1256 | if (!g_file_query_exists (file, NULL)) { |
| 1257 | if (!g_file_make_directory_with_parents (file, NULL, error)) |
| 1258 | return FALSE; |
| 1259 | } |
| 1260 | |
| 1261 | /* get a random filename */ |
| 1262 | for (guint i = 0; i < 6; i++) |
| 1263 | tmpname[i] = (gchar) g_random_int_range ('A', 'Z'); |
| 1264 | filename = g_build_filename (dirname, tmpname, NULL); |
| 1265 | |
| 1266 | /* just copy to the temp file */ |
Richard Hughes | 23135eb | 2017-11-30 21:01:25 +0000 | [diff] [blame] | 1267 | fu_device_set_status (device, FWUPD_STATUS_SCHEDULING); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1268 | if (!g_file_set_contents (filename, |
| 1269 | g_bytes_get_data (blob_cab, NULL), |
| 1270 | (gssize) g_bytes_get_size (blob_cab), |
| 1271 | error)) |
| 1272 | return FALSE; |
| 1273 | |
| 1274 | /* schedule for next boot */ |
| 1275 | g_debug ("schedule %s to be installed to %s on next boot", |
| 1276 | filename, fu_device_get_id (device)); |
Richard Hughes | 38fb56c | 2018-02-01 22:07:52 +0000 | [diff] [blame] | 1277 | release = fu_device_get_release_default (device); |
| 1278 | fwupd_release_set_version (release_tmp, fwupd_release_get_version (release)); |
| 1279 | fwupd_release_set_filename (release_tmp, filename); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1280 | |
| 1281 | /* add to database */ |
Richard Hughes | 3e90a58 | 2018-01-06 22:38:09 +0000 | [diff] [blame] | 1282 | fu_device_set_update_state (device, FWUPD_UPDATE_STATE_PENDING); |
Richard Hughes | 38fb56c | 2018-02-01 22:07:52 +0000 | [diff] [blame] | 1283 | if (!fu_history_add_device (history, device, release_tmp, error)) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1284 | return FALSE; |
| 1285 | |
| 1286 | /* next boot we run offline */ |
| 1287 | return fu_plugin_runner_offline_setup (error); |
| 1288 | } |
| 1289 | |
| 1290 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1291 | fu_plugin_runner_verify (FuPlugin *self, |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1292 | FuDevice *device, |
| 1293 | FuPluginVerifyFlags flags, |
| 1294 | GError **error) |
| 1295 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1296 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 1297 | FuPluginVerifyFunc func = NULL; |
Richard Hughes | ababbb7 | 2017-06-15 20:18:36 +0100 | [diff] [blame] | 1298 | GPtrArray *checksums; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1299 | |
| 1300 | /* not enabled */ |
| 1301 | if (!priv->enabled) |
| 1302 | return TRUE; |
| 1303 | |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 1304 | /* no object loaded */ |
| 1305 | if (priv->module == NULL) |
| 1306 | return TRUE; |
| 1307 | |
Richard Hughes | ababbb7 | 2017-06-15 20:18:36 +0100 | [diff] [blame] | 1308 | /* clear any existing verification checksums */ |
| 1309 | checksums = fu_device_get_checksums (device); |
| 1310 | g_ptr_array_set_size (checksums, 0); |
| 1311 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1312 | /* optional */ |
| 1313 | g_module_symbol (priv->module, "fu_plugin_verify", (gpointer *) &func); |
| 1314 | if (func == NULL) |
| 1315 | return TRUE; |
| 1316 | g_debug ("performing verify() on %s", priv->name); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1317 | if (!func (self, device, flags, error)) { |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1318 | g_prefix_error (error, "failed to verify %s: ", priv->name); |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1319 | return FALSE; |
| 1320 | } |
| 1321 | return TRUE; |
| 1322 | } |
| 1323 | |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1324 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1325 | fu_plugin_runner_unlock (FuPlugin *self, FuDevice *device, GError **error) |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1326 | { |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1327 | guint64 flags; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1328 | |
| 1329 | /* final check */ |
| 1330 | flags = fu_device_get_flags (device); |
| 1331 | if ((flags & FWUPD_DEVICE_FLAG_LOCKED) == 0) { |
| 1332 | g_set_error (error, |
| 1333 | FWUPD_ERROR, |
| 1334 | FWUPD_ERROR_NOT_SUPPORTED, |
| 1335 | "Device %s is not locked", |
| 1336 | fu_device_get_id (device)); |
| 1337 | return FALSE; |
| 1338 | } |
| 1339 | |
Richard Hughes | 9c4b531 | 2017-11-14 11:34:53 +0000 | [diff] [blame] | 1340 | /* run vfunc */ |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1341 | if (!fu_plugin_runner_device_generic (self, device, |
Richard Hughes | 9c4b531 | 2017-11-14 11:34:53 +0000 | [diff] [blame] | 1342 | "fu_plugin_unlock", error)) |
| 1343 | return FALSE; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1344 | |
| 1345 | /* update with correct flags */ |
| 1346 | flags = fu_device_get_flags (device); |
| 1347 | fu_device_set_flags (device, flags &= ~FWUPD_DEVICE_FLAG_LOCKED); |
| 1348 | fu_device_set_modified (device, (guint64) g_get_real_time () / G_USEC_PER_SEC); |
| 1349 | return TRUE; |
| 1350 | } |
| 1351 | |
| 1352 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1353 | fu_plugin_runner_update (FuPlugin *self, |
Richard Hughes | a785a1c | 2017-08-25 16:00:58 +0100 | [diff] [blame] | 1354 | FuDevice *device, |
| 1355 | GBytes *blob_cab, |
| 1356 | GBytes *blob_fw, |
| 1357 | FwupdInstallFlags flags, |
| 1358 | GError **error) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1359 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1360 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | a785a1c | 2017-08-25 16:00:58 +0100 | [diff] [blame] | 1361 | FuPluginUpdateFunc update_func; |
Richard Hughes | 780ef3f | 2018-01-12 16:20:31 +0000 | [diff] [blame] | 1362 | g_autoptr(FuHistory) history = NULL; |
Richard Hughes | 68982c6 | 2017-09-13 15:40:14 +0100 | [diff] [blame] | 1363 | g_autoptr(FuDevice) device_pending = NULL; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1364 | GError *error_update = NULL; |
Richard Hughes | f556d37 | 2017-06-15 19:49:18 +0100 | [diff] [blame] | 1365 | GPtrArray *checksums; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1366 | |
| 1367 | /* not enabled */ |
Richard Hughes | 41c1548 | 2018-02-01 22:07:21 +0000 | [diff] [blame] | 1368 | if (!priv->enabled) { |
| 1369 | g_debug ("plugin not enabled, skipping"); |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1370 | return TRUE; |
Richard Hughes | 41c1548 | 2018-02-01 22:07:21 +0000 | [diff] [blame] | 1371 | } |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1372 | |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 1373 | /* no object loaded */ |
Richard Hughes | 41c1548 | 2018-02-01 22:07:21 +0000 | [diff] [blame] | 1374 | if (priv->module == NULL) { |
| 1375 | g_debug ("module not enabled, skipping"); |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 1376 | return TRUE; |
Richard Hughes | 41c1548 | 2018-02-01 22:07:21 +0000 | [diff] [blame] | 1377 | } |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 1378 | |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1379 | /* optional */ |
Richard Hughes | a785a1c | 2017-08-25 16:00:58 +0100 | [diff] [blame] | 1380 | g_module_symbol (priv->module, "fu_plugin_update", (gpointer *) &update_func); |
| 1381 | if (update_func == NULL) { |
| 1382 | g_set_error_literal (error, |
| 1383 | FWUPD_ERROR, |
| 1384 | FWUPD_ERROR_NOT_SUPPORTED, |
| 1385 | "No update possible"); |
| 1386 | return FALSE; |
| 1387 | } |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1388 | |
Richard Hughes | a785a1c | 2017-08-25 16:00:58 +0100 | [diff] [blame] | 1389 | /* just schedule this for the next reboot */ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1390 | if (flags & FWUPD_INSTALL_FLAG_OFFLINE) { |
Richard Hughes | 026cdd8 | 2018-05-18 10:23:19 +0100 | [diff] [blame] | 1391 | if (blob_cab == NULL) { |
| 1392 | g_set_error_literal (error, |
| 1393 | FWUPD_ERROR, |
| 1394 | FWUPD_ERROR_NOT_SUPPORTED, |
| 1395 | "No cabinet archive to schedule"); |
| 1396 | return FALSE; |
| 1397 | } |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1398 | return fu_plugin_runner_schedule_update (self, |
Richard Hughes | a785a1c | 2017-08-25 16:00:58 +0100 | [diff] [blame] | 1399 | device, |
| 1400 | blob_cab, |
| 1401 | error); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1402 | } |
| 1403 | |
| 1404 | /* cancel the pending action */ |
| 1405 | if (!fu_plugin_runner_offline_invalidate (error)) |
| 1406 | return FALSE; |
| 1407 | |
| 1408 | /* online */ |
Richard Hughes | 780ef3f | 2018-01-12 16:20:31 +0000 | [diff] [blame] | 1409 | history = fu_history_new (); |
Richard Hughes | 0b9d996 | 2018-01-12 16:31:28 +0000 | [diff] [blame] | 1410 | device_pending = fu_history_get_device_by_id (history, fu_device_get_id (device), NULL); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1411 | if (!update_func (self, device, blob_fw, flags, &error_update)) { |
Richard Hughes | c0cd023 | 2018-01-31 15:02:00 +0000 | [diff] [blame] | 1412 | fu_device_set_update_error (device, error_update->message); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1413 | g_propagate_error (error, error_update); |
| 1414 | return FALSE; |
| 1415 | } |
| 1416 | |
Richard Hughes | f556d37 | 2017-06-15 19:49:18 +0100 | [diff] [blame] | 1417 | /* no longer valid */ |
| 1418 | checksums = fu_device_get_checksums (device); |
| 1419 | g_ptr_array_set_size (checksums, 0); |
| 1420 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1421 | /* cleanup */ |
Richard Hughes | 68982c6 | 2017-09-13 15:40:14 +0100 | [diff] [blame] | 1422 | if (device_pending != NULL) { |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1423 | const gchar *tmp; |
Richard Hughes | bc3a4e1 | 2018-01-06 22:41:47 +0000 | [diff] [blame] | 1424 | FwupdRelease *release; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1425 | |
Richard Hughes | 780ef3f | 2018-01-12 16:20:31 +0000 | [diff] [blame] | 1426 | /* update history database */ |
Richard Hughes | c0cd023 | 2018-01-31 15:02:00 +0000 | [diff] [blame] | 1427 | fu_device_set_update_state (device, FWUPD_UPDATE_STATE_SUCCESS); |
| 1428 | if (!fu_history_modify_device (history, device, |
| 1429 | FU_HISTORY_FLAGS_MATCH_NEW_VERSION, |
| 1430 | error)) |
Richard Hughes | 0b9d996 | 2018-01-12 16:31:28 +0000 | [diff] [blame] | 1431 | return FALSE; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1432 | |
| 1433 | /* delete cab file */ |
Richard Hughes | bc3a4e1 | 2018-01-06 22:41:47 +0000 | [diff] [blame] | 1434 | release = fu_device_get_release_default (device_pending); |
| 1435 | tmp = fwupd_release_get_filename (release); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1436 | if (tmp != NULL && g_str_has_prefix (tmp, LIBEXECDIR)) { |
| 1437 | g_autoptr(GError) error_local = NULL; |
| 1438 | g_autoptr(GFile) file = NULL; |
| 1439 | file = g_file_new_for_path (tmp); |
| 1440 | if (!g_file_delete (file, NULL, &error_local)) { |
| 1441 | g_set_error (error, |
| 1442 | FWUPD_ERROR, |
| 1443 | FWUPD_ERROR_INVALID_FILE, |
| 1444 | "Failed to delete %s: %s", |
| 1445 | tmp, error_local->message); |
| 1446 | return FALSE; |
| 1447 | } |
| 1448 | } |
| 1449 | } |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1450 | return TRUE; |
| 1451 | } |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1452 | |
| 1453 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1454 | fu_plugin_runner_clear_results (FuPlugin *self, FuDevice *device, GError **error) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1455 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1456 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 1457 | FuPluginDeviceFunc func = NULL; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1458 | |
| 1459 | /* not enabled */ |
| 1460 | if (!priv->enabled) |
| 1461 | return TRUE; |
| 1462 | |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 1463 | /* no object loaded */ |
| 1464 | if (priv->module == NULL) |
| 1465 | return TRUE; |
| 1466 | |
Richard Hughes | 65e44ca | 2018-01-30 17:26:30 +0000 | [diff] [blame] | 1467 | /* optional */ |
| 1468 | g_module_symbol (priv->module, "fu_plugin_get_results", (gpointer *) &func); |
| 1469 | if (func == NULL) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1470 | return TRUE; |
Richard Hughes | 65e44ca | 2018-01-30 17:26:30 +0000 | [diff] [blame] | 1471 | g_debug ("performing clear_result() on %s", priv->name); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1472 | if (!func (self, device, error)) { |
Richard Hughes | 65e44ca | 2018-01-30 17:26:30 +0000 | [diff] [blame] | 1473 | g_prefix_error (error, "failed to clear_result %s: ", priv->name); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1474 | return FALSE; |
| 1475 | } |
Richard Hughes | 65e44ca | 2018-01-30 17:26:30 +0000 | [diff] [blame] | 1476 | return TRUE; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1477 | } |
| 1478 | |
| 1479 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1480 | fu_plugin_runner_get_results (FuPlugin *self, FuDevice *device, GError **error) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1481 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1482 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 1483 | FuPluginDeviceFunc func = NULL; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1484 | |
| 1485 | /* not enabled */ |
| 1486 | if (!priv->enabled) |
| 1487 | return TRUE; |
| 1488 | |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 1489 | /* no object loaded */ |
| 1490 | if (priv->module == NULL) |
| 1491 | return TRUE; |
| 1492 | |
Richard Hughes | 65e44ca | 2018-01-30 17:26:30 +0000 | [diff] [blame] | 1493 | /* optional */ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1494 | g_module_symbol (priv->module, "fu_plugin_get_results", (gpointer *) &func); |
Richard Hughes | 65e44ca | 2018-01-30 17:26:30 +0000 | [diff] [blame] | 1495 | if (func == NULL) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1496 | return TRUE; |
Richard Hughes | 65e44ca | 2018-01-30 17:26:30 +0000 | [diff] [blame] | 1497 | g_debug ("performing get_results() on %s", priv->name); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1498 | if (!func (self, device, error)) { |
Richard Hughes | 65e44ca | 2018-01-30 17:26:30 +0000 | [diff] [blame] | 1499 | g_prefix_error (error, "failed to get_results %s: ", priv->name); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1500 | return FALSE; |
| 1501 | } |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1502 | return TRUE; |
| 1503 | } |
| 1504 | |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 1505 | /** |
| 1506 | * fu_plugin_get_order: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 1507 | * @self: a #FuPlugin |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 1508 | * |
| 1509 | * Gets the plugin order, where higher numbers are run after lower |
| 1510 | * numbers. |
| 1511 | * |
| 1512 | * Returns: the integer value |
| 1513 | **/ |
| 1514 | guint |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1515 | fu_plugin_get_order (FuPlugin *self) |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 1516 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1517 | FuPluginPrivate *priv = fu_plugin_get_instance_private (self); |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 1518 | return priv->order; |
| 1519 | } |
| 1520 | |
| 1521 | /** |
| 1522 | * fu_plugin_set_order: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 1523 | * @self: a #FuPlugin |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 1524 | * @order: a integer value |
| 1525 | * |
| 1526 | * Sets the plugin order, where higher numbers are run after lower |
| 1527 | * numbers. |
| 1528 | **/ |
| 1529 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1530 | fu_plugin_set_order (FuPlugin *self, guint order) |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 1531 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1532 | FuPluginPrivate *priv = fu_plugin_get_instance_private (self); |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 1533 | priv->order = order; |
| 1534 | } |
| 1535 | |
| 1536 | /** |
Richard Hughes | 81c427c | 2018-08-06 15:20:17 +0100 | [diff] [blame] | 1537 | * fu_plugin_get_priority: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 1538 | * @self: a #FuPlugin |
Richard Hughes | 81c427c | 2018-08-06 15:20:17 +0100 | [diff] [blame] | 1539 | * |
| 1540 | * Gets the plugin priority, where higher numbers are better. |
| 1541 | * |
| 1542 | * Returns: the integer value |
| 1543 | **/ |
| 1544 | guint |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1545 | fu_plugin_get_priority (FuPlugin *self) |
Richard Hughes | 81c427c | 2018-08-06 15:20:17 +0100 | [diff] [blame] | 1546 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1547 | FuPluginPrivate *priv = fu_plugin_get_instance_private (self); |
Richard Hughes | 81c427c | 2018-08-06 15:20:17 +0100 | [diff] [blame] | 1548 | return priv->priority; |
| 1549 | } |
| 1550 | |
| 1551 | /** |
| 1552 | * fu_plugin_set_priority: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 1553 | * @self: a #FuPlugin |
Richard Hughes | 81c427c | 2018-08-06 15:20:17 +0100 | [diff] [blame] | 1554 | * @priority: a integer value |
| 1555 | * |
| 1556 | * Sets the plugin priority, where higher numbers are better. |
| 1557 | **/ |
| 1558 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1559 | fu_plugin_set_priority (FuPlugin *self, guint priority) |
Richard Hughes | 81c427c | 2018-08-06 15:20:17 +0100 | [diff] [blame] | 1560 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1561 | FuPluginPrivate *priv = fu_plugin_get_instance_private (self); |
Richard Hughes | 81c427c | 2018-08-06 15:20:17 +0100 | [diff] [blame] | 1562 | priv->priority = priority; |
| 1563 | } |
| 1564 | |
| 1565 | /** |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 1566 | * fu_plugin_add_rule: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 1567 | * @self: a #FuPlugin |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 1568 | * @rule: a #FuPluginRule, e.g. %FU_PLUGIN_RULE_CONFLICTS |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 1569 | * @name: a plugin name, e.g. `upower` |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 1570 | * |
| 1571 | * If the plugin name is found, the rule will be used to sort the plugin list, |
| 1572 | * for example the plugin specified by @name will be ordered after this plugin |
| 1573 | * when %FU_PLUGIN_RULE_RUN_AFTER is used. |
| 1574 | * |
| 1575 | * NOTE: The depsolver is iterative and may not solve overly-complicated rules; |
| 1576 | * If depsolving fails then fwupd will not start. |
| 1577 | **/ |
| 1578 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1579 | fu_plugin_add_rule (FuPlugin *self, FuPluginRule rule, const gchar *name) |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 1580 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1581 | FuPluginPrivate *priv = fu_plugin_get_instance_private (self); |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 1582 | g_ptr_array_add (priv->rules[rule], g_strdup (name)); |
| 1583 | } |
| 1584 | |
| 1585 | /** |
| 1586 | * fu_plugin_get_rules: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 1587 | * @self: a #FuPlugin |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 1588 | * @rule: a #FuPluginRule, e.g. %FU_PLUGIN_RULE_CONFLICTS |
| 1589 | * |
| 1590 | * Gets the plugin IDs that should be run after this plugin. |
| 1591 | * |
| 1592 | * Returns: (element-type utf8) (transfer none): the list of plugin names, e.g. ['appstream'] |
| 1593 | **/ |
| 1594 | GPtrArray * |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1595 | fu_plugin_get_rules (FuPlugin *self, FuPluginRule rule) |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 1596 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1597 | FuPluginPrivate *priv = fu_plugin_get_instance_private (self); |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 1598 | return priv->rules[rule]; |
| 1599 | } |
| 1600 | |
Richard Hughes | 80b79bb | 2018-01-11 21:11:06 +0000 | [diff] [blame] | 1601 | /** |
Richard Hughes | 5f3a56b | 2018-06-28 12:13:59 +0100 | [diff] [blame] | 1602 | * fu_plugin_has_rule: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 1603 | * @self: a #FuPlugin |
Richard Hughes | 5f3a56b | 2018-06-28 12:13:59 +0100 | [diff] [blame] | 1604 | * @rule: a #FuPluginRule, e.g. %FU_PLUGIN_RULE_CONFLICTS |
| 1605 | * @name: a plugin name, e.g. `upower` |
| 1606 | * |
Richard Hughes | 87fb9ff | 2018-06-28 12:55:59 +0100 | [diff] [blame] | 1607 | * Gets the plugin IDs that should be run after this plugin. |
Richard Hughes | 5f3a56b | 2018-06-28 12:13:59 +0100 | [diff] [blame] | 1608 | * |
| 1609 | * Returns: %TRUE if the name exists for the specific rule |
| 1610 | **/ |
| 1611 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1612 | fu_plugin_has_rule (FuPlugin *self, FuPluginRule rule, const gchar *name) |
Richard Hughes | 5f3a56b | 2018-06-28 12:13:59 +0100 | [diff] [blame] | 1613 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1614 | FuPluginPrivate *priv = fu_plugin_get_instance_private (self); |
Richard Hughes | 5f3a56b | 2018-06-28 12:13:59 +0100 | [diff] [blame] | 1615 | for (guint i = 0; i < priv->rules[rule]->len; i++) { |
| 1616 | const gchar *tmp = g_ptr_array_index (priv->rules[rule], i); |
| 1617 | if (g_strcmp0 (tmp, name) == 0) |
| 1618 | return TRUE; |
| 1619 | } |
| 1620 | return FALSE; |
| 1621 | } |
| 1622 | |
| 1623 | /** |
Richard Hughes | 80b79bb | 2018-01-11 21:11:06 +0000 | [diff] [blame] | 1624 | * fu_plugin_add_report_metadata: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 1625 | * @self: a #FuPlugin |
Richard Hughes | 80b79bb | 2018-01-11 21:11:06 +0000 | [diff] [blame] | 1626 | * @key: a string, e.g. `FwupdateVersion` |
| 1627 | * @value: a string, e.g. `10` |
| 1628 | * |
| 1629 | * Sets any additional metadata to be included in the firmware report to aid |
| 1630 | * debugging problems. |
| 1631 | * |
| 1632 | * Any data included here will be sent to the metadata server after user |
| 1633 | * confirmation. |
| 1634 | **/ |
| 1635 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1636 | fu_plugin_add_report_metadata (FuPlugin *self, const gchar *key, const gchar *value) |
Richard Hughes | 80b79bb | 2018-01-11 21:11:06 +0000 | [diff] [blame] | 1637 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1638 | FuPluginPrivate *priv = fu_plugin_get_instance_private (self); |
Richard Hughes | 80b79bb | 2018-01-11 21:11:06 +0000 | [diff] [blame] | 1639 | g_hash_table_insert (priv->report_metadata, g_strdup (key), g_strdup (value)); |
| 1640 | } |
| 1641 | |
| 1642 | /** |
| 1643 | * fu_plugin_get_report_metadata: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 1644 | * @self: a #FuPlugin |
Richard Hughes | 80b79bb | 2018-01-11 21:11:06 +0000 | [diff] [blame] | 1645 | * |
| 1646 | * Returns the list of additional metadata to be added when filing a report. |
| 1647 | * |
| 1648 | * Returns: (transfer none): the map of report metadata |
| 1649 | **/ |
| 1650 | GHashTable * |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1651 | fu_plugin_get_report_metadata (FuPlugin *self) |
Richard Hughes | 80b79bb | 2018-01-11 21:11:06 +0000 | [diff] [blame] | 1652 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1653 | FuPluginPrivate *priv = fu_plugin_get_instance_private (self); |
Richard Hughes | 80b79bb | 2018-01-11 21:11:06 +0000 | [diff] [blame] | 1654 | return priv->report_metadata; |
| 1655 | } |
| 1656 | |
Mario Limonciello | 963dc42 | 2018-02-27 14:26:58 -0600 | [diff] [blame] | 1657 | /** |
| 1658 | * fu_plugin_get_config_value: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 1659 | * @self: a #FuPlugin |
Mario Limonciello | 963dc42 | 2018-02-27 14:26:58 -0600 | [diff] [blame] | 1660 | * @key: A settings key |
| 1661 | * |
| 1662 | * Return the value of a key if it's been configured |
| 1663 | * |
| 1664 | * Since: 1.0.6 |
| 1665 | **/ |
| 1666 | gchar * |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1667 | fu_plugin_get_config_value (FuPlugin *self, const gchar *key) |
Mario Limonciello | 963dc42 | 2018-02-27 14:26:58 -0600 | [diff] [blame] | 1668 | { |
Richard Hughes | 4be17d1 | 2018-05-30 20:36:29 +0100 | [diff] [blame] | 1669 | g_autofree gchar *conf_dir = NULL; |
Mario Limonciello | 963dc42 | 2018-02-27 14:26:58 -0600 | [diff] [blame] | 1670 | g_autofree gchar *conf_file = NULL; |
| 1671 | g_autofree gchar *conf_path = NULL; |
| 1672 | g_autoptr(GKeyFile) keyfile = NULL; |
| 1673 | const gchar *plugin_name; |
| 1674 | |
Richard Hughes | 4be17d1 | 2018-05-30 20:36:29 +0100 | [diff] [blame] | 1675 | conf_dir = fu_common_get_path (FU_PATH_KIND_SYSCONFDIR_PKG); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1676 | plugin_name = fu_plugin_get_name (self); |
Mario Limonciello | 963dc42 | 2018-02-27 14:26:58 -0600 | [diff] [blame] | 1677 | conf_file = g_strdup_printf ("%s.conf", plugin_name); |
Richard Hughes | 4be17d1 | 2018-05-30 20:36:29 +0100 | [diff] [blame] | 1678 | conf_path = g_build_filename (conf_dir, conf_file, NULL); |
Mario Limonciello | 963dc42 | 2018-02-27 14:26:58 -0600 | [diff] [blame] | 1679 | if (!g_file_test (conf_path, G_FILE_TEST_IS_REGULAR)) |
| 1680 | return NULL; |
| 1681 | keyfile = g_key_file_new (); |
| 1682 | if (!g_key_file_load_from_file (keyfile, conf_path, |
| 1683 | G_KEY_FILE_NONE, NULL)) |
| 1684 | return NULL; |
| 1685 | return g_key_file_get_string (keyfile, plugin_name, key, NULL); |
| 1686 | } |
| 1687 | |
Richard Hughes | 8c71a3f | 2018-05-22 19:19:52 +0100 | [diff] [blame] | 1688 | /** |
| 1689 | * fu_plugin_name_compare: |
| 1690 | * @plugin1: first #FuPlugin to compare. |
| 1691 | * @plugin2: second #FuPlugin to compare. |
| 1692 | * |
| 1693 | * Compares two plugins by their names. |
| 1694 | * |
| 1695 | * Returns: 1, 0 or -1 if @plugin1 is greater, equal, or less than @plugin2. |
| 1696 | **/ |
| 1697 | gint |
| 1698 | fu_plugin_name_compare (FuPlugin *plugin1, FuPlugin *plugin2) |
| 1699 | { |
| 1700 | FuPluginPrivate *priv1 = fu_plugin_get_instance_private (plugin1); |
| 1701 | FuPluginPrivate *priv2 = fu_plugin_get_instance_private (plugin2); |
| 1702 | return g_strcmp0 (priv1->name, priv2->name); |
| 1703 | } |
| 1704 | |
| 1705 | /** |
| 1706 | * fu_plugin_order_compare: |
| 1707 | * @plugin1: first #FuPlugin to compare. |
| 1708 | * @plugin2: second #FuPlugin to compare. |
| 1709 | * |
| 1710 | * Compares two plugins by their depsolved order. |
| 1711 | * |
| 1712 | * Returns: 1, 0 or -1 if @plugin1 is greater, equal, or less than @plugin2. |
| 1713 | **/ |
| 1714 | gint |
| 1715 | fu_plugin_order_compare (FuPlugin *plugin1, FuPlugin *plugin2) |
| 1716 | { |
| 1717 | FuPluginPrivate *priv1 = fu_plugin_get_instance_private (plugin1); |
| 1718 | FuPluginPrivate *priv2 = fu_plugin_get_instance_private (plugin2); |
| 1719 | if (priv1->order < priv2->order) |
| 1720 | return -1; |
| 1721 | if (priv1->order > priv2->order) |
| 1722 | return 1; |
| 1723 | return 0; |
| 1724 | } |
| 1725 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1726 | static void |
| 1727 | fu_plugin_class_init (FuPluginClass *klass) |
| 1728 | { |
| 1729 | GObjectClass *object_class = G_OBJECT_CLASS (klass); |
| 1730 | object_class->finalize = fu_plugin_finalize; |
| 1731 | signals[SIGNAL_DEVICE_ADDED] = |
| 1732 | g_signal_new ("device-added", |
| 1733 | G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, |
| 1734 | G_STRUCT_OFFSET (FuPluginClass, device_added), |
| 1735 | NULL, NULL, g_cclosure_marshal_VOID__OBJECT, |
| 1736 | G_TYPE_NONE, 1, FU_TYPE_DEVICE); |
| 1737 | signals[SIGNAL_DEVICE_REMOVED] = |
| 1738 | g_signal_new ("device-removed", |
| 1739 | G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, |
| 1740 | G_STRUCT_OFFSET (FuPluginClass, device_removed), |
| 1741 | NULL, NULL, g_cclosure_marshal_VOID__OBJECT, |
| 1742 | G_TYPE_NONE, 1, FU_TYPE_DEVICE); |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 1743 | signals[SIGNAL_DEVICE_REGISTER] = |
| 1744 | g_signal_new ("device-register", |
| 1745 | G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, |
| 1746 | G_STRUCT_OFFSET (FuPluginClass, device_register), |
| 1747 | NULL, NULL, g_cclosure_marshal_VOID__OBJECT, |
| 1748 | G_TYPE_NONE, 1, FU_TYPE_DEVICE); |
Richard Hughes | 362d6d7 | 2017-01-07 21:42:14 +0000 | [diff] [blame] | 1749 | signals[SIGNAL_RECOLDPLUG] = |
| 1750 | g_signal_new ("recoldplug", |
| 1751 | G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, |
| 1752 | G_STRUCT_OFFSET (FuPluginClass, recoldplug), |
| 1753 | NULL, NULL, g_cclosure_marshal_VOID__VOID, |
| 1754 | G_TYPE_NONE, 0); |
Richard Hughes | b082903 | 2017-01-10 09:27:08 +0000 | [diff] [blame] | 1755 | signals[SIGNAL_SET_COLDPLUG_DELAY] = |
| 1756 | g_signal_new ("set-coldplug-delay", |
| 1757 | G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, |
| 1758 | G_STRUCT_OFFSET (FuPluginClass, set_coldplug_delay), |
| 1759 | NULL, NULL, g_cclosure_marshal_VOID__UINT, |
| 1760 | G_TYPE_NONE, 1, G_TYPE_UINT); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1761 | } |
| 1762 | |
| 1763 | static void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1764 | fu_plugin_init (FuPlugin *self) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1765 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1766 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1767 | priv->enabled = TRUE; |
| 1768 | priv->devices = g_hash_table_new_full (g_str_hash, g_str_equal, |
| 1769 | g_free, (GDestroyNotify) g_object_unref); |
Richard Hughes | 37d0943 | 2018-09-09 10:39:45 +0100 | [diff] [blame] | 1770 | priv->devices_mutex = fu_mutex_new (G_OBJECT_TYPE_NAME(self), "devices"); |
Richard Hughes | 80b79bb | 2018-01-11 21:11:06 +0000 | [diff] [blame] | 1771 | priv->report_metadata = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 1772 | for (guint i = 0; i < FU_PLUGIN_RULE_LAST; i++) |
| 1773 | priv->rules[i] = g_ptr_array_new_with_free_func (g_free); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1774 | } |
| 1775 | |
| 1776 | static void |
| 1777 | fu_plugin_finalize (GObject *object) |
| 1778 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1779 | FuPlugin *self = FU_PLUGIN (object); |
| 1780 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1781 | FuPluginInitFunc func = NULL; |
| 1782 | |
| 1783 | /* optional */ |
| 1784 | if (priv->module != NULL) { |
| 1785 | g_module_symbol (priv->module, "fu_plugin_destroy", (gpointer *) &func); |
| 1786 | if (func != NULL) { |
| 1787 | g_debug ("performing destroy() on %s", priv->name); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1788 | func (self); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1789 | } |
| 1790 | } |
| 1791 | |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 1792 | for (guint i = 0; i < FU_PLUGIN_RULE_LAST; i++) |
| 1793 | g_ptr_array_unref (priv->rules[i]); |
| 1794 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1795 | if (priv->usb_ctx != NULL) |
| 1796 | g_object_unref (priv->usb_ctx); |
Richard Hughes | b8f8db2 | 2017-04-25 15:56:00 +0100 | [diff] [blame] | 1797 | if (priv->hwids != NULL) |
Richard Hughes | d7704d4 | 2017-08-08 20:29:09 +0100 | [diff] [blame] | 1798 | g_object_unref (priv->hwids); |
Richard Hughes | 9c028f0 | 2017-10-28 21:14:28 +0100 | [diff] [blame] | 1799 | if (priv->quirks != NULL) |
| 1800 | g_object_unref (priv->quirks); |
Richard Hughes | 1354ea9 | 2017-09-19 15:58:31 +0100 | [diff] [blame] | 1801 | if (priv->supported_guids != NULL) |
| 1802 | g_ptr_array_unref (priv->supported_guids); |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 1803 | if (priv->udev_subsystems != NULL) |
| 1804 | g_ptr_array_unref (priv->udev_subsystems); |
Richard Hughes | 49e5e05 | 2017-09-03 12:15:41 +0100 | [diff] [blame] | 1805 | if (priv->smbios != NULL) |
| 1806 | g_object_unref (priv->smbios); |
Richard Hughes | 275d3b4 | 2018-04-20 16:40:37 +0100 | [diff] [blame] | 1807 | if (priv->runtime_versions != NULL) |
| 1808 | g_hash_table_unref (priv->runtime_versions); |
Richard Hughes | 34e0dab | 2018-04-20 16:43:00 +0100 | [diff] [blame] | 1809 | if (priv->compile_versions != NULL) |
| 1810 | g_hash_table_unref (priv->compile_versions); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1811 | g_hash_table_unref (priv->devices); |
Richard Hughes | 80b79bb | 2018-01-11 21:11:06 +0000 | [diff] [blame] | 1812 | g_hash_table_unref (priv->report_metadata); |
Richard Hughes | 37d0943 | 2018-09-09 10:39:45 +0100 | [diff] [blame] | 1813 | g_object_unref (priv->devices_mutex); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1814 | g_free (priv->name); |
| 1815 | g_free (priv->data); |
Mario Limonciello | 3f9a1c1 | 2018-06-06 14:06:40 -0500 | [diff] [blame] | 1816 | /* Must happen as the last step to avoid prematurely |
| 1817 | * freeing memory held by the plugin */ |
| 1818 | #ifndef RUNNING_ON_VALGRIND |
| 1819 | if (priv->module != NULL) |
| 1820 | g_module_close (priv->module); |
| 1821 | #endif |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1822 | |
| 1823 | G_OBJECT_CLASS (fu_plugin_parent_class)->finalize (object); |
| 1824 | } |
| 1825 | |
| 1826 | FuPlugin * |
| 1827 | fu_plugin_new (void) |
| 1828 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1829 | return FU_PLUGIN (g_object_new (FU_TYPE_PLUGIN, NULL)); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1830 | } |