Richard Hughes | 02c90d8 | 2018-08-09 12:13:03 +0100 | [diff] [blame] | 1 | /* |
Richard Hughes | 5c9b1fc | 2021-01-07 14:20:49 +0000 | [diff] [blame] | 2 | * Copyright (C) 2016 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> |
Mario Limonciello | 6d0aa3d | 2017-02-28 08:22:27 -0600 | [diff] [blame] | 16 | #ifdef HAVE_VALGRIND |
Richard Hughes | 576c012 | 2017-02-24 09:47:00 +0000 | [diff] [blame] | 17 | #include <valgrind.h> |
Mario Limonciello | 6d0aa3d | 2017-02-28 08:22:27 -0600 | [diff] [blame] | 18 | #endif /* HAVE_VALGRIND */ |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 19 | |
Richard Hughes | 9dde04f | 2017-09-13 12:07:15 +0100 | [diff] [blame] | 20 | #include "fu-device-private.h" |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 21 | #include "fu-plugin-private.h" |
Richard Hughes | 37d0943 | 2018-09-09 10:39:45 +0100 | [diff] [blame] | 22 | #include "fu-mutex.h" |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 23 | |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 24 | /** |
| 25 | * SECTION:fu-plugin |
| 26 | * @short_description: a daemon plugin |
| 27 | * |
| 28 | * An object that represents a plugin run by the daemon. |
| 29 | * |
| 30 | * See also: #FuDevice |
| 31 | */ |
| 32 | |
Richard Hughes | b082903 | 2017-01-10 09:27:08 +0000 | [diff] [blame] | 33 | #define FU_PLUGIN_COLDPLUG_DELAY_MAXIMUM 3000u /* ms */ |
| 34 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 35 | static void fu_plugin_finalize (GObject *object); |
| 36 | |
| 37 | typedef struct { |
| 38 | GModule *module; |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 39 | guint order; |
Richard Hughes | 81c427c | 2018-08-06 15:20:17 +0100 | [diff] [blame] | 40 | guint priority; |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 41 | GPtrArray *rules[FU_PLUGIN_RULE_LAST]; |
Richard Hughes | 68ab1e4 | 2021-01-13 14:01:17 +0000 | [diff] [blame] | 42 | GPtrArray *devices; /* (nullable) (element-type FuDevice) */ |
Richard Hughes | f425d29 | 2019-01-18 17:57:39 +0000 | [diff] [blame] | 43 | gchar *build_hash; |
Richard Hughes | d7704d4 | 2017-08-08 20:29:09 +0100 | [diff] [blame] | 44 | FuHwids *hwids; |
Richard Hughes | 9c028f0 | 2017-10-28 21:14:28 +0100 | [diff] [blame] | 45 | FuQuirks *quirks; |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 46 | GHashTable *runtime_versions; |
Richard Hughes | 34e0dab | 2018-04-20 16:43:00 +0100 | [diff] [blame] | 47 | GHashTable *compile_versions; |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 48 | GPtrArray *udev_subsystems; |
Richard Hughes | 1354ea9 | 2017-09-19 15:58:31 +0100 | [diff] [blame] | 49 | FuSmbios *smbios; |
Richard Hughes | 989acf1 | 2019-10-05 20:16:47 +0100 | [diff] [blame] | 50 | GType device_gtype; |
Richard Hughes | faf2afe | 2021-01-13 14:00:20 +0000 | [diff] [blame] | 51 | GHashTable *cache; /* (nullable): platform_id:GObject */ |
| 52 | GRWLock cache_mutex; |
Richard Hughes | 1d900f7 | 2020-06-22 15:17:39 +0100 | [diff] [blame] | 53 | GHashTable *report_metadata; /* (nullable): key:value */ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 54 | FuPluginData *data; |
| 55 | } FuPluginPrivate; |
| 56 | |
| 57 | enum { |
| 58 | SIGNAL_DEVICE_ADDED, |
| 59 | SIGNAL_DEVICE_REMOVED, |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 60 | SIGNAL_DEVICE_REGISTER, |
Richard Hughes | 75b965d | 2018-11-15 13:51:21 +0000 | [diff] [blame] | 61 | SIGNAL_RULES_CHANGED, |
Richard Hughes | 362d6d7 | 2017-01-07 21:42:14 +0000 | [diff] [blame] | 62 | SIGNAL_RECOLDPLUG, |
Richard Hughes | b082903 | 2017-01-10 09:27:08 +0000 | [diff] [blame] | 63 | SIGNAL_SET_COLDPLUG_DELAY, |
Richard Hughes | aabdc37 | 2018-11-14 10:11:08 +0000 | [diff] [blame] | 64 | SIGNAL_CHECK_SUPPORTED, |
Richard Hughes | 95c98a9 | 2019-10-22 16:03:15 +0100 | [diff] [blame] | 65 | SIGNAL_ADD_FIRMWARE_GTYPE, |
Richard Hughes | 399859e | 2020-05-11 19:44:03 +0100 | [diff] [blame] | 66 | SIGNAL_SECURITY_CHANGED, |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 67 | SIGNAL_LAST |
| 68 | }; |
| 69 | |
| 70 | static guint signals[SIGNAL_LAST] = { 0 }; |
| 71 | |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 72 | G_DEFINE_TYPE_WITH_PRIVATE (FuPlugin, fu_plugin, FWUPD_TYPE_PLUGIN) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 73 | #define GET_PRIVATE(o) (fu_plugin_get_instance_private (o)) |
| 74 | |
| 75 | typedef const gchar *(*FuPluginGetNameFunc) (void); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 76 | typedef void (*FuPluginInitFunc) (FuPlugin *self); |
| 77 | typedef gboolean (*FuPluginStartupFunc) (FuPlugin *self, |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 78 | GError **error); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 79 | typedef void (*FuPluginDeviceRegisterFunc) (FuPlugin *self, |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 80 | FuDevice *device); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 81 | typedef gboolean (*FuPluginDeviceFunc) (FuPlugin *self, |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 82 | FuDevice *device, |
| 83 | GError **error); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 84 | typedef gboolean (*FuPluginFlaggedDeviceFunc) (FuPlugin *self, |
Mario Limonciello | e3b1a3f | 2018-08-21 13:01:45 -0500 | [diff] [blame] | 85 | FwupdInstallFlags flags, |
| 86 | FuDevice *device, |
| 87 | GError **error); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 88 | typedef gboolean (*FuPluginDeviceArrayFunc) (FuPlugin *self, |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 89 | GPtrArray *devices, |
| 90 | GError **error); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 91 | typedef gboolean (*FuPluginVerifyFunc) (FuPlugin *self, |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 92 | FuDevice *device, |
| 93 | FuPluginVerifyFlags flags, |
| 94 | GError **error); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 95 | typedef gboolean (*FuPluginUpdateFunc) (FuPlugin *self, |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 96 | FuDevice *device, |
| 97 | GBytes *blob_fw, |
| 98 | FwupdInstallFlags flags, |
| 99 | GError **error); |
Richard Hughes | f58ac73 | 2020-05-12 15:23:44 +0100 | [diff] [blame] | 100 | typedef void (*FuPluginSecurityAttrsFunc) (FuPlugin *self, |
| 101 | FuSecurityAttrs *attrs); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 102 | |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 103 | /** |
Mario Limonciello | 52e75ba | 2019-11-22 13:21:19 -0600 | [diff] [blame] | 104 | * fu_plugin_is_open: |
| 105 | * @self: A #FuPlugin |
| 106 | * |
| 107 | * Determines if the plugin is opened |
| 108 | * |
| 109 | * Returns: TRUE for opened, FALSE for not |
| 110 | * |
| 111 | * Since: 1.3.5 |
| 112 | **/ |
| 113 | gboolean |
| 114 | fu_plugin_is_open (FuPlugin *self) |
| 115 | { |
| 116 | FuPluginPrivate *priv = GET_PRIVATE (self); |
| 117 | return priv->module != NULL; |
| 118 | } |
| 119 | |
| 120 | /** |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 121 | * fu_plugin_get_name: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 122 | * @self: A #FuPlugin |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 123 | * |
| 124 | * Gets the plugin name. |
| 125 | * |
| 126 | * Returns: a plugin name, or %NULL for unknown. |
| 127 | * |
| 128 | * Since: 0.8.0 |
| 129 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 130 | const gchar * |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 131 | fu_plugin_get_name (FuPlugin *self) |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 132 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 133 | g_return_val_if_fail (FU_IS_PLUGIN (self), NULL); |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 134 | return fwupd_plugin_get_name (FWUPD_PLUGIN (self)); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 135 | } |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 136 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 137 | /** |
| 138 | * fu_plugin_set_name: |
| 139 | * @self: A #FuPlugin |
| 140 | * @name: A string |
| 141 | * |
| 142 | * Sets the plugin name. |
| 143 | * |
| 144 | * Since: 0.8.0 |
| 145 | **/ |
Richard Hughes | 3483410 | 2017-11-21 21:55:00 +0000 | [diff] [blame] | 146 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 147 | fu_plugin_set_name (FuPlugin *self, const gchar *name) |
Richard Hughes | 3483410 | 2017-11-21 21:55:00 +0000 | [diff] [blame] | 148 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 149 | g_return_if_fail (FU_IS_PLUGIN (self)); |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 150 | fwupd_plugin_set_name (FWUPD_PLUGIN (self), name); |
Richard Hughes | 3483410 | 2017-11-21 21:55:00 +0000 | [diff] [blame] | 151 | } |
| 152 | |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 153 | /** |
Richard Hughes | f425d29 | 2019-01-18 17:57:39 +0000 | [diff] [blame] | 154 | * fu_plugin_set_build_hash: |
| 155 | * @self: A #FuPlugin |
| 156 | * @build_hash: A checksum |
| 157 | * |
| 158 | * Sets the plugin build hash, typically a SHA256 checksum. All plugins must |
| 159 | * set the correct checksum to avoid the daemon being marked as tainted. |
| 160 | * |
| 161 | * Since: 1.2.4 |
| 162 | **/ |
| 163 | void |
| 164 | fu_plugin_set_build_hash (FuPlugin *self, const gchar *build_hash) |
| 165 | { |
| 166 | FuPluginPrivate *priv = GET_PRIVATE (self); |
| 167 | g_return_if_fail (FU_IS_PLUGIN (self)); |
| 168 | g_return_if_fail (build_hash != NULL); |
Richard Hughes | 382524d | 2021-01-28 13:14:35 +0000 | [diff] [blame] | 169 | |
| 170 | /* not changed */ |
| 171 | if (g_strcmp0 (priv->build_hash, build_hash) == 0) |
| 172 | return; |
| 173 | |
Richard Hughes | f425d29 | 2019-01-18 17:57:39 +0000 | [diff] [blame] | 174 | g_free (priv->build_hash); |
| 175 | priv->build_hash = g_strdup (build_hash); |
| 176 | } |
| 177 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 178 | /** |
| 179 | * fu_plugin_get_build_hash: |
| 180 | * @self: A #FuPlugin |
| 181 | * |
| 182 | * Gets the build hash a plugin was generated with. |
| 183 | * |
| 184 | * Returns: (transfer none): a #gchar, or %NULL for unset. |
| 185 | * |
| 186 | * Since: 1.2.4 |
| 187 | **/ |
Richard Hughes | f425d29 | 2019-01-18 17:57:39 +0000 | [diff] [blame] | 188 | const gchar * |
| 189 | fu_plugin_get_build_hash (FuPlugin *self) |
| 190 | { |
| 191 | FuPluginPrivate *priv = GET_PRIVATE (self); |
| 192 | g_return_val_if_fail (FU_IS_PLUGIN (self), NULL); |
| 193 | return priv->build_hash; |
| 194 | } |
| 195 | |
| 196 | /** |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 197 | * fu_plugin_cache_lookup: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 198 | * @self: A #FuPlugin |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 199 | * @id: the key |
| 200 | * |
| 201 | * Finds an object in the per-plugin cache. |
| 202 | * |
| 203 | * Returns: (transfer none): a #GObject, or %NULL for unfound. |
| 204 | * |
| 205 | * Since: 0.8.0 |
| 206 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 207 | gpointer |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 208 | fu_plugin_cache_lookup (FuPlugin *self, const gchar *id) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 209 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 210 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | faf2afe | 2021-01-13 14:00:20 +0000 | [diff] [blame] | 211 | g_autoptr(GRWLockReaderLocker) locker = g_rw_lock_reader_locker_new (&priv->cache_mutex); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 212 | g_return_val_if_fail (FU_IS_PLUGIN (self), NULL); |
Richard Hughes | ccd78a9 | 2017-01-11 16:57:41 +0000 | [diff] [blame] | 213 | g_return_val_if_fail (id != NULL, NULL); |
Richard Hughes | 37d0943 | 2018-09-09 10:39:45 +0100 | [diff] [blame] | 214 | g_return_val_if_fail (locker != NULL, NULL); |
Richard Hughes | faf2afe | 2021-01-13 14:00:20 +0000 | [diff] [blame] | 215 | if (priv->cache == NULL) |
Richard Hughes | 371f6b2 | 2020-06-22 15:21:17 +0100 | [diff] [blame] | 216 | return NULL; |
Richard Hughes | faf2afe | 2021-01-13 14:00:20 +0000 | [diff] [blame] | 217 | return g_hash_table_lookup (priv->cache, id); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 218 | } |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 219 | |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 220 | /** |
| 221 | * fu_plugin_cache_add: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 222 | * @self: A #FuPlugin |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 223 | * @id: the key |
| 224 | * @dev: a #GObject, typically a #FuDevice |
| 225 | * |
| 226 | * Adds an object to the per-plugin cache. |
| 227 | * |
| 228 | * Since: 0.8.0 |
| 229 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 230 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 231 | fu_plugin_cache_add (FuPlugin *self, const gchar *id, gpointer dev) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 232 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 233 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | faf2afe | 2021-01-13 14:00:20 +0000 | [diff] [blame] | 234 | g_autoptr(GRWLockWriterLocker) locker = g_rw_lock_writer_locker_new (&priv->cache_mutex); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 235 | g_return_if_fail (FU_IS_PLUGIN (self)); |
Richard Hughes | ccd78a9 | 2017-01-11 16:57:41 +0000 | [diff] [blame] | 236 | g_return_if_fail (id != NULL); |
Richard Hughes | 37d0943 | 2018-09-09 10:39:45 +0100 | [diff] [blame] | 237 | g_return_if_fail (locker != NULL); |
Richard Hughes | faf2afe | 2021-01-13 14:00:20 +0000 | [diff] [blame] | 238 | if (priv->cache == NULL) { |
| 239 | priv->cache = g_hash_table_new_full (g_str_hash, |
| 240 | g_str_equal, |
| 241 | g_free, |
| 242 | (GDestroyNotify) g_object_unref); |
Richard Hughes | 371f6b2 | 2020-06-22 15:21:17 +0100 | [diff] [blame] | 243 | } |
Richard Hughes | faf2afe | 2021-01-13 14:00:20 +0000 | [diff] [blame] | 244 | g_hash_table_insert (priv->cache, g_strdup (id), g_object_ref (dev)); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 245 | } |
| 246 | |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 247 | /** |
| 248 | * fu_plugin_cache_remove: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 249 | * @self: A #FuPlugin |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 250 | * @id: the key |
| 251 | * |
| 252 | * Removes an object from the per-plugin cache. |
| 253 | * |
| 254 | * Since: 0.8.0 |
| 255 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 256 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 257 | fu_plugin_cache_remove (FuPlugin *self, const gchar *id) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 258 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 259 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | faf2afe | 2021-01-13 14:00:20 +0000 | [diff] [blame] | 260 | g_autoptr(GRWLockWriterLocker) locker = g_rw_lock_writer_locker_new (&priv->cache_mutex); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 261 | g_return_if_fail (FU_IS_PLUGIN (self)); |
Richard Hughes | ccd78a9 | 2017-01-11 16:57:41 +0000 | [diff] [blame] | 262 | g_return_if_fail (id != NULL); |
Richard Hughes | 37d0943 | 2018-09-09 10:39:45 +0100 | [diff] [blame] | 263 | g_return_if_fail (locker != NULL); |
Richard Hughes | faf2afe | 2021-01-13 14:00:20 +0000 | [diff] [blame] | 264 | if (priv->cache == NULL) |
Richard Hughes | 371f6b2 | 2020-06-22 15:21:17 +0100 | [diff] [blame] | 265 | return; |
Richard Hughes | faf2afe | 2021-01-13 14:00:20 +0000 | [diff] [blame] | 266 | g_hash_table_remove (priv->cache, id); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 267 | } |
| 268 | |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 269 | /** |
| 270 | * fu_plugin_get_data: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 271 | * @self: A #FuPlugin |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 272 | * |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 273 | * Gets the per-plugin allocated private data. This will return %NULL unless |
| 274 | * fu_plugin_alloc_data() has been called by the plugin. |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 275 | * |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 276 | * Returns: (transfer none): a pointer to a structure, or %NULL for unset. |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 277 | * |
| 278 | * Since: 0.8.0 |
| 279 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 280 | FuPluginData * |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 281 | fu_plugin_get_data (FuPlugin *self) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 282 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 283 | FuPluginPrivate *priv = GET_PRIVATE (self); |
| 284 | g_return_val_if_fail (FU_IS_PLUGIN (self), NULL); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 285 | return priv->data; |
| 286 | } |
| 287 | |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 288 | /** |
Richard Hughes | 00f66f6 | 2019-11-27 11:42:53 +0000 | [diff] [blame] | 289 | * fu_plugin_alloc_data: (skip): |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 290 | * @self: A #FuPlugin |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 291 | * @data_sz: the size to allocate |
| 292 | * |
| 293 | * Allocates the per-plugin allocated private data. |
| 294 | * |
| 295 | * Returns: (transfer full): a pointer to a structure, or %NULL for unset. |
| 296 | * |
| 297 | * Since: 0.8.0 |
| 298 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 299 | FuPluginData * |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 300 | fu_plugin_alloc_data (FuPlugin *self, gsize data_sz) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 301 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 302 | FuPluginPrivate *priv = GET_PRIVATE (self); |
| 303 | g_return_val_if_fail (FU_IS_PLUGIN (self), NULL); |
Richard Hughes | 44dee88 | 2017-01-11 08:31:10 +0000 | [diff] [blame] | 304 | if (priv->data != NULL) { |
| 305 | g_critical ("fu_plugin_alloc_data() already used by plugin"); |
| 306 | return priv->data; |
| 307 | } |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 308 | priv->data = g_malloc0 (data_sz); |
| 309 | return priv->data; |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 310 | } |
| 311 | |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 312 | /** |
| 313 | * fu_plugin_get_usb_context: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 314 | * @self: A #FuPlugin |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 315 | * |
Richard Hughes | 9e9b73f | 2021-02-09 13:37:41 +0000 | [diff] [blame] | 316 | * This used to get the shared USB context that all plugins can use; it now |
| 317 | * returns %NULL; |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 318 | * |
| 319 | * Returns: (transfer none): a #GUsbContext. |
| 320 | * |
| 321 | * Since: 0.8.0 |
| 322 | **/ |
Richard Hughes | bc93e4a | 2016-12-08 17:29:51 +0000 | [diff] [blame] | 323 | GUsbContext * |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 324 | fu_plugin_get_usb_context (FuPlugin *self) |
Richard Hughes | bc93e4a | 2016-12-08 17:29:51 +0000 | [diff] [blame] | 325 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 326 | g_return_val_if_fail (FU_IS_PLUGIN (self), NULL); |
Richard Hughes | 9e9b73f | 2021-02-09 13:37:41 +0000 | [diff] [blame] | 327 | return NULL; |
Richard Hughes | bc93e4a | 2016-12-08 17:29:51 +0000 | [diff] [blame] | 328 | } |
| 329 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 330 | /** |
| 331 | * fu_plugin_set_usb_context: |
| 332 | * @self: A #FuPlugin |
| 333 | * @usb_ctx: A #FGUsbContext |
| 334 | * |
Richard Hughes | 9e9b73f | 2021-02-09 13:37:41 +0000 | [diff] [blame] | 335 | * This used to set the shared USB context for a plugin. It now does nothing. |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 336 | * |
| 337 | * Since: 0.8.0 |
| 338 | **/ |
Richard Hughes | bc93e4a | 2016-12-08 17:29:51 +0000 | [diff] [blame] | 339 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 340 | fu_plugin_set_usb_context (FuPlugin *self, GUsbContext *usb_ctx) |
Richard Hughes | bc93e4a | 2016-12-08 17:29:51 +0000 | [diff] [blame] | 341 | { |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 342 | } |
| 343 | |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 344 | /** |
| 345 | * fu_plugin_get_enabled: |
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 | * |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 348 | * Returns if the plugin is enabled. Plugins may self-disable using |
| 349 | * fu_plugin_set_enabled() or can be disabled by the daemon. |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 350 | * |
| 351 | * Returns: %TRUE if the plugin is currently enabled. |
| 352 | * |
| 353 | * Since: 0.8.0 |
| 354 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 355 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 356 | fu_plugin_get_enabled (FuPlugin *self) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 357 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 358 | g_return_val_if_fail (FU_IS_PLUGIN (self), FALSE); |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 359 | return !fu_plugin_has_flag (self, FWUPD_PLUGIN_FLAG_DISABLED); |
Richard Hughes | bc93e4a | 2016-12-08 17:29:51 +0000 | [diff] [blame] | 360 | } |
| 361 | |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 362 | /** |
| 363 | * fu_plugin_set_enabled: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 364 | * @self: A #FuPlugin |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 365 | * @enabled: the enabled value |
| 366 | * |
| 367 | * Enables or disables a plugin. Plugins can self-disable at any point. |
| 368 | * |
| 369 | * Since: 0.8.0 |
| 370 | **/ |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 371 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 372 | fu_plugin_set_enabled (FuPlugin *self, gboolean enabled) |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 373 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 374 | g_return_if_fail (FU_IS_PLUGIN (self)); |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 375 | if (enabled) { |
| 376 | fwupd_plugin_remove_flag (FWUPD_PLUGIN (self), |
| 377 | FWUPD_PLUGIN_FLAG_DISABLED); |
| 378 | } else { |
| 379 | fu_plugin_add_flag (self, FWUPD_PLUGIN_FLAG_DISABLED); |
| 380 | } |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 381 | } |
| 382 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 383 | /** |
| 384 | * fu_plugin_guess_name_from_fn: |
| 385 | * @filename: filename to guess |
| 386 | * |
| 387 | * Tries to guess the name of the plugin from a filename |
| 388 | * |
| 389 | * Returns: (transfer full): the guessed name of the plugin |
| 390 | * |
| 391 | * Since: 1.0.8 |
| 392 | **/ |
Richard Hughes | 1e456bc | 2018-05-10 20:16:16 +0100 | [diff] [blame] | 393 | gchar * |
| 394 | fu_plugin_guess_name_from_fn (const gchar *filename) |
| 395 | { |
| 396 | const gchar *prefix = "libfu_plugin_"; |
| 397 | gchar *name; |
| 398 | gchar *str = g_strstr_len (filename, -1, prefix); |
| 399 | if (str == NULL) |
| 400 | return NULL; |
| 401 | name = g_strdup (str + strlen (prefix)); |
| 402 | g_strdelimit (name, ".", '\0'); |
| 403 | return name; |
| 404 | } |
| 405 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 406 | /** |
| 407 | * fu_plugin_open: |
| 408 | * @self: A #FuPlugin |
| 409 | * @filename: The shared object filename to open |
| 410 | * @error: A #GError or NULL |
| 411 | * |
| 412 | * Opens the plugin module |
| 413 | * |
| 414 | * Returns: TRUE for success, FALSE for fail |
| 415 | * |
| 416 | * Since: 0.8.0 |
| 417 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 418 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 419 | fu_plugin_open (FuPlugin *self, const gchar *filename, GError **error) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 420 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 421 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 422 | FuPluginInitFunc func = NULL; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 423 | |
Richard Hughes | 6a489a9 | 2020-12-22 10:32:06 +0000 | [diff] [blame] | 424 | g_return_val_if_fail (FU_IS_PLUGIN (self), FALSE); |
| 425 | g_return_val_if_fail (filename != NULL, FALSE); |
| 426 | g_return_val_if_fail (error == NULL || *error == NULL, FALSE); |
| 427 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 428 | priv->module = g_module_open (filename, 0); |
| 429 | if (priv->module == NULL) { |
| 430 | g_set_error (error, |
| 431 | G_IO_ERROR, |
| 432 | G_IO_ERROR_FAILED, |
Mario Limonciello | f560553 | 2019-11-04 07:49:50 -0600 | [diff] [blame] | 433 | "failed to open plugin %s: %s", |
| 434 | filename, g_module_error ()); |
Mario Limonciello | c3a8173 | 2020-10-20 09:16:18 -0500 | [diff] [blame] | 435 | fu_plugin_add_flag (self, FWUPD_PLUGIN_FLAG_FAILED_OPEN); |
| 436 | fu_plugin_add_flag (self, FWUPD_PLUGIN_FLAG_USER_WARNING); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 437 | return FALSE; |
| 438 | } |
| 439 | |
| 440 | /* set automatically */ |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 441 | if (fu_plugin_get_name (self) == NULL) { |
| 442 | g_autofree gchar *str = fu_plugin_guess_name_from_fn (filename); |
| 443 | fu_plugin_set_name (self, str); |
| 444 | } |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 445 | |
| 446 | /* optional */ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 447 | g_module_symbol (priv->module, "fu_plugin_init", (gpointer *) &func); |
| 448 | if (func != NULL) { |
Mario Limonciello | 67a8b89 | 2020-09-28 13:44:39 -0500 | [diff] [blame] | 449 | g_debug ("init(%s)", filename); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 450 | func (self); |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 451 | } |
| 452 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 453 | return TRUE; |
| 454 | } |
| 455 | |
Richard Hughes | 203ed84 | 2020-11-02 14:25:13 +0000 | [diff] [blame] | 456 | /* order of usefulness to the user */ |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 457 | static const gchar * |
| 458 | fu_plugin_build_device_update_error (FuPlugin *self) |
| 459 | { |
| 460 | if (fu_plugin_has_flag (self, FWUPD_PLUGIN_FLAG_NO_HARDWARE)) |
| 461 | return "Not updatable as required hardware was not found"; |
| 462 | if (fu_plugin_has_flag (self, FWUPD_PLUGIN_FLAG_LEGACY_BIOS)) |
| 463 | return "Not updatable in legacy BIOS mode"; |
| 464 | if (fu_plugin_has_flag (self, FWUPD_PLUGIN_FLAG_CAPSULES_UNSUPPORTED)) |
Mario Limonciello | 797da4f | 2021-01-12 12:38:51 -0600 | [diff] [blame] | 465 | return "Not updatable as UEFI capsule updates not enabled in firmware setup"; |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 466 | if (fu_plugin_has_flag (self, FWUPD_PLUGIN_FLAG_UNLOCK_REQUIRED)) |
| 467 | return "Not updatable as requires unlock"; |
| 468 | if (fu_plugin_has_flag (self, FWUPD_PLUGIN_FLAG_EFIVAR_NOT_MOUNTED)) |
| 469 | return "Not updatable as efivarfs was not found"; |
| 470 | if (fu_plugin_has_flag (self, FWUPD_PLUGIN_FLAG_ESP_NOT_FOUND)) |
| 471 | return "Not updatable as UEFI ESP partition not detected"; |
| 472 | if (fu_plugin_has_flag (self, FWUPD_PLUGIN_FLAG_DISABLED)) |
| 473 | return "Not updatable as plugin was disabled"; |
| 474 | return NULL; |
| 475 | } |
| 476 | |
Richard Hughes | 68ab1e4 | 2021-01-13 14:01:17 +0000 | [diff] [blame] | 477 | static void |
| 478 | fu_plugin_ensure_devices (FuPlugin *self) |
| 479 | { |
| 480 | FuPluginPrivate *priv = GET_PRIVATE (self); |
| 481 | if (priv->devices != NULL) |
| 482 | return; |
| 483 | priv->devices = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref); |
| 484 | } |
| 485 | |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 486 | /** |
| 487 | * fu_plugin_device_add: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 488 | * @self: A #FuPlugin |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 489 | * @device: A #FuDevice |
| 490 | * |
| 491 | * Asks the daemon to add a device to the exported list. If this device ID |
| 492 | * has already been added by a different plugin then this request will be |
| 493 | * ignored. |
| 494 | * |
| 495 | * Plugins should use fu_plugin_device_add_delay() if they are not capable of |
| 496 | * actually flashing an image to the hardware so that higher-priority plugins |
| 497 | * can add the device themselves. |
| 498 | * |
| 499 | * Since: 0.8.0 |
| 500 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 501 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 502 | fu_plugin_device_add (FuPlugin *self, FuDevice *device) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 503 | { |
Richard Hughes | 68ab1e4 | 2021-01-13 14:01:17 +0000 | [diff] [blame] | 504 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 5e44729 | 2018-04-27 14:25:54 +0100 | [diff] [blame] | 505 | GPtrArray *children; |
Richard Hughes | c125ec0 | 2018-09-05 19:35:17 +0100 | [diff] [blame] | 506 | g_autoptr(GError) error = NULL; |
Richard Hughes | 5e44729 | 2018-04-27 14:25:54 +0100 | [diff] [blame] | 507 | |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 508 | g_return_if_fail (FU_IS_PLUGIN (self)); |
Richard Hughes | ccd78a9 | 2017-01-11 16:57:41 +0000 | [diff] [blame] | 509 | g_return_if_fail (FU_IS_DEVICE (device)); |
| 510 | |
Richard Hughes | c125ec0 | 2018-09-05 19:35:17 +0100 | [diff] [blame] | 511 | /* ensure the device ID is set from the physical and logical IDs */ |
| 512 | if (!fu_device_ensure_id (device, &error)) { |
| 513 | g_warning ("ignoring add: %s", error->message); |
| 514 | return; |
| 515 | } |
| 516 | |
Richard Hughes | 68ab1e4 | 2021-01-13 14:01:17 +0000 | [diff] [blame] | 517 | /* add to array */ |
| 518 | fu_plugin_ensure_devices (self); |
| 519 | g_ptr_array_add (priv->devices, g_object_ref (device)); |
| 520 | |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 521 | /* proxy to device where required */ |
| 522 | if (fu_plugin_has_flag (self, FWUPD_PLUGIN_FLAG_CLEAR_UPDATABLE)) { |
| 523 | g_debug ("plugin %s has _CLEAR_UPDATABLE, so removing from %s", |
| 524 | fu_plugin_get_name (self), |
| 525 | fu_device_get_id (device)); |
| 526 | fu_device_remove_flag (device, FWUPD_DEVICE_FLAG_UPDATABLE); |
| 527 | } |
| 528 | if (fu_plugin_has_flag (self, FWUPD_PLUGIN_FLAG_USER_WARNING) && |
| 529 | fu_device_get_update_error (device) == NULL) { |
| 530 | const gchar *tmp = fu_plugin_build_device_update_error (self); |
| 531 | g_debug ("setting %s update error to '%s' from %s", |
| 532 | fu_device_get_id (device), tmp, fu_plugin_get_name (self)); |
| 533 | fu_device_set_update_error (device, tmp); |
| 534 | } |
| 535 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 536 | g_debug ("emit added from %s: %s", |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 537 | fu_plugin_get_name (self), |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 538 | fu_device_get_id (device)); |
| 539 | 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] | 540 | fu_device_set_plugin (device, fu_plugin_get_name (self)); |
| 541 | g_signal_emit (self, signals[SIGNAL_DEVICE_ADDED], 0, device); |
Richard Hughes | 5e44729 | 2018-04-27 14:25:54 +0100 | [diff] [blame] | 542 | |
Richard Hughes | 128c016 | 2018-08-10 11:00:29 +0100 | [diff] [blame] | 543 | /* add children if they have not already been added */ |
Richard Hughes | 5e44729 | 2018-04-27 14:25:54 +0100 | [diff] [blame] | 544 | children = fu_device_get_children (device); |
| 545 | for (guint i = 0; i < children->len; i++) { |
| 546 | FuDevice *child = g_ptr_array_index (children, i); |
Richard Hughes | 128c016 | 2018-08-10 11:00:29 +0100 | [diff] [blame] | 547 | if (fu_device_get_created (child) == 0) |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 548 | fu_plugin_device_add (self, child); |
Richard Hughes | 5e44729 | 2018-04-27 14:25:54 +0100 | [diff] [blame] | 549 | } |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 550 | } |
| 551 | |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 552 | /** |
Richard Hughes | 68ab1e4 | 2021-01-13 14:01:17 +0000 | [diff] [blame] | 553 | * fu_plugin_get_devices: |
| 554 | * @self: A #FuPlugin |
| 555 | * |
| 556 | * Returns all devices added by the plugin using fu_plugin_device_add() and |
| 557 | * not yet removed with fu_plugin_device_remove(). |
| 558 | * |
| 559 | * Returns: (transfer none) (element-type FuDevice): devices |
| 560 | * |
| 561 | * Since: 1.5.6 |
| 562 | **/ |
| 563 | GPtrArray * |
| 564 | fu_plugin_get_devices (FuPlugin *self) |
| 565 | { |
| 566 | FuPluginPrivate *priv = GET_PRIVATE (self); |
| 567 | g_return_val_if_fail (FU_IS_PLUGIN (self), NULL); |
| 568 | fu_plugin_ensure_devices (self); |
| 569 | return priv->devices; |
| 570 | } |
| 571 | |
| 572 | /** |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 573 | * fu_plugin_device_register: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 574 | * @self: A #FuPlugin |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 575 | * @device: A #FuDevice |
| 576 | * |
| 577 | * Registers the device with other plugins so they can set metadata. |
| 578 | * |
| 579 | * Plugins do not have to call this manually as this is done automatically |
| 580 | * when using fu_plugin_device_add(). They may wish to use this manually |
Richard Hughes | 21eaeef | 2020-01-14 12:10:01 +0000 | [diff] [blame] | 581 | * if for instance the coldplug should be ignored based on the metadata |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 582 | * set from other plugins. |
| 583 | * |
| 584 | * Since: 0.9.7 |
| 585 | **/ |
| 586 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 587 | fu_plugin_device_register (FuPlugin *self, FuDevice *device) |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 588 | { |
Richard Hughes | c125ec0 | 2018-09-05 19:35:17 +0100 | [diff] [blame] | 589 | g_autoptr(GError) error = NULL; |
| 590 | |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 591 | g_return_if_fail (FU_IS_PLUGIN (self)); |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 592 | g_return_if_fail (FU_IS_DEVICE (device)); |
| 593 | |
Richard Hughes | c125ec0 | 2018-09-05 19:35:17 +0100 | [diff] [blame] | 594 | /* ensure the device ID is set from the physical and logical IDs */ |
| 595 | if (!fu_device_ensure_id (device, &error)) { |
| 596 | g_warning ("ignoring registration: %s", error->message); |
| 597 | return; |
| 598 | } |
| 599 | |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 600 | g_debug ("emit device-register from %s: %s", |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 601 | fu_plugin_get_name (self), |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 602 | fu_device_get_id (device)); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 603 | g_signal_emit (self, signals[SIGNAL_DEVICE_REGISTER], 0, device); |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 604 | } |
| 605 | |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 606 | /** |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 607 | * fu_plugin_device_remove: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 608 | * @self: A #FuPlugin |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 609 | * @device: A #FuDevice |
| 610 | * |
| 611 | * Asks the daemon to remove a device from the exported list. |
| 612 | * |
| 613 | * Since: 0.8.0 |
| 614 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 615 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 616 | fu_plugin_device_remove (FuPlugin *self, FuDevice *device) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 617 | { |
Richard Hughes | 68ab1e4 | 2021-01-13 14:01:17 +0000 | [diff] [blame] | 618 | FuPluginPrivate *priv = GET_PRIVATE (self); |
| 619 | |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 620 | g_return_if_fail (FU_IS_PLUGIN (self)); |
Richard Hughes | ccd78a9 | 2017-01-11 16:57:41 +0000 | [diff] [blame] | 621 | g_return_if_fail (FU_IS_DEVICE (device)); |
| 622 | |
Richard Hughes | 68ab1e4 | 2021-01-13 14:01:17 +0000 | [diff] [blame] | 623 | /* remove from array */ |
| 624 | if (priv->devices != NULL) |
| 625 | g_ptr_array_remove (priv->devices, device); |
| 626 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 627 | g_debug ("emit removed from %s: %s", |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 628 | fu_plugin_get_name (self), |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 629 | fu_device_get_id (device)); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 630 | g_signal_emit (self, signals[SIGNAL_DEVICE_REMOVED], 0, device); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 631 | } |
| 632 | |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 633 | /** |
Richard Hughes | 2de8f13 | 2018-01-17 09:12:02 +0000 | [diff] [blame] | 634 | * fu_plugin_request_recoldplug: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 635 | * @self: A #FuPlugin |
Richard Hughes | 362d6d7 | 2017-01-07 21:42:14 +0000 | [diff] [blame] | 636 | * |
| 637 | * Ask all the plugins to coldplug all devices, which will include the prepare() |
| 638 | * and cleanup() phases. Duplicate devices added will be ignored. |
| 639 | * |
| 640 | * Since: 0.8.0 |
| 641 | **/ |
| 642 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 643 | fu_plugin_request_recoldplug (FuPlugin *self) |
Richard Hughes | 362d6d7 | 2017-01-07 21:42:14 +0000 | [diff] [blame] | 644 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 645 | g_return_if_fail (FU_IS_PLUGIN (self)); |
| 646 | g_signal_emit (self, signals[SIGNAL_RECOLDPLUG], 0); |
Richard Hughes | 362d6d7 | 2017-01-07 21:42:14 +0000 | [diff] [blame] | 647 | } |
| 648 | |
Richard Hughes | b082903 | 2017-01-10 09:27:08 +0000 | [diff] [blame] | 649 | /** |
Richard Hughes | 399859e | 2020-05-11 19:44:03 +0100 | [diff] [blame] | 650 | * fu_plugin_security_changed: |
| 651 | * @self: A #FuPlugin |
| 652 | * |
| 653 | * Informs the daemon that the HSI state may have changed. |
| 654 | * |
| 655 | * Since: 1.5.0 |
| 656 | **/ |
| 657 | void |
| 658 | fu_plugin_security_changed (FuPlugin *self) |
| 659 | { |
| 660 | g_return_if_fail (FU_IS_PLUGIN (self)); |
| 661 | g_signal_emit (self, signals[SIGNAL_SECURITY_CHANGED], 0); |
| 662 | } |
| 663 | |
| 664 | /** |
Richard Hughes | b8f8db2 | 2017-04-25 15:56:00 +0100 | [diff] [blame] | 665 | * fu_plugin_check_hwid: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 666 | * @self: A #FuPlugin |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 667 | * @hwid: A Hardware ID GUID, e.g. `6de5d951-d755-576b-bd09-c5cf66b27234` |
Richard Hughes | b8f8db2 | 2017-04-25 15:56:00 +0100 | [diff] [blame] | 668 | * |
Richard Hughes | d7704d4 | 2017-08-08 20:29:09 +0100 | [diff] [blame] | 669 | * 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] | 670 | * specific system can be shown using the `fwupdmgr hwids` command. |
| 671 | * |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 672 | * Returns: %TRUE if the HwId is found on the system. |
| 673 | * |
Richard Hughes | b8f8db2 | 2017-04-25 15:56:00 +0100 | [diff] [blame] | 674 | * Since: 0.9.1 |
| 675 | **/ |
| 676 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 677 | fu_plugin_check_hwid (FuPlugin *self, const gchar *hwid) |
Richard Hughes | b8f8db2 | 2017-04-25 15:56:00 +0100 | [diff] [blame] | 678 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 679 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | b8f8db2 | 2017-04-25 15:56:00 +0100 | [diff] [blame] | 680 | if (priv->hwids == NULL) |
| 681 | return FALSE; |
Richard Hughes | d7704d4 | 2017-08-08 20:29:09 +0100 | [diff] [blame] | 682 | return fu_hwids_has_guid (priv->hwids, hwid); |
| 683 | } |
| 684 | |
| 685 | /** |
Patrick Rudolph | a60b547 | 2019-10-16 10:43:03 +0200 | [diff] [blame] | 686 | * fu_plugin_get_hwid_replace_value: |
| 687 | * @self: A #FuPlugin |
| 688 | * @keys: A key, e.g. `HardwareID-3` or %FU_HWIDS_KEY_PRODUCT_SKU |
| 689 | * @error: A #GError or %NULL |
| 690 | * |
| 691 | * Gets the replacement value for a specific key. All hardware IDs on a |
| 692 | * specific system can be shown using the `fwupdmgr hwids` command. |
| 693 | * |
| 694 | * Returns: (transfer full): a string, or %NULL for error. |
| 695 | * |
| 696 | * Since: 1.3.3 |
| 697 | **/ |
| 698 | gchar * |
| 699 | fu_plugin_get_hwid_replace_value (FuPlugin *self, const gchar *keys, GError **error) |
| 700 | { |
| 701 | FuPluginPrivate *priv = GET_PRIVATE (self); |
| 702 | if (priv->hwids == NULL) |
| 703 | return NULL; |
| 704 | |
| 705 | return fu_hwids_get_replace_values (priv->hwids, keys, error); |
| 706 | } |
| 707 | |
| 708 | /** |
Richard Hughes | 69a5f35 | 2018-08-08 11:58:15 +0100 | [diff] [blame] | 709 | * fu_plugin_get_hwids: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 710 | * @self: A #FuPlugin |
Richard Hughes | 69a5f35 | 2018-08-08 11:58:15 +0100 | [diff] [blame] | 711 | * |
| 712 | * Returns all the HWIDs defined in the system. All hardware IDs on a |
| 713 | * specific system can be shown using the `fwupdmgr hwids` command. |
| 714 | * |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 715 | * Returns: (transfer none) (element-type utf8): An array of GUIDs |
Richard Hughes | 69a5f35 | 2018-08-08 11:58:15 +0100 | [diff] [blame] | 716 | * |
| 717 | * Since: 1.1.1 |
| 718 | **/ |
| 719 | GPtrArray * |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 720 | fu_plugin_get_hwids (FuPlugin *self) |
Richard Hughes | 69a5f35 | 2018-08-08 11:58:15 +0100 | [diff] [blame] | 721 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 722 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 69a5f35 | 2018-08-08 11:58:15 +0100 | [diff] [blame] | 723 | if (priv->hwids == NULL) |
| 724 | return NULL; |
| 725 | return fu_hwids_get_guids (priv->hwids); |
| 726 | } |
| 727 | |
| 728 | /** |
Richard Hughes | 1984180 | 2019-09-10 16:48:00 +0100 | [diff] [blame] | 729 | * fu_plugin_has_custom_flag: |
| 730 | * @self: A #FuPlugin |
| 731 | * @flag: A custom text flag, specific to the plugin, e.g. `uefi-force-enable` |
| 732 | * |
| 733 | * Returns if a per-plugin HwId custom flag exists, typically added from a DMI quirk. |
| 734 | * |
| 735 | * Returns: %TRUE if the quirk entry exists |
| 736 | * |
| 737 | * Since: 1.3.1 |
| 738 | **/ |
| 739 | gboolean |
| 740 | fu_plugin_has_custom_flag (FuPlugin *self, const gchar *flag) |
| 741 | { |
| 742 | FuPluginPrivate *priv = GET_PRIVATE (self); |
| 743 | GPtrArray *hwids = fu_plugin_get_hwids (self); |
| 744 | |
| 745 | g_return_val_if_fail (FU_IS_PLUGIN (self), FALSE); |
| 746 | g_return_val_if_fail (flag != NULL, FALSE); |
| 747 | |
| 748 | /* never set up, e.g. in tests */ |
| 749 | if (hwids == NULL) |
| 750 | return FALSE; |
| 751 | |
| 752 | /* search each hwid */ |
| 753 | for (guint i = 0; i < hwids->len; i++) { |
| 754 | const gchar *hwid = g_ptr_array_index (hwids, i); |
| 755 | const gchar *value; |
| 756 | g_autofree gchar *key = g_strdup_printf ("HwId=%s", hwid); |
| 757 | |
| 758 | /* does prefixed quirk exist */ |
| 759 | value = fu_quirks_lookup_by_id (priv->quirks, key, FU_QUIRKS_FLAGS); |
| 760 | if (value != NULL) { |
| 761 | g_auto(GStrv) quirks = g_strsplit (value, ",", -1); |
| 762 | if (g_strv_contains ((const gchar * const *) quirks, flag)) |
| 763 | return TRUE; |
| 764 | } |
| 765 | } |
| 766 | return FALSE; |
| 767 | } |
| 768 | |
| 769 | /** |
Richard Hughes | 1354ea9 | 2017-09-19 15:58:31 +0100 | [diff] [blame] | 770 | * fu_plugin_check_supported: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 771 | * @self: A #FuPlugin |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 772 | * @guid: A Hardware ID GUID, e.g. `6de5d951-d755-576b-bd09-c5cf66b27234` |
Richard Hughes | 1354ea9 | 2017-09-19 15:58:31 +0100 | [diff] [blame] | 773 | * |
| 774 | * Checks to see if a specific device GUID is supported, i.e. available in the |
| 775 | * AppStream metadata. |
| 776 | * |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 777 | * Returns: %TRUE if the device is supported. |
| 778 | * |
Richard Hughes | 1354ea9 | 2017-09-19 15:58:31 +0100 | [diff] [blame] | 779 | * Since: 1.0.0 |
| 780 | **/ |
Richard Hughes | d8a8d5e | 2019-10-08 13:05:02 +0100 | [diff] [blame] | 781 | static gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 782 | fu_plugin_check_supported (FuPlugin *self, const gchar *guid) |
Richard Hughes | 1354ea9 | 2017-09-19 15:58:31 +0100 | [diff] [blame] | 783 | { |
Richard Hughes | aabdc37 | 2018-11-14 10:11:08 +0000 | [diff] [blame] | 784 | gboolean retval = FALSE; |
| 785 | g_signal_emit (self, signals[SIGNAL_CHECK_SUPPORTED], 0, guid, &retval); |
| 786 | return retval; |
Richard Hughes | 1354ea9 | 2017-09-19 15:58:31 +0100 | [diff] [blame] | 787 | } |
| 788 | |
| 789 | /** |
Richard Hughes | d7704d4 | 2017-08-08 20:29:09 +0100 | [diff] [blame] | 790 | * fu_plugin_get_dmi_value: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 791 | * @self: A #FuPlugin |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 792 | * @dmi_id: A DMI ID, e.g. `BiosVersion` |
Richard Hughes | d7704d4 | 2017-08-08 20:29:09 +0100 | [diff] [blame] | 793 | * |
| 794 | * Gets a hardware DMI value. |
| 795 | * |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 796 | * Returns: The string, or %NULL |
| 797 | * |
Richard Hughes | d7704d4 | 2017-08-08 20:29:09 +0100 | [diff] [blame] | 798 | * Since: 0.9.7 |
| 799 | **/ |
| 800 | const gchar * |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 801 | fu_plugin_get_dmi_value (FuPlugin *self, const gchar *dmi_id) |
Richard Hughes | d7704d4 | 2017-08-08 20:29:09 +0100 | [diff] [blame] | 802 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 803 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | d7704d4 | 2017-08-08 20:29:09 +0100 | [diff] [blame] | 804 | if (priv->hwids == NULL) |
Richard Hughes | 7ef96b8 | 2017-08-23 18:28:24 +0100 | [diff] [blame] | 805 | return NULL; |
Richard Hughes | d7704d4 | 2017-08-08 20:29:09 +0100 | [diff] [blame] | 806 | return fu_hwids_get_value (priv->hwids, dmi_id); |
Richard Hughes | b8f8db2 | 2017-04-25 15:56:00 +0100 | [diff] [blame] | 807 | } |
| 808 | |
Richard Hughes | 49e5e05 | 2017-09-03 12:15:41 +0100 | [diff] [blame] | 809 | /** |
| 810 | * fu_plugin_get_smbios_string: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 811 | * @self: A #FuPlugin |
Richard Hughes | 49e5e05 | 2017-09-03 12:15:41 +0100 | [diff] [blame] | 812 | * @structure_type: A SMBIOS structure type, e.g. %FU_SMBIOS_STRUCTURE_TYPE_BIOS |
| 813 | * @offset: A SMBIOS offset |
| 814 | * |
| 815 | * Gets a hardware SMBIOS string. |
| 816 | * |
| 817 | * The @type and @offset can be referenced from the DMTF SMBIOS specification: |
| 818 | * https://www.dmtf.org/sites/default/files/standards/documents/DSP0134_3.1.1.pdf |
| 819 | * |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 820 | * Returns: A string, or %NULL |
| 821 | * |
Richard Hughes | 49e5e05 | 2017-09-03 12:15:41 +0100 | [diff] [blame] | 822 | * Since: 0.9.8 |
| 823 | **/ |
| 824 | const gchar * |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 825 | fu_plugin_get_smbios_string (FuPlugin *self, guint8 structure_type, guint8 offset) |
Richard Hughes | 49e5e05 | 2017-09-03 12:15:41 +0100 | [diff] [blame] | 826 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 827 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 49e5e05 | 2017-09-03 12:15:41 +0100 | [diff] [blame] | 828 | if (priv->smbios == NULL) |
| 829 | return NULL; |
| 830 | return fu_smbios_get_string (priv->smbios, structure_type, offset, NULL); |
| 831 | } |
| 832 | |
| 833 | /** |
| 834 | * fu_plugin_get_smbios_data: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 835 | * @self: A #FuPlugin |
Richard Hughes | 49e5e05 | 2017-09-03 12:15:41 +0100 | [diff] [blame] | 836 | * @structure_type: A SMBIOS structure type, e.g. %FU_SMBIOS_STRUCTURE_TYPE_BIOS |
| 837 | * |
| 838 | * Gets a hardware SMBIOS data. |
| 839 | * |
Richard Hughes | dfaca2d | 2019-08-01 08:08:03 +0100 | [diff] [blame] | 840 | * Returns: (transfer full): A #GBytes, or %NULL |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 841 | * |
Richard Hughes | 49e5e05 | 2017-09-03 12:15:41 +0100 | [diff] [blame] | 842 | * Since: 0.9.8 |
| 843 | **/ |
| 844 | GBytes * |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 845 | fu_plugin_get_smbios_data (FuPlugin *self, guint8 structure_type) |
Richard Hughes | 49e5e05 | 2017-09-03 12:15:41 +0100 | [diff] [blame] | 846 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 847 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 49e5e05 | 2017-09-03 12:15:41 +0100 | [diff] [blame] | 848 | if (priv->smbios == NULL) |
| 849 | return NULL; |
| 850 | return fu_smbios_get_data (priv->smbios, structure_type, NULL); |
| 851 | } |
| 852 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 853 | /** |
| 854 | * fu_plugin_set_hwids: |
| 855 | * @self: A #FuPlugin |
| 856 | * @hwids: A #FuHwids |
| 857 | * |
| 858 | * Sets the hwids for a plugin |
| 859 | * |
| 860 | * Since: 0.9.7 |
| 861 | **/ |
Richard Hughes | b8f8db2 | 2017-04-25 15:56:00 +0100 | [diff] [blame] | 862 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 863 | fu_plugin_set_hwids (FuPlugin *self, FuHwids *hwids) |
Richard Hughes | b8f8db2 | 2017-04-25 15:56:00 +0100 | [diff] [blame] | 864 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 865 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | d7704d4 | 2017-08-08 20:29:09 +0100 | [diff] [blame] | 866 | g_set_object (&priv->hwids, hwids); |
Richard Hughes | b8f8db2 | 2017-04-25 15:56:00 +0100 | [diff] [blame] | 867 | } |
| 868 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 869 | /** |
| 870 | * fu_plugin_set_udev_subsystems: |
| 871 | * @self: A #FuPlugin |
Richard Hughes | a0d81c7 | 2019-11-27 11:41:54 +0000 | [diff] [blame] | 872 | * @udev_subsystems: (element-type utf8): A #GPtrArray |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 873 | * |
| 874 | * Sets the udev subsystems used by a plugin |
| 875 | * |
| 876 | * Since: 1.1.2 |
| 877 | **/ |
Richard Hughes | 49e5e05 | 2017-09-03 12:15:41 +0100 | [diff] [blame] | 878 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 879 | fu_plugin_set_udev_subsystems (FuPlugin *self, GPtrArray *udev_subsystems) |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 880 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 881 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 882 | if (priv->udev_subsystems != NULL) |
| 883 | g_ptr_array_unref (priv->udev_subsystems); |
| 884 | priv->udev_subsystems = g_ptr_array_ref (udev_subsystems); |
| 885 | } |
| 886 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 887 | /** |
| 888 | * fu_plugin_set_quirks: |
| 889 | * @self: A #FuPlugin |
| 890 | * @quirks: A #FuQuirks |
| 891 | * |
| 892 | * Sets the quirks for a plugin |
| 893 | * |
| 894 | * Since: 1.0.1 |
| 895 | **/ |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 896 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 897 | fu_plugin_set_quirks (FuPlugin *self, FuQuirks *quirks) |
Richard Hughes | 9c028f0 | 2017-10-28 21:14:28 +0100 | [diff] [blame] | 898 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 899 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 9c028f0 | 2017-10-28 21:14:28 +0100 | [diff] [blame] | 900 | g_set_object (&priv->quirks, quirks); |
| 901 | } |
| 902 | |
| 903 | /** |
| 904 | * fu_plugin_get_quirks: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 905 | * @self: A #FuPlugin |
Richard Hughes | 9c028f0 | 2017-10-28 21:14:28 +0100 | [diff] [blame] | 906 | * |
| 907 | * Returns the hardware database object. This can be used to discover device |
| 908 | * quirks or other device-specific settings. |
| 909 | * |
| 910 | * Returns: (transfer none): a #FuQuirks, or %NULL if not set |
| 911 | * |
| 912 | * Since: 1.0.1 |
| 913 | **/ |
| 914 | FuQuirks * |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 915 | fu_plugin_get_quirks (FuPlugin *self) |
Richard Hughes | 9c028f0 | 2017-10-28 21:14:28 +0100 | [diff] [blame] | 916 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 917 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 9c028f0 | 2017-10-28 21:14:28 +0100 | [diff] [blame] | 918 | return priv->quirks; |
| 919 | } |
| 920 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 921 | /** |
| 922 | * fu_plugin_set_runtime_versions: |
| 923 | * @self: A #FuPlugin |
| 924 | * @runtime_versions: A #GHashTables |
| 925 | * |
| 926 | * Sets the runtime versions for a plugin |
| 927 | * |
| 928 | * Since: 1.0.7 |
| 929 | **/ |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 930 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 931 | fu_plugin_set_runtime_versions (FuPlugin *self, GHashTable *runtime_versions) |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 932 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 933 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 934 | priv->runtime_versions = g_hash_table_ref (runtime_versions); |
| 935 | } |
| 936 | |
| 937 | /** |
| 938 | * fu_plugin_add_runtime_version: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 939 | * @self: A #FuPlugin |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 940 | * @component_id: An AppStream component id, e.g. "org.gnome.Software" |
| 941 | * @version: A version string, e.g. "1.2.3" |
| 942 | * |
Richard Hughes | dce9120 | 2019-04-08 12:47:45 +0100 | [diff] [blame] | 943 | * Sets a runtime version of a specific dependency. |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 944 | * |
| 945 | * Since: 1.0.7 |
| 946 | **/ |
| 947 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 948 | fu_plugin_add_runtime_version (FuPlugin *self, |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 949 | const gchar *component_id, |
| 950 | const gchar *version) |
| 951 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 952 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | b01b486 | 2018-04-20 16:39:48 +0100 | [diff] [blame] | 953 | if (priv->runtime_versions == NULL) |
| 954 | return; |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 955 | g_hash_table_insert (priv->runtime_versions, |
| 956 | g_strdup (component_id), |
| 957 | g_strdup (version)); |
| 958 | } |
| 959 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 960 | /** |
| 961 | * fu_plugin_set_compile_versions: |
| 962 | * @self: A #FuPlugin |
| 963 | * @compile_versions: A #GHashTables |
| 964 | * |
| 965 | * Sets the compile time versions for a plugin |
| 966 | * |
| 967 | * Since: 1.0.7 |
| 968 | **/ |
Richard Hughes | 34e0dab | 2018-04-20 16:43:00 +0100 | [diff] [blame] | 969 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 970 | fu_plugin_set_compile_versions (FuPlugin *self, GHashTable *compile_versions) |
Richard Hughes | 34e0dab | 2018-04-20 16:43:00 +0100 | [diff] [blame] | 971 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 972 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 34e0dab | 2018-04-20 16:43:00 +0100 | [diff] [blame] | 973 | priv->compile_versions = g_hash_table_ref (compile_versions); |
| 974 | } |
| 975 | |
| 976 | /** |
| 977 | * fu_plugin_add_compile_version: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 978 | * @self: A #FuPlugin |
Richard Hughes | 34e0dab | 2018-04-20 16:43:00 +0100 | [diff] [blame] | 979 | * @component_id: An AppStream component id, e.g. "org.gnome.Software" |
| 980 | * @version: A version string, e.g. "1.2.3" |
| 981 | * |
Richard Hughes | dce9120 | 2019-04-08 12:47:45 +0100 | [diff] [blame] | 982 | * Sets a compile-time version of a specific dependency. |
Richard Hughes | 34e0dab | 2018-04-20 16:43:00 +0100 | [diff] [blame] | 983 | * |
| 984 | * Since: 1.0.7 |
| 985 | **/ |
| 986 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 987 | fu_plugin_add_compile_version (FuPlugin *self, |
Richard Hughes | 34e0dab | 2018-04-20 16:43:00 +0100 | [diff] [blame] | 988 | const gchar *component_id, |
| 989 | const gchar *version) |
| 990 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 991 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 34e0dab | 2018-04-20 16:43:00 +0100 | [diff] [blame] | 992 | if (priv->compile_versions == NULL) |
| 993 | return; |
| 994 | g_hash_table_insert (priv->compile_versions, |
| 995 | g_strdup (component_id), |
| 996 | g_strdup (version)); |
| 997 | } |
| 998 | |
Richard Hughes | 9c028f0 | 2017-10-28 21:14:28 +0100 | [diff] [blame] | 999 | /** |
| 1000 | * fu_plugin_lookup_quirk_by_id: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 1001 | * @self: A #FuPlugin |
Richard Hughes | 87fb9ff | 2018-06-28 12:55:59 +0100 | [diff] [blame] | 1002 | * @group: A string, e.g. "DfuFlags" |
| 1003 | * @key: An ID to match the entry, e.g. "Summary" |
Richard Hughes | 9c028f0 | 2017-10-28 21:14:28 +0100 | [diff] [blame] | 1004 | * |
| 1005 | * Looks up an entry in the hardware database using a string value. |
| 1006 | * |
| 1007 | * Returns: (transfer none): values from the database, or %NULL if not found |
| 1008 | * |
| 1009 | * Since: 1.0.1 |
| 1010 | **/ |
| 1011 | const gchar * |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1012 | 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] | 1013 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1014 | FuPluginPrivate *priv = GET_PRIVATE (self); |
| 1015 | g_return_val_if_fail (FU_IS_PLUGIN (self), NULL); |
Richard Hughes | 9c028f0 | 2017-10-28 21:14:28 +0100 | [diff] [blame] | 1016 | |
Richard Hughes | 9c028f0 | 2017-10-28 21:14:28 +0100 | [diff] [blame] | 1017 | /* exact ID */ |
Richard Hughes | 87fb9ff | 2018-06-28 12:55:59 +0100 | [diff] [blame] | 1018 | return fu_quirks_lookup_by_id (priv->quirks, group, key); |
Richard Hughes | 9c028f0 | 2017-10-28 21:14:28 +0100 | [diff] [blame] | 1019 | } |
| 1020 | |
| 1021 | /** |
Richard Hughes | 8fe7cdd | 2018-08-23 10:02:44 +0100 | [diff] [blame] | 1022 | * fu_plugin_lookup_quirk_by_id_as_uint64: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 1023 | * @self: A #FuPlugin |
Richard Hughes | 8fe7cdd | 2018-08-23 10:02:44 +0100 | [diff] [blame] | 1024 | * @group: A string, e.g. "DfuFlags" |
| 1025 | * @key: An ID to match the entry, e.g. "Size" |
| 1026 | * |
| 1027 | * Looks up an entry in the hardware database using a string key, returning |
| 1028 | * an integer value. Values are assumed base 10, unless prefixed with "0x" |
| 1029 | * where they are parsed as base 16. |
| 1030 | * |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1031 | * Returns: guint64 id or 0 if not found |
Richard Hughes | 8fe7cdd | 2018-08-23 10:02:44 +0100 | [diff] [blame] | 1032 | * |
| 1033 | * Since: 1.1.2 |
| 1034 | **/ |
| 1035 | guint64 |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1036 | 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] | 1037 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1038 | 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] | 1039 | } |
| 1040 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1041 | /** |
| 1042 | * fu_plugin_set_smbios: |
| 1043 | * @self: A #FuPlugin |
| 1044 | * @smbios: A #FuSmbios |
| 1045 | * |
| 1046 | * Sets the smbios for a plugin |
| 1047 | * |
| 1048 | * Since: 1.0.0 |
| 1049 | **/ |
Richard Hughes | 1354ea9 | 2017-09-19 15:58:31 +0100 | [diff] [blame] | 1050 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1051 | fu_plugin_set_smbios (FuPlugin *self, FuSmbios *smbios) |
Richard Hughes | 49e5e05 | 2017-09-03 12:15:41 +0100 | [diff] [blame] | 1052 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1053 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 49e5e05 | 2017-09-03 12:15:41 +0100 | [diff] [blame] | 1054 | g_set_object (&priv->smbios, smbios); |
| 1055 | } |
| 1056 | |
Richard Hughes | b8f8db2 | 2017-04-25 15:56:00 +0100 | [diff] [blame] | 1057 | /** |
Richard Hughes | b082903 | 2017-01-10 09:27:08 +0000 | [diff] [blame] | 1058 | * fu_plugin_set_coldplug_delay: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 1059 | * @self: A #FuPlugin |
Richard Hughes | b082903 | 2017-01-10 09:27:08 +0000 | [diff] [blame] | 1060 | * @duration: A delay in milliseconds |
| 1061 | * |
Richard Hughes | 21eaeef | 2020-01-14 12:10:01 +0000 | [diff] [blame] | 1062 | * Set the minimum time that should be waited in-between the call to |
Richard Hughes | b082903 | 2017-01-10 09:27:08 +0000 | [diff] [blame] | 1063 | * fu_plugin_coldplug_prepare() and fu_plugin_coldplug(). This is usually going |
Richard Hughes | 203ed84 | 2020-11-02 14:25:13 +0000 | [diff] [blame] | 1064 | * to be the minimum hardware initialization time from a datasheet. |
Richard Hughes | b082903 | 2017-01-10 09:27:08 +0000 | [diff] [blame] | 1065 | * |
| 1066 | * It is better to use this function rather than using a sleep() in the plugin |
| 1067 | * itself as then only one delay is done in the daemon rather than waiting for |
| 1068 | * each coldplug prepare in a serial way. |
| 1069 | * |
| 1070 | * Additionally, very long delays should be avoided as the daemon will be |
| 1071 | * blocked from processing requests whilst the coldplug delay is being |
| 1072 | * performed. |
| 1073 | * |
| 1074 | * Since: 0.8.0 |
| 1075 | **/ |
| 1076 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1077 | fu_plugin_set_coldplug_delay (FuPlugin *self, guint duration) |
Richard Hughes | b082903 | 2017-01-10 09:27:08 +0000 | [diff] [blame] | 1078 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1079 | g_return_if_fail (FU_IS_PLUGIN (self)); |
Richard Hughes | b082903 | 2017-01-10 09:27:08 +0000 | [diff] [blame] | 1080 | g_return_if_fail (duration > 0); |
| 1081 | |
| 1082 | /* check sanity */ |
| 1083 | if (duration > FU_PLUGIN_COLDPLUG_DELAY_MAXIMUM) { |
| 1084 | g_warning ("duration of %ums is crazy, truncating to %ums", |
| 1085 | duration, |
| 1086 | FU_PLUGIN_COLDPLUG_DELAY_MAXIMUM); |
| 1087 | duration = FU_PLUGIN_COLDPLUG_DELAY_MAXIMUM; |
| 1088 | } |
| 1089 | |
| 1090 | /* emit */ |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1091 | g_signal_emit (self, signals[SIGNAL_SET_COLDPLUG_DELAY], 0, duration); |
Richard Hughes | b082903 | 2017-01-10 09:27:08 +0000 | [diff] [blame] | 1092 | } |
| 1093 | |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 1094 | static gboolean |
| 1095 | fu_plugin_device_attach (FuPlugin *self, FuDevice *device, GError **error) |
| 1096 | { |
| 1097 | g_autoptr(FuDeviceLocker) locker = NULL; |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 1098 | locker = fu_device_locker_new (device, error); |
| 1099 | if (locker == NULL) |
| 1100 | return FALSE; |
| 1101 | return fu_device_attach (device, error); |
| 1102 | } |
| 1103 | |
| 1104 | static gboolean |
| 1105 | fu_plugin_device_detach (FuPlugin *self, FuDevice *device, GError **error) |
| 1106 | { |
| 1107 | g_autoptr(FuDeviceLocker) locker = NULL; |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 1108 | locker = fu_device_locker_new (device, error); |
| 1109 | if (locker == NULL) |
| 1110 | return FALSE; |
| 1111 | return fu_device_detach (device, error); |
| 1112 | } |
| 1113 | |
| 1114 | static gboolean |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 1115 | fu_plugin_device_activate (FuPlugin *self, FuDevice *device, GError **error) |
| 1116 | { |
| 1117 | g_autoptr(FuDeviceLocker) locker = NULL; |
| 1118 | locker = fu_device_locker_new (device, error); |
| 1119 | if (locker == NULL) |
| 1120 | return FALSE; |
| 1121 | return fu_device_activate (device, error); |
| 1122 | } |
| 1123 | |
| 1124 | static gboolean |
| 1125 | fu_plugin_device_write_firmware (FuPlugin *self, FuDevice *device, |
| 1126 | GBytes *fw, FwupdInstallFlags flags, |
| 1127 | GError **error) |
| 1128 | { |
| 1129 | g_autoptr(FuDeviceLocker) locker = NULL; |
| 1130 | locker = fu_device_locker_new (device, error); |
| 1131 | if (locker == NULL) |
| 1132 | return FALSE; |
Richard Hughes | 1a61258 | 2020-09-29 19:39:38 +0100 | [diff] [blame] | 1133 | |
| 1134 | /* back the old firmware up to /var/lib/fwupd */ |
| 1135 | if (fu_device_has_flag (device, FWUPD_DEVICE_FLAG_BACKUP_BEFORE_INSTALL)) { |
| 1136 | g_autoptr(GBytes) fw_old = NULL; |
| 1137 | g_autofree gchar *path = NULL; |
| 1138 | g_autofree gchar *fn = NULL; |
| 1139 | g_autofree gchar *localstatedir = NULL; |
| 1140 | |
| 1141 | fw_old = fu_device_dump_firmware (device, error); |
| 1142 | if (fw_old == NULL) { |
| 1143 | g_prefix_error (error, "failed to backup old firmware: "); |
| 1144 | return FALSE; |
| 1145 | } |
| 1146 | localstatedir = fu_common_get_path (FU_PATH_KIND_LOCALSTATEDIR_PKG); |
| 1147 | fn = g_strdup_printf ("%s.bin", fu_device_get_version (device)); |
| 1148 | path = g_build_filename (localstatedir, |
| 1149 | "backup", |
| 1150 | fu_device_get_id (device), |
| 1151 | fu_device_get_serial (device) != NULL ? |
| 1152 | fu_device_get_serial (device) : |
| 1153 | "default", |
| 1154 | fn, NULL); |
| 1155 | if (!fu_common_set_contents_bytes (path, fw_old, error)) |
| 1156 | return FALSE; |
| 1157 | } |
| 1158 | |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 1159 | return fu_device_write_firmware (device, fw, flags, error); |
| 1160 | } |
| 1161 | |
Richard Hughes | 7f67721 | 2019-10-05 16:19:40 +0100 | [diff] [blame] | 1162 | static gboolean |
| 1163 | fu_plugin_device_read_firmware (FuPlugin *self, FuDevice *device, GError **error) |
| 1164 | { |
| 1165 | g_autoptr(FuDeviceLocker) locker = NULL; |
Richard Hughes | f0eb091 | 2019-10-10 11:37:22 +0100 | [diff] [blame] | 1166 | g_autoptr(FuFirmware) firmware = NULL; |
Richard Hughes | 7f67721 | 2019-10-05 16:19:40 +0100 | [diff] [blame] | 1167 | g_autoptr(GBytes) fw = NULL; |
| 1168 | GChecksumType checksum_types[] = { |
| 1169 | G_CHECKSUM_SHA1, |
| 1170 | G_CHECKSUM_SHA256, |
| 1171 | 0 }; |
| 1172 | locker = fu_device_locker_new (device, error); |
| 1173 | if (locker == NULL) |
| 1174 | return FALSE; |
| 1175 | if (!fu_device_detach (device, error)) |
| 1176 | return FALSE; |
Richard Hughes | f0eb091 | 2019-10-10 11:37:22 +0100 | [diff] [blame] | 1177 | firmware = fu_device_read_firmware (device, error); |
| 1178 | if (firmware == NULL) { |
| 1179 | g_autoptr(GError) error_local = NULL; |
| 1180 | if (!fu_device_attach (device, &error_local)) |
| 1181 | g_debug ("ignoring attach failure: %s", error_local->message); |
| 1182 | g_prefix_error (error, "failed to read firmware: "); |
| 1183 | return FALSE; |
| 1184 | } |
| 1185 | fw = fu_firmware_write (firmware, error); |
Richard Hughes | 7f67721 | 2019-10-05 16:19:40 +0100 | [diff] [blame] | 1186 | if (fw == NULL) { |
| 1187 | g_autoptr(GError) error_local = NULL; |
| 1188 | if (!fu_device_attach (device, &error_local)) |
Richard Hughes | f0eb091 | 2019-10-10 11:37:22 +0100 | [diff] [blame] | 1189 | g_debug ("ignoring attach failure: %s", error_local->message); |
| 1190 | g_prefix_error (error, "failed to write firmware: "); |
Richard Hughes | 7f67721 | 2019-10-05 16:19:40 +0100 | [diff] [blame] | 1191 | return FALSE; |
| 1192 | } |
| 1193 | for (guint i = 0; checksum_types[i] != 0; i++) { |
| 1194 | g_autofree gchar *hash = NULL; |
| 1195 | hash = g_compute_checksum_for_bytes (checksum_types[i], fw); |
| 1196 | fu_device_add_checksum (device, hash); |
| 1197 | } |
| 1198 | return fu_device_attach (device, error); |
| 1199 | } |
| 1200 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1201 | /** |
| 1202 | * fu_plugin_runner_startup: |
| 1203 | * @self: a #FuPlugin |
| 1204 | * @error: a #GError or NULL |
| 1205 | * |
| 1206 | * Runs the startup routine for the plugin |
| 1207 | * |
| 1208 | * Returns: #TRUE for success, #FALSE for failure |
| 1209 | * |
| 1210 | * Since: 0.8.0 |
| 1211 | **/ |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1212 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1213 | fu_plugin_runner_startup (FuPlugin *self, GError **error) |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1214 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1215 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 1216 | FuPluginStartupFunc func = NULL; |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1217 | g_autoptr(GError) error_local = NULL; |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1218 | |
| 1219 | /* not enabled */ |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1220 | if (fu_plugin_has_flag (self, FWUPD_PLUGIN_FLAG_DISABLED)) |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1221 | return TRUE; |
| 1222 | |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 1223 | /* no object loaded */ |
| 1224 | if (priv->module == NULL) |
| 1225 | return TRUE; |
| 1226 | |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1227 | /* optional */ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1228 | g_module_symbol (priv->module, "fu_plugin_startup", (gpointer *) &func); |
| 1229 | if (func == NULL) |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1230 | return TRUE; |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1231 | g_debug ("startup(%s)", fu_plugin_get_name (self)); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1232 | if (!func (self, &error_local)) { |
| 1233 | if (error_local == NULL) { |
Mario Limonciello | 67a8b89 | 2020-09-28 13:44:39 -0500 | [diff] [blame] | 1234 | g_critical ("unset plugin error in startup(%s)", |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1235 | fu_plugin_get_name (self)); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1236 | g_set_error_literal (&error_local, |
| 1237 | FWUPD_ERROR, |
| 1238 | FWUPD_ERROR_INTERNAL, |
| 1239 | "unspecified error"); |
| 1240 | } |
| 1241 | g_propagate_prefixed_error (error, g_steal_pointer (&error_local), |
| 1242 | "failed to startup using %s: ", |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1243 | fu_plugin_get_name (self)); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1244 | return FALSE; |
| 1245 | } |
| 1246 | return TRUE; |
| 1247 | } |
| 1248 | |
| 1249 | static gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1250 | fu_plugin_runner_device_generic (FuPlugin *self, FuDevice *device, |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 1251 | const gchar *symbol_name, |
| 1252 | FuPluginDeviceFunc device_func, |
| 1253 | GError **error) |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1254 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1255 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1256 | FuPluginDeviceFunc func = NULL; |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1257 | g_autoptr(GError) error_local = NULL; |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1258 | |
| 1259 | /* not enabled */ |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1260 | if (fu_plugin_has_flag (self, FWUPD_PLUGIN_FLAG_DISABLED)) |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1261 | return TRUE; |
| 1262 | |
Richard Hughes | d3d96cc | 2017-11-14 11:34:33 +0000 | [diff] [blame] | 1263 | /* no object loaded */ |
| 1264 | if (priv->module == NULL) |
| 1265 | return TRUE; |
| 1266 | |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1267 | /* optional */ |
| 1268 | g_module_symbol (priv->module, symbol_name, (gpointer *) &func); |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 1269 | if (func == NULL) { |
| 1270 | if (device_func != NULL) { |
Mario Limonciello | 67a8b89 | 2020-09-28 13:44:39 -0500 | [diff] [blame] | 1271 | g_debug ("running superclassed %s(%s)", |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1272 | symbol_name + 10, fu_plugin_get_name (self)); |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 1273 | return device_func (self, device, error); |
| 1274 | } |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1275 | return TRUE; |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 1276 | } |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1277 | g_debug ("%s(%s)", symbol_name + 10, fu_plugin_get_name (self)); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1278 | if (!func (self, device, &error_local)) { |
| 1279 | if (error_local == NULL) { |
Mario Limonciello | 67a8b89 | 2020-09-28 13:44:39 -0500 | [diff] [blame] | 1280 | g_critical ("unset plugin error in %s(%s)", |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1281 | fu_plugin_get_name (self), symbol_name + 10); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1282 | g_set_error_literal (&error_local, |
| 1283 | FWUPD_ERROR, |
| 1284 | FWUPD_ERROR_INTERNAL, |
| 1285 | "unspecified error"); |
| 1286 | } |
| 1287 | g_propagate_prefixed_error (error, g_steal_pointer (&error_local), |
| 1288 | "failed to %s using %s: ", |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1289 | symbol_name + 10, fu_plugin_get_name (self)); |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1290 | return FALSE; |
| 1291 | } |
| 1292 | return TRUE; |
| 1293 | } |
| 1294 | |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 1295 | static gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1296 | fu_plugin_runner_flagged_device_generic (FuPlugin *self, FwupdInstallFlags flags, |
Mario Limonciello | e3b1a3f | 2018-08-21 13:01:45 -0500 | [diff] [blame] | 1297 | FuDevice *device, |
| 1298 | const gchar *symbol_name, GError **error) |
| 1299 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1300 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Mario Limonciello | e3b1a3f | 2018-08-21 13:01:45 -0500 | [diff] [blame] | 1301 | FuPluginFlaggedDeviceFunc func = NULL; |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1302 | g_autoptr(GError) error_local = NULL; |
Mario Limonciello | e3b1a3f | 2018-08-21 13:01:45 -0500 | [diff] [blame] | 1303 | |
| 1304 | /* not enabled */ |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1305 | if (fu_plugin_has_flag (self, FWUPD_PLUGIN_FLAG_DISABLED)) |
Mario Limonciello | e3b1a3f | 2018-08-21 13:01:45 -0500 | [diff] [blame] | 1306 | return TRUE; |
| 1307 | |
| 1308 | /* no object loaded */ |
| 1309 | if (priv->module == NULL) |
| 1310 | return TRUE; |
| 1311 | |
| 1312 | /* optional */ |
| 1313 | g_module_symbol (priv->module, symbol_name, (gpointer *) &func); |
| 1314 | if (func == NULL) |
| 1315 | return TRUE; |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1316 | g_debug ("%s(%s)", symbol_name + 10, fu_plugin_get_name (self)); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1317 | if (!func (self, flags, device, &error_local)) { |
| 1318 | if (error_local == NULL) { |
Mario Limonciello | 67a8b89 | 2020-09-28 13:44:39 -0500 | [diff] [blame] | 1319 | g_critical ("unset plugin error in %s(%s)", |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1320 | fu_plugin_get_name (self), symbol_name + 10); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1321 | g_set_error_literal (&error_local, |
| 1322 | FWUPD_ERROR, |
| 1323 | FWUPD_ERROR_INTERNAL, |
| 1324 | "unspecified error"); |
| 1325 | } |
| 1326 | g_propagate_prefixed_error (error, g_steal_pointer (&error_local), |
| 1327 | "failed to %s using %s: ", |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1328 | symbol_name + 10, fu_plugin_get_name (self)); |
Mario Limonciello | e3b1a3f | 2018-08-21 13:01:45 -0500 | [diff] [blame] | 1329 | return FALSE; |
| 1330 | } |
| 1331 | return TRUE; |
| 1332 | |
| 1333 | } |
| 1334 | |
| 1335 | static gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1336 | fu_plugin_runner_device_array_generic (FuPlugin *self, GPtrArray *devices, |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 1337 | const gchar *symbol_name, GError **error) |
| 1338 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1339 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 1340 | FuPluginDeviceArrayFunc func = NULL; |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1341 | g_autoptr(GError) error_local = NULL; |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 1342 | |
| 1343 | /* not enabled */ |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1344 | if (fu_plugin_has_flag (self, FWUPD_PLUGIN_FLAG_DISABLED)) |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 1345 | return TRUE; |
| 1346 | |
| 1347 | /* no object loaded */ |
| 1348 | if (priv->module == NULL) |
| 1349 | return TRUE; |
| 1350 | |
| 1351 | /* optional */ |
| 1352 | g_module_symbol (priv->module, symbol_name, (gpointer *) &func); |
| 1353 | if (func == NULL) |
| 1354 | return TRUE; |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1355 | g_debug ("%s(%s)", symbol_name + 10, fu_plugin_get_name (self)); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1356 | if (!func (self, devices, &error_local)) { |
| 1357 | if (error_local == NULL) { |
Mario Limonciello | 67a8b89 | 2020-09-28 13:44:39 -0500 | [diff] [blame] | 1358 | g_critical ("unset plugin error in for %s(%s)", |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1359 | fu_plugin_get_name (self), symbol_name + 10); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1360 | g_set_error_literal (&error_local, |
| 1361 | FWUPD_ERROR, |
| 1362 | FWUPD_ERROR_INTERNAL, |
| 1363 | "unspecified error"); |
| 1364 | } |
| 1365 | g_propagate_prefixed_error (error, g_steal_pointer (&error_local), |
| 1366 | "failed to %s using %s: ", |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1367 | symbol_name + 10, fu_plugin_get_name (self)); |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 1368 | return FALSE; |
| 1369 | } |
| 1370 | return TRUE; |
| 1371 | } |
| 1372 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1373 | /** |
| 1374 | * fu_plugin_runner_coldplug: |
| 1375 | * @self: a #FuPlugin |
| 1376 | * @error: a #GError or NULL |
| 1377 | * |
| 1378 | * Runs the coldplug routine for the plugin |
| 1379 | * |
| 1380 | * Returns: #TRUE for success, #FALSE for failure |
| 1381 | * |
| 1382 | * Since: 0.8.0 |
| 1383 | **/ |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1384 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1385 | fu_plugin_runner_coldplug (FuPlugin *self, GError **error) |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1386 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1387 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 1388 | FuPluginStartupFunc func = NULL; |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1389 | g_autoptr(GError) error_local = NULL; |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1390 | |
| 1391 | /* not enabled */ |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1392 | if (fu_plugin_has_flag (self, FWUPD_PLUGIN_FLAG_DISABLED)) |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1393 | return TRUE; |
| 1394 | |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 1395 | /* no object loaded */ |
| 1396 | if (priv->module == NULL) |
| 1397 | return TRUE; |
| 1398 | |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1399 | /* optional */ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1400 | g_module_symbol (priv->module, "fu_plugin_coldplug", (gpointer *) &func); |
| 1401 | if (func == NULL) |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1402 | return TRUE; |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1403 | g_debug ("coldplug(%s)", fu_plugin_get_name (self)); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1404 | if (!func (self, &error_local)) { |
| 1405 | if (error_local == NULL) { |
Mario Limonciello | 67a8b89 | 2020-09-28 13:44:39 -0500 | [diff] [blame] | 1406 | g_critical ("unset plugin error in coldplug(%s)", |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1407 | fu_plugin_get_name (self)); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1408 | g_set_error_literal (&error_local, |
| 1409 | FWUPD_ERROR, |
| 1410 | FWUPD_ERROR_INTERNAL, |
| 1411 | "unspecified error"); |
| 1412 | } |
| 1413 | g_propagate_prefixed_error (error, g_steal_pointer (&error_local), |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1414 | "failed to coldplug using %s: ", fu_plugin_get_name (self)); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1415 | return FALSE; |
| 1416 | } |
| 1417 | return TRUE; |
| 1418 | } |
| 1419 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1420 | /** |
| 1421 | * fu_plugin_runner_recoldplug: |
| 1422 | * @self: a #FuPlugin |
| 1423 | * @error: a #GError or NULL |
| 1424 | * |
| 1425 | * Runs the recoldplug routine for the plugin |
| 1426 | * |
| 1427 | * Returns: #TRUE for success, #FALSE for failure |
| 1428 | * |
| 1429 | * Since: 1.0.4 |
| 1430 | **/ |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 1431 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1432 | fu_plugin_runner_recoldplug (FuPlugin *self, GError **error) |
Richard Hughes | 2de8f13 | 2018-01-17 09:12:02 +0000 | [diff] [blame] | 1433 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1434 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 2de8f13 | 2018-01-17 09:12:02 +0000 | [diff] [blame] | 1435 | FuPluginStartupFunc func = NULL; |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1436 | g_autoptr(GError) error_local = NULL; |
Richard Hughes | 2de8f13 | 2018-01-17 09:12:02 +0000 | [diff] [blame] | 1437 | |
| 1438 | /* not enabled */ |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1439 | if (fu_plugin_has_flag (self, FWUPD_PLUGIN_FLAG_DISABLED)) |
Richard Hughes | 2de8f13 | 2018-01-17 09:12:02 +0000 | [diff] [blame] | 1440 | return TRUE; |
| 1441 | |
| 1442 | /* no object loaded */ |
| 1443 | if (priv->module == NULL) |
| 1444 | return TRUE; |
| 1445 | |
| 1446 | /* optional */ |
| 1447 | g_module_symbol (priv->module, "fu_plugin_recoldplug", (gpointer *) &func); |
| 1448 | if (func == NULL) |
| 1449 | return TRUE; |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1450 | g_debug ("recoldplug(%s)", fu_plugin_get_name (self)); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1451 | if (!func (self, &error_local)) { |
| 1452 | if (error_local == NULL) { |
Mario Limonciello | 67a8b89 | 2020-09-28 13:44:39 -0500 | [diff] [blame] | 1453 | g_critical ("unset plugin error in recoldplug(%s)", |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1454 | fu_plugin_get_name (self)); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1455 | g_set_error_literal (&error_local, |
| 1456 | FWUPD_ERROR, |
| 1457 | FWUPD_ERROR_INTERNAL, |
| 1458 | "unspecified error"); |
| 1459 | } |
| 1460 | g_propagate_prefixed_error (error, g_steal_pointer (&error_local), |
| 1461 | "failed to recoldplug using %s: ", |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1462 | fu_plugin_get_name (self)); |
Richard Hughes | 2de8f13 | 2018-01-17 09:12:02 +0000 | [diff] [blame] | 1463 | return FALSE; |
| 1464 | } |
| 1465 | return TRUE; |
| 1466 | } |
| 1467 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1468 | /** |
| 1469 | * fu_plugin_runner_coldplug_prepare: |
| 1470 | * @self: a #FuPlugin |
| 1471 | * @error: a #GError or NULL |
| 1472 | * |
| 1473 | * Runs the coldplug_prepare routine for the plugin |
| 1474 | * |
| 1475 | * Returns: #TRUE for success, #FALSE for failure |
| 1476 | * |
| 1477 | * Since: 0.8.0 |
| 1478 | **/ |
Richard Hughes | 2de8f13 | 2018-01-17 09:12:02 +0000 | [diff] [blame] | 1479 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1480 | fu_plugin_runner_coldplug_prepare (FuPlugin *self, GError **error) |
Richard Hughes | 46487c9 | 2017-01-07 21:26:34 +0000 | [diff] [blame] | 1481 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1482 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 46487c9 | 2017-01-07 21:26:34 +0000 | [diff] [blame] | 1483 | FuPluginStartupFunc func = NULL; |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1484 | g_autoptr(GError) error_local = NULL; |
Richard Hughes | 46487c9 | 2017-01-07 21:26:34 +0000 | [diff] [blame] | 1485 | |
| 1486 | /* not enabled */ |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1487 | if (fu_plugin_has_flag (self, FWUPD_PLUGIN_FLAG_DISABLED)) |
Richard Hughes | 46487c9 | 2017-01-07 21:26:34 +0000 | [diff] [blame] | 1488 | return TRUE; |
| 1489 | |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 1490 | /* no object loaded */ |
| 1491 | if (priv->module == NULL) |
| 1492 | return TRUE; |
| 1493 | |
Richard Hughes | 46487c9 | 2017-01-07 21:26:34 +0000 | [diff] [blame] | 1494 | /* optional */ |
| 1495 | g_module_symbol (priv->module, "fu_plugin_coldplug_prepare", (gpointer *) &func); |
| 1496 | if (func == NULL) |
| 1497 | return TRUE; |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1498 | g_debug ("coldplug_prepare(%s)", fu_plugin_get_name (self)); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1499 | if (!func (self, &error_local)) { |
| 1500 | if (error_local == NULL) { |
Mario Limonciello | 67a8b89 | 2020-09-28 13:44:39 -0500 | [diff] [blame] | 1501 | g_critical ("unset plugin error in coldplug_prepare(%s)", |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1502 | fu_plugin_get_name (self)); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1503 | g_set_error_literal (&error_local, |
| 1504 | FWUPD_ERROR, |
| 1505 | FWUPD_ERROR_INTERNAL, |
| 1506 | "unspecified error"); |
| 1507 | } |
| 1508 | g_propagate_prefixed_error (error, g_steal_pointer (&error_local), |
| 1509 | "failed to coldplug_prepare using %s: ", |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1510 | fu_plugin_get_name (self)); |
Richard Hughes | 46487c9 | 2017-01-07 21:26:34 +0000 | [diff] [blame] | 1511 | return FALSE; |
| 1512 | } |
| 1513 | return TRUE; |
| 1514 | } |
| 1515 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1516 | /** |
| 1517 | * fu_plugin_runner_coldplug_cleanup: |
| 1518 | * @self: a #FuPlugin |
| 1519 | * @error: a #GError or NULL |
| 1520 | * |
| 1521 | * Runs the coldplug_cleanup routine for the plugin |
| 1522 | * |
| 1523 | * Returns: #TRUE for success, #FALSE for failure |
| 1524 | * |
| 1525 | * Since: 0.8.0 |
| 1526 | **/ |
Richard Hughes | 46487c9 | 2017-01-07 21:26:34 +0000 | [diff] [blame] | 1527 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1528 | fu_plugin_runner_coldplug_cleanup (FuPlugin *self, GError **error) |
Richard Hughes | 46487c9 | 2017-01-07 21:26:34 +0000 | [diff] [blame] | 1529 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1530 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 46487c9 | 2017-01-07 21:26:34 +0000 | [diff] [blame] | 1531 | FuPluginStartupFunc func = NULL; |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1532 | g_autoptr(GError) error_local = NULL; |
Richard Hughes | 46487c9 | 2017-01-07 21:26:34 +0000 | [diff] [blame] | 1533 | |
| 1534 | /* not enabled */ |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1535 | if (fu_plugin_has_flag (self, FWUPD_PLUGIN_FLAG_DISABLED)) |
Richard Hughes | 46487c9 | 2017-01-07 21:26:34 +0000 | [diff] [blame] | 1536 | return TRUE; |
| 1537 | |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 1538 | /* no object loaded */ |
| 1539 | if (priv->module == NULL) |
| 1540 | return TRUE; |
| 1541 | |
Richard Hughes | 46487c9 | 2017-01-07 21:26:34 +0000 | [diff] [blame] | 1542 | /* optional */ |
| 1543 | g_module_symbol (priv->module, "fu_plugin_coldplug_cleanup", (gpointer *) &func); |
| 1544 | if (func == NULL) |
| 1545 | return TRUE; |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1546 | g_debug ("coldplug_cleanup(%s)", fu_plugin_get_name (self)); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1547 | if (!func (self, &error_local)) { |
| 1548 | if (error_local == NULL) { |
Mario Limonciello | 67a8b89 | 2020-09-28 13:44:39 -0500 | [diff] [blame] | 1549 | g_critical ("unset plugin error in coldplug_cleanup(%s)", |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1550 | fu_plugin_get_name (self)); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1551 | g_set_error_literal (&error_local, |
| 1552 | FWUPD_ERROR, |
| 1553 | FWUPD_ERROR_INTERNAL, |
| 1554 | "unspecified error"); |
| 1555 | } |
| 1556 | g_propagate_prefixed_error (error, g_steal_pointer (&error_local), |
| 1557 | "failed to coldplug_cleanup using %s: ", |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1558 | fu_plugin_get_name (self)); |
Richard Hughes | 46487c9 | 2017-01-07 21:26:34 +0000 | [diff] [blame] | 1559 | return FALSE; |
| 1560 | } |
| 1561 | return TRUE; |
| 1562 | } |
| 1563 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1564 | /** |
| 1565 | * fu_plugin_runner_composite_prepare: |
| 1566 | * @self: a #FuPlugin |
Richard Hughes | a0d81c7 | 2019-11-27 11:41:54 +0000 | [diff] [blame] | 1567 | * @devices: (element-type FuDevice): a #GPtrArray of devices |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1568 | * @error: a #GError or NULL |
| 1569 | * |
| 1570 | * Runs the composite_prepare routine for the plugin |
| 1571 | * |
| 1572 | * Returns: #TRUE for success, #FALSE for failure |
| 1573 | * |
| 1574 | * Since: 1.0.9 |
| 1575 | **/ |
Richard Hughes | 46487c9 | 2017-01-07 21:26:34 +0000 | [diff] [blame] | 1576 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1577 | fu_plugin_runner_composite_prepare (FuPlugin *self, GPtrArray *devices, GError **error) |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 1578 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1579 | return fu_plugin_runner_device_array_generic (self, devices, |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 1580 | "fu_plugin_composite_prepare", |
| 1581 | error); |
| 1582 | } |
| 1583 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1584 | /** |
| 1585 | * fu_plugin_runner_composite_cleanup: |
| 1586 | * @self: a #FuPlugin |
Richard Hughes | a0d81c7 | 2019-11-27 11:41:54 +0000 | [diff] [blame] | 1587 | * @devices: (element-type FuDevice): a #GPtrArray of devices |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1588 | * @error: a #GError or NULL |
| 1589 | * |
| 1590 | * Runs the composite_cleanup routine for the plugin |
| 1591 | * |
| 1592 | * Returns: #TRUE for success, #FALSE for failure |
| 1593 | * |
| 1594 | * Since: 1.0.9 |
| 1595 | **/ |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 1596 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1597 | fu_plugin_runner_composite_cleanup (FuPlugin *self, GPtrArray *devices, GError **error) |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 1598 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1599 | return fu_plugin_runner_device_array_generic (self, devices, |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 1600 | "fu_plugin_composite_cleanup", |
| 1601 | error); |
| 1602 | } |
| 1603 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1604 | /** |
| 1605 | * fu_plugin_runner_update_prepare: |
| 1606 | * @self: a #FuPlugin |
Richard Hughes | 2bbb7d2 | 2020-11-30 09:18:45 +0000 | [diff] [blame] | 1607 | * @flags: #FwupdInstallFlags |
| 1608 | * @device: a #FuDevice |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1609 | * @error: a #GError or NULL |
| 1610 | * |
| 1611 | * Runs the update_prepare routine for the plugin |
| 1612 | * |
| 1613 | * Returns: #TRUE for success, #FALSE for failure |
| 1614 | * |
| 1615 | * Since: 1.1.2 |
| 1616 | **/ |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 1617 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1618 | fu_plugin_runner_update_prepare (FuPlugin *self, FwupdInstallFlags flags, FuDevice *device, |
Mario Limonciello | e3b1a3f | 2018-08-21 13:01:45 -0500 | [diff] [blame] | 1619 | GError **error) |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 1620 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1621 | return fu_plugin_runner_flagged_device_generic (self, flags, device, |
Mario Limonciello | e3b1a3f | 2018-08-21 13:01:45 -0500 | [diff] [blame] | 1622 | "fu_plugin_update_prepare", |
| 1623 | error); |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 1624 | } |
| 1625 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1626 | /** |
| 1627 | * fu_plugin_runner_update_cleanup: |
| 1628 | * @self: a #FuPlugin |
Richard Hughes | 2bbb7d2 | 2020-11-30 09:18:45 +0000 | [diff] [blame] | 1629 | * @flags: #FwupdInstallFlags |
| 1630 | * @device: a #FuDevice |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1631 | * @error: a #GError or NULL |
| 1632 | * |
| 1633 | * Runs the update_cleanup routine for the plugin |
| 1634 | * |
| 1635 | * Returns: #TRUE for success, #FALSE for failure |
| 1636 | * |
| 1637 | * Since: 1.1.2 |
| 1638 | **/ |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 1639 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1640 | fu_plugin_runner_update_cleanup (FuPlugin *self, FwupdInstallFlags flags, FuDevice *device, |
Mario Limonciello | e3b1a3f | 2018-08-21 13:01:45 -0500 | [diff] [blame] | 1641 | GError **error) |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 1642 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1643 | return fu_plugin_runner_flagged_device_generic (self, flags, device, |
Mario Limonciello | e3b1a3f | 2018-08-21 13:01:45 -0500 | [diff] [blame] | 1644 | "fu_plugin_update_cleanup", |
| 1645 | error); |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1646 | } |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 1647 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1648 | /** |
| 1649 | * fu_plugin_runner_update_attach: |
| 1650 | * @self: a #FuPlugin |
| 1651 | * @device: a #FuDevice |
| 1652 | * @error: a #GError or NULL |
| 1653 | * |
| 1654 | * Runs the update_attach routine for the plugin |
| 1655 | * |
| 1656 | * Returns: #TRUE for success, #FALSE for failure |
| 1657 | * |
| 1658 | * Since: 1.1.2 |
| 1659 | **/ |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1660 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1661 | fu_plugin_runner_update_attach (FuPlugin *self, FuDevice *device, GError **error) |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1662 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1663 | return fu_plugin_runner_device_generic (self, device, |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 1664 | "fu_plugin_update_attach", |
| 1665 | fu_plugin_device_attach, |
| 1666 | error); |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1667 | } |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 1668 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1669 | /** |
| 1670 | * fu_plugin_runner_update_detach: |
| 1671 | * @self: a #FuPlugin |
| 1672 | * @device: A #FuDevice |
| 1673 | * @error: a #GError or NULL |
| 1674 | * |
| 1675 | * Runs the update_detach routine for the plugin |
| 1676 | * |
| 1677 | * Returns: #TRUE for success, #FALSE for failure |
| 1678 | * |
| 1679 | * Since: 1.1.2 |
| 1680 | **/ |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1681 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1682 | fu_plugin_runner_update_detach (FuPlugin *self, FuDevice *device, GError **error) |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1683 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1684 | return fu_plugin_runner_device_generic (self, device, |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 1685 | "fu_plugin_update_detach", |
| 1686 | fu_plugin_device_detach, |
| 1687 | error); |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1688 | } |
| 1689 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1690 | /** |
| 1691 | * fu_plugin_runner_update_reload: |
| 1692 | * @self: a #FuPlugin |
Richard Hughes | 2bbb7d2 | 2020-11-30 09:18:45 +0000 | [diff] [blame] | 1693 | * @device: A #FuDevice |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1694 | * @error: a #GError or NULL |
| 1695 | * |
| 1696 | * Runs reload routine for a device |
| 1697 | * |
| 1698 | * Returns: #TRUE for success, #FALSE for failure |
| 1699 | * |
| 1700 | * Since: 1.1.2 |
| 1701 | **/ |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1702 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1703 | fu_plugin_runner_update_reload (FuPlugin *self, FuDevice *device, GError **error) |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1704 | { |
Richard Hughes | 42f33df | 2019-10-05 20:52:33 +0100 | [diff] [blame] | 1705 | g_autoptr(FuDeviceLocker) locker = NULL; |
| 1706 | |
| 1707 | /* not enabled */ |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1708 | if (fu_plugin_has_flag (self, FWUPD_PLUGIN_FLAG_DISABLED)) |
Richard Hughes | 42f33df | 2019-10-05 20:52:33 +0100 | [diff] [blame] | 1709 | return TRUE; |
| 1710 | |
| 1711 | /* no object loaded */ |
| 1712 | locker = fu_device_locker_new (device, error); |
| 1713 | if (locker == NULL) |
| 1714 | return FALSE; |
| 1715 | return fu_device_reload (device, error); |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 1716 | } |
| 1717 | |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 1718 | /** |
Richard Hughes | 196c6c6 | 2020-05-11 19:42:47 +0100 | [diff] [blame] | 1719 | * fu_plugin_runner_add_security_attrs: |
| 1720 | * @self: a #FuPlugin |
Richard Hughes | 3ecd22c | 2020-05-19 20:13:47 +0100 | [diff] [blame] | 1721 | * @attrs: a #FuSecurityAttrs |
Richard Hughes | 196c6c6 | 2020-05-11 19:42:47 +0100 | [diff] [blame] | 1722 | * |
Richard Hughes | 3ecd22c | 2020-05-19 20:13:47 +0100 | [diff] [blame] | 1723 | * Runs the `add_security_attrs()` routine for the plugin |
Richard Hughes | 196c6c6 | 2020-05-11 19:42:47 +0100 | [diff] [blame] | 1724 | * |
| 1725 | * Since: 1.5.0 |
| 1726 | **/ |
Richard Hughes | f58ac73 | 2020-05-12 15:23:44 +0100 | [diff] [blame] | 1727 | void |
| 1728 | fu_plugin_runner_add_security_attrs (FuPlugin *self, FuSecurityAttrs *attrs) |
Richard Hughes | 196c6c6 | 2020-05-11 19:42:47 +0100 | [diff] [blame] | 1729 | { |
Richard Hughes | f58ac73 | 2020-05-12 15:23:44 +0100 | [diff] [blame] | 1730 | FuPluginPrivate *priv = GET_PRIVATE (self); |
| 1731 | FuPluginSecurityAttrsFunc func = NULL; |
| 1732 | const gchar *symbol_name = "fu_plugin_add_security_attrs"; |
| 1733 | |
| 1734 | /* no object loaded */ |
| 1735 | if (priv->module == NULL) |
| 1736 | return; |
| 1737 | |
| 1738 | /* optional, but gets called even for disabled plugins */ |
| 1739 | g_module_symbol (priv->module, symbol_name, (gpointer *) &func); |
| 1740 | if (func == NULL) |
| 1741 | return; |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1742 | g_debug ("%s(%s)", symbol_name + 10, fu_plugin_get_name (self)); |
Richard Hughes | f58ac73 | 2020-05-12 15:23:44 +0100 | [diff] [blame] | 1743 | func (self, attrs); |
Richard Hughes | 196c6c6 | 2020-05-11 19:42:47 +0100 | [diff] [blame] | 1744 | } |
| 1745 | |
| 1746 | /** |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 1747 | * fu_plugin_add_udev_subsystem: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 1748 | * @self: a #FuPlugin |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 1749 | * @subsystem: a subsystem name, e.g. `pciport` |
| 1750 | * |
| 1751 | * Registers the udev subsystem to be watched by the daemon. |
| 1752 | * |
| 1753 | * Plugins can use this method only in fu_plugin_init() |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1754 | * |
| 1755 | * Since: 1.1.2 |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 1756 | **/ |
| 1757 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1758 | fu_plugin_add_udev_subsystem (FuPlugin *self, const gchar *subsystem) |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 1759 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1760 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | ea327fc | 2020-06-22 15:23:29 +0100 | [diff] [blame] | 1761 | if (priv->udev_subsystems == NULL) |
| 1762 | priv->udev_subsystems = g_ptr_array_new_with_free_func (g_free); |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 1763 | for (guint i = 0; i < priv->udev_subsystems->len; i++) { |
| 1764 | const gchar *subsystem_tmp = g_ptr_array_index (priv->udev_subsystems, i); |
| 1765 | if (g_strcmp0 (subsystem_tmp, subsystem) == 0) |
| 1766 | return; |
| 1767 | } |
| 1768 | g_debug ("added udev subsystem watch of %s", subsystem); |
| 1769 | g_ptr_array_add (priv->udev_subsystems, g_strdup (subsystem)); |
| 1770 | } |
| 1771 | |
Richard Hughes | 989acf1 | 2019-10-05 20:16:47 +0100 | [diff] [blame] | 1772 | /** |
| 1773 | * fu_plugin_set_device_gtype: |
| 1774 | * @self: a #FuPlugin |
| 1775 | * @device_gtype: a #GType `FU_TYPE_DEVICE` |
| 1776 | * |
| 1777 | * Sets the device #GType which is used when creating devices. |
| 1778 | * |
Richard Hughes | 525f71f | 2021-02-09 14:52:47 +0000 | [diff] [blame] | 1779 | * If this method is used then fu_plugin_backend_device_added() is not called, and |
Richard Hughes | 989acf1 | 2019-10-05 20:16:47 +0100 | [diff] [blame] | 1780 | * instead the object is created in the daemon for the plugin. |
| 1781 | * |
| 1782 | * Plugins can use this method only in fu_plugin_init() |
| 1783 | * |
| 1784 | * Since: 1.3.3 |
| 1785 | **/ |
| 1786 | void |
| 1787 | fu_plugin_set_device_gtype (FuPlugin *self, GType device_gtype) |
| 1788 | { |
| 1789 | FuPluginPrivate *priv = GET_PRIVATE (self); |
| 1790 | priv->device_gtype = device_gtype; |
| 1791 | } |
| 1792 | |
Richard Hughes | 9f71fe3 | 2021-01-03 20:35:36 +0000 | [diff] [blame] | 1793 | static gchar * |
| 1794 | fu_common_string_uncamelcase (const gchar *str) |
| 1795 | { |
| 1796 | GString *tmp = g_string_new (NULL); |
| 1797 | for (guint i = 0; str[i] != '\0'; i++) { |
| 1798 | if (g_ascii_islower (str[i]) || |
| 1799 | g_ascii_isdigit (str[i])) { |
| 1800 | g_string_append_c (tmp, str[i]); |
| 1801 | continue; |
| 1802 | } |
| 1803 | if (i > 0) |
| 1804 | g_string_append_c (tmp, '-'); |
| 1805 | g_string_append_c (tmp, g_ascii_tolower (str[i])); |
| 1806 | } |
| 1807 | return g_string_free (tmp, FALSE); |
| 1808 | } |
| 1809 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1810 | /** |
| 1811 | * fu_plugin_add_firmware_gtype: |
| 1812 | * @self: a #FuPlugin |
Richard Hughes | 9f71fe3 | 2021-01-03 20:35:36 +0000 | [diff] [blame] | 1813 | * @id: (nullable): An optional string describing the type, e.g. "ihex" |
| 1814 | * @gtype: a #GType e.g. `FU_TYPE_FOO_FIRMWARE` |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1815 | * |
Richard Hughes | 9f71fe3 | 2021-01-03 20:35:36 +0000 | [diff] [blame] | 1816 | * Adds a firmware #GType which is used when creating devices. If @id is not |
| 1817 | * specified then it is guessed using the #GType name. |
| 1818 | * |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1819 | * Plugins can use this method only in fu_plugin_init() |
| 1820 | * |
| 1821 | * Since: 1.3.3 |
| 1822 | **/ |
Richard Hughes | 95c98a9 | 2019-10-22 16:03:15 +0100 | [diff] [blame] | 1823 | void |
| 1824 | fu_plugin_add_firmware_gtype (FuPlugin *self, const gchar *id, GType gtype) |
| 1825 | { |
Richard Hughes | 9f71fe3 | 2021-01-03 20:35:36 +0000 | [diff] [blame] | 1826 | g_autofree gchar *id_safe = NULL; |
| 1827 | if (id != NULL) { |
| 1828 | id_safe = g_strdup (id); |
| 1829 | } else { |
Richard Hughes | ebb10a5 | 2021-01-05 13:34:39 +0000 | [diff] [blame] | 1830 | g_autoptr(GString) str = g_string_new (g_type_name (gtype)); |
Richard Hughes | 9f71fe3 | 2021-01-03 20:35:36 +0000 | [diff] [blame] | 1831 | if (g_str_has_prefix (str->str, "Fu")) |
| 1832 | g_string_erase (str, 0, 2); |
| 1833 | fu_common_string_replace (str, "Firmware", ""); |
| 1834 | id_safe = fu_common_string_uncamelcase (str->str); |
| 1835 | } |
| 1836 | g_signal_emit (self, signals[SIGNAL_ADD_FIRMWARE_GTYPE], 0, id_safe, gtype); |
Richard Hughes | 95c98a9 | 2019-10-22 16:03:15 +0100 | [diff] [blame] | 1837 | } |
| 1838 | |
Richard Hughes | 989acf1 | 2019-10-05 20:16:47 +0100 | [diff] [blame] | 1839 | static gboolean |
Richard Hughes | d8a8d5e | 2019-10-08 13:05:02 +0100 | [diff] [blame] | 1840 | fu_plugin_check_supported_device (FuPlugin *self, FuDevice *device) |
| 1841 | { |
| 1842 | GPtrArray *instance_ids = fu_device_get_instance_ids (device); |
| 1843 | for (guint i = 0; i < instance_ids->len; i++) { |
| 1844 | const gchar *instance_id = g_ptr_array_index (instance_ids, i); |
| 1845 | g_autofree gchar *guid = fwupd_guid_hash_string (instance_id); |
| 1846 | if (fu_plugin_check_supported (self, guid)) |
| 1847 | return TRUE; |
| 1848 | } |
| 1849 | return FALSE; |
| 1850 | } |
| 1851 | |
| 1852 | static gboolean |
Richard Hughes | 525f71f | 2021-02-09 14:52:47 +0000 | [diff] [blame] | 1853 | fu_plugin_backend_device_added (FuPlugin *self, FuDevice *device, GError **error) |
Richard Hughes | 989acf1 | 2019-10-05 20:16:47 +0100 | [diff] [blame] | 1854 | { |
| 1855 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | d8a8d5e | 2019-10-08 13:05:02 +0100 | [diff] [blame] | 1856 | GType device_gtype = fu_device_get_specialized_gtype (FU_DEVICE (device)); |
Richard Hughes | 989acf1 | 2019-10-05 20:16:47 +0100 | [diff] [blame] | 1857 | g_autoptr(FuDevice) dev = NULL; |
| 1858 | g_autoptr(FuDeviceLocker) locker = NULL; |
Richard Hughes | d8a8d5e | 2019-10-08 13:05:02 +0100 | [diff] [blame] | 1859 | |
| 1860 | /* fall back to plugin default */ |
| 1861 | if (device_gtype == G_TYPE_INVALID) |
| 1862 | device_gtype = priv->device_gtype; |
| 1863 | |
| 1864 | /* create new device and incorporate existing properties */ |
| 1865 | dev = g_object_new (device_gtype, NULL); |
| 1866 | fu_device_incorporate (dev, FU_DEVICE (device)); |
Richard Hughes | 0f66a02 | 2020-02-19 18:54:38 +0000 | [diff] [blame] | 1867 | if (!fu_plugin_runner_device_created (self, dev, error)) |
| 1868 | return FALSE; |
Richard Hughes | d8a8d5e | 2019-10-08 13:05:02 +0100 | [diff] [blame] | 1869 | |
| 1870 | /* there are a lot of different devices that match, but not all respond |
| 1871 | * well to opening -- so limit some ones with issued updates */ |
Richard Hughes | cf10029 | 2021-01-04 10:36:37 +0000 | [diff] [blame] | 1872 | if (fu_device_has_internal_flag (dev, FU_DEVICE_INTERNAL_FLAG_ONLY_SUPPORTED)) { |
Richard Hughes | d8a8d5e | 2019-10-08 13:05:02 +0100 | [diff] [blame] | 1873 | if (!fu_device_probe (dev, error)) |
| 1874 | return FALSE; |
| 1875 | fu_device_convert_instance_ids (dev); |
| 1876 | if (!fu_plugin_check_supported_device (self, dev)) { |
| 1877 | g_autofree gchar *guids = fu_device_get_guids_as_str (dev); |
| 1878 | g_debug ("%s has no updates, so ignoring device", guids); |
| 1879 | return TRUE; |
| 1880 | } |
| 1881 | } |
| 1882 | |
| 1883 | /* open and add */ |
| 1884 | locker = fu_device_locker_new (dev, error); |
| 1885 | if (locker == NULL) |
| 1886 | return FALSE; |
| 1887 | fu_plugin_device_add (self, dev); |
Richard Hughes | 6a07870 | 2020-05-09 20:36:33 +0100 | [diff] [blame] | 1888 | fu_plugin_runner_device_added (self, dev); |
Richard Hughes | d8a8d5e | 2019-10-08 13:05:02 +0100 | [diff] [blame] | 1889 | return TRUE; |
| 1890 | } |
| 1891 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1892 | /** |
| 1893 | * fu_plugin_runner_usb_device_added: |
| 1894 | * @self: a #FuPlugin |
| 1895 | * @device: a #FuUsbDevice |
| 1896 | * @error: a #GError or NULL |
| 1897 | * |
Richard Hughes | 525f71f | 2021-02-09 14:52:47 +0000 | [diff] [blame] | 1898 | * Call the backend_device_added routine for the plugin |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1899 | * |
| 1900 | * Returns: #TRUE for success, #FALSE for failure |
| 1901 | * |
| 1902 | * Since: 1.0.2 |
| 1903 | **/ |
Richard Hughes | 104f651 | 2017-11-24 11:44:57 +0000 | [diff] [blame] | 1904 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1905 | fu_plugin_runner_usb_device_added (FuPlugin *self, FuUsbDevice *device, GError **error) |
Richard Hughes | 104f651 | 2017-11-24 11:44:57 +0000 | [diff] [blame] | 1906 | { |
Richard Hughes | 525f71f | 2021-02-09 14:52:47 +0000 | [diff] [blame] | 1907 | return fu_plugin_runner_backend_device_added (self, FU_DEVICE (device), error); |
Richard Hughes | 104f651 | 2017-11-24 11:44:57 +0000 | [diff] [blame] | 1908 | } |
| 1909 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1910 | /** |
| 1911 | * fu_plugin_runner_udev_device_added: |
| 1912 | * @self: a #FuPlugin |
| 1913 | * @device: a #FuUdevDevice |
| 1914 | * @error: a #GError or NULL |
| 1915 | * |
Richard Hughes | 525f71f | 2021-02-09 14:52:47 +0000 | [diff] [blame] | 1916 | * Call the backend_device_added routine for the plugin |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1917 | * |
| 1918 | * Returns: #TRUE for success, #FALSE for failure |
| 1919 | * |
| 1920 | * Since: 1.0.2 |
| 1921 | **/ |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 1922 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1923 | fu_plugin_runner_udev_device_added (FuPlugin *self, FuUdevDevice *device, GError **error) |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 1924 | { |
Richard Hughes | 525f71f | 2021-02-09 14:52:47 +0000 | [diff] [blame] | 1925 | return fu_plugin_runner_backend_device_added (self, FU_DEVICE (device), error); |
| 1926 | } |
| 1927 | |
| 1928 | /** |
| 1929 | * fu_plugin_runner_backend_device_added: |
| 1930 | * @self: a #FuPlugin |
| 1931 | * @device: a #FuDevice |
| 1932 | * @error: a #GError or NULL |
| 1933 | * |
| 1934 | * Call the backend_device_added routine for the plugin |
| 1935 | * |
| 1936 | * Returns: #TRUE for success, #FALSE for failure |
| 1937 | * |
| 1938 | * Since: 1.5.6 |
| 1939 | **/ |
| 1940 | gboolean |
| 1941 | fu_plugin_runner_backend_device_added (FuPlugin *self, FuDevice *device, GError **error) |
| 1942 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1943 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 525f71f | 2021-02-09 14:52:47 +0000 | [diff] [blame] | 1944 | FuPluginDeviceFunc func = NULL; |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1945 | g_autoptr(GError) error_local = NULL; |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 1946 | |
Richard Hughes | 6a489a9 | 2020-12-22 10:32:06 +0000 | [diff] [blame] | 1947 | g_return_val_if_fail (FU_IS_PLUGIN (self), FALSE); |
Richard Hughes | 525f71f | 2021-02-09 14:52:47 +0000 | [diff] [blame] | 1948 | g_return_val_if_fail (FU_IS_DEVICE (device), FALSE); |
Richard Hughes | 6a489a9 | 2020-12-22 10:32:06 +0000 | [diff] [blame] | 1949 | g_return_val_if_fail (error == NULL || *error == NULL, FALSE); |
| 1950 | |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 1951 | /* not enabled */ |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1952 | if (fu_plugin_has_flag (self, FWUPD_PLUGIN_FLAG_DISABLED)) |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 1953 | return TRUE; |
| 1954 | |
| 1955 | /* no object loaded */ |
| 1956 | if (priv->module == NULL) |
| 1957 | return TRUE; |
| 1958 | |
| 1959 | /* optional */ |
Richard Hughes | 525f71f | 2021-02-09 14:52:47 +0000 | [diff] [blame] | 1960 | g_module_symbol (priv->module, "fu_plugin_backend_device_added", (gpointer *) &func); |
Richard Hughes | d8a8d5e | 2019-10-08 13:05:02 +0100 | [diff] [blame] | 1961 | if (func == NULL) { |
| 1962 | if (priv->device_gtype != G_TYPE_INVALID || |
Richard Hughes | 525f71f | 2021-02-09 14:52:47 +0000 | [diff] [blame] | 1963 | fu_device_get_specialized_gtype (device) != G_TYPE_INVALID) { |
| 1964 | return fu_plugin_backend_device_added (self, device, error); |
Richard Hughes | d8a8d5e | 2019-10-08 13:05:02 +0100 | [diff] [blame] | 1965 | } |
Richard Hughes | a21e025 | 2020-12-01 12:21:33 +0000 | [diff] [blame] | 1966 | g_set_error_literal (error, |
| 1967 | FWUPD_ERROR, |
| 1968 | FWUPD_ERROR_INTERNAL, |
| 1969 | "No device GType set"); |
| 1970 | return FALSE; |
Richard Hughes | d8a8d5e | 2019-10-08 13:05:02 +0100 | [diff] [blame] | 1971 | } |
Richard Hughes | 525f71f | 2021-02-09 14:52:47 +0000 | [diff] [blame] | 1972 | g_debug ("backend_device_added(%s)", fu_plugin_get_name (self)); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1973 | if (!func (self, device, &error_local)) { |
| 1974 | if (error_local == NULL) { |
Richard Hughes | 525f71f | 2021-02-09 14:52:47 +0000 | [diff] [blame] | 1975 | g_critical ("unset plugin error in backend_device_added(%s)", |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1976 | fu_plugin_get_name (self)); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1977 | g_set_error_literal (&error_local, |
| 1978 | FWUPD_ERROR, |
| 1979 | FWUPD_ERROR_INTERNAL, |
| 1980 | "unspecified error"); |
| 1981 | } |
| 1982 | g_propagate_prefixed_error (error, g_steal_pointer (&error_local), |
| 1983 | "failed to add device using on %s: ", |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1984 | fu_plugin_get_name (self)); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1985 | return FALSE; |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 1986 | } |
| 1987 | return TRUE; |
| 1988 | } |
| 1989 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1990 | /** |
| 1991 | * fu_plugin_runner_udev_device_changed: |
| 1992 | * @self: a #FuPlugin |
| 1993 | * @device: a #FuUdevDevice |
| 1994 | * @error: a #GError or NULL |
| 1995 | * |
Richard Hughes | 525f71f | 2021-02-09 14:52:47 +0000 | [diff] [blame] | 1996 | * Call the backend_device_changed routine for the plugin |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1997 | * |
| 1998 | * Returns: #TRUE for success, #FALSE for failure |
| 1999 | * |
| 2000 | * Since: 1.0.2 |
| 2001 | **/ |
Richard Hughes | 5e952ce | 2019-08-26 11:09:46 +0100 | [diff] [blame] | 2002 | gboolean |
| 2003 | fu_plugin_runner_udev_device_changed (FuPlugin *self, FuUdevDevice *device, GError **error) |
| 2004 | { |
Richard Hughes | 525f71f | 2021-02-09 14:52:47 +0000 | [diff] [blame] | 2005 | return fu_plugin_runner_backend_device_changed (self, FU_DEVICE (device), error); |
| 2006 | } |
| 2007 | |
| 2008 | /** |
| 2009 | * fu_plugin_runner_backend_device_changed: |
| 2010 | * @self: a #FuPlugin |
| 2011 | * @device: a #FuDevice |
| 2012 | * @error: a #GError or NULL |
| 2013 | * |
| 2014 | * Call the backend_device_changed routine for the plugin |
| 2015 | * |
| 2016 | * Returns: #TRUE for success, #FALSE for failure |
| 2017 | * |
| 2018 | * Since: 1.5.6 |
| 2019 | **/ |
| 2020 | gboolean |
| 2021 | fu_plugin_runner_backend_device_changed (FuPlugin *self, FuDevice *device, GError **error) |
| 2022 | { |
Richard Hughes | 5e952ce | 2019-08-26 11:09:46 +0100 | [diff] [blame] | 2023 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 525f71f | 2021-02-09 14:52:47 +0000 | [diff] [blame] | 2024 | FuPluginDeviceFunc func = NULL; |
Richard Hughes | 5e952ce | 2019-08-26 11:09:46 +0100 | [diff] [blame] | 2025 | g_autoptr(GError) error_local = NULL; |
| 2026 | |
Richard Hughes | 6a489a9 | 2020-12-22 10:32:06 +0000 | [diff] [blame] | 2027 | g_return_val_if_fail (FU_IS_PLUGIN (self), FALSE); |
Richard Hughes | 525f71f | 2021-02-09 14:52:47 +0000 | [diff] [blame] | 2028 | g_return_val_if_fail (FU_IS_DEVICE (device), FALSE); |
Richard Hughes | 6a489a9 | 2020-12-22 10:32:06 +0000 | [diff] [blame] | 2029 | g_return_val_if_fail (error == NULL || *error == NULL, FALSE); |
| 2030 | |
Richard Hughes | 5e952ce | 2019-08-26 11:09:46 +0100 | [diff] [blame] | 2031 | /* not enabled */ |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 2032 | if (fu_plugin_has_flag (self, FWUPD_PLUGIN_FLAG_DISABLED)) |
Richard Hughes | 5e952ce | 2019-08-26 11:09:46 +0100 | [diff] [blame] | 2033 | return TRUE; |
| 2034 | |
| 2035 | /* no object loaded */ |
| 2036 | if (priv->module == NULL) |
| 2037 | return TRUE; |
| 2038 | |
| 2039 | /* optional */ |
Richard Hughes | 525f71f | 2021-02-09 14:52:47 +0000 | [diff] [blame] | 2040 | g_module_symbol (priv->module, "fu_plugin_backend_device_changed", (gpointer *) &func); |
Mario Limonciello | 6d23514 | 2020-09-10 21:35:17 -0500 | [diff] [blame] | 2041 | if (func == NULL) |
Richard Hughes | 5e952ce | 2019-08-26 11:09:46 +0100 | [diff] [blame] | 2042 | return TRUE; |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 2043 | g_debug ("udev_device_changed(%s)", fu_plugin_get_name (self)); |
Richard Hughes | 5e952ce | 2019-08-26 11:09:46 +0100 | [diff] [blame] | 2044 | if (!func (self, device, &error_local)) { |
| 2045 | if (error_local == NULL) { |
Mario Limonciello | 67a8b89 | 2020-09-28 13:44:39 -0500 | [diff] [blame] | 2046 | g_critical ("unset plugin error in udev_device_changed(%s)", |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 2047 | fu_plugin_get_name (self)); |
Richard Hughes | 5e952ce | 2019-08-26 11:09:46 +0100 | [diff] [blame] | 2048 | g_set_error_literal (&error_local, |
| 2049 | FWUPD_ERROR, |
| 2050 | FWUPD_ERROR_INTERNAL, |
| 2051 | "unspecified error"); |
| 2052 | } |
| 2053 | g_propagate_prefixed_error (error, g_steal_pointer (&error_local), |
| 2054 | "failed to change device on %s: ", |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 2055 | fu_plugin_get_name (self)); |
Richard Hughes | 5e952ce | 2019-08-26 11:09:46 +0100 | [diff] [blame] | 2056 | return FALSE; |
| 2057 | } |
| 2058 | return TRUE; |
| 2059 | } |
| 2060 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 2061 | /** |
Richard Hughes | 6a07870 | 2020-05-09 20:36:33 +0100 | [diff] [blame] | 2062 | * fu_plugin_runner_device_added: |
| 2063 | * @self: a #FuPlugin |
| 2064 | * @device: a #FuDevice |
| 2065 | * |
| 2066 | * Call the device_added routine for the plugin |
| 2067 | * |
| 2068 | * Since: 1.5.0 |
| 2069 | **/ |
| 2070 | void |
| 2071 | fu_plugin_runner_device_added (FuPlugin *self, FuDevice *device) |
| 2072 | { |
| 2073 | FuPluginPrivate *priv = GET_PRIVATE (self); |
| 2074 | FuPluginDeviceRegisterFunc func = NULL; |
| 2075 | |
| 2076 | /* not enabled */ |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 2077 | if (fu_plugin_has_flag (self, FWUPD_PLUGIN_FLAG_DISABLED)) |
Richard Hughes | 6a07870 | 2020-05-09 20:36:33 +0100 | [diff] [blame] | 2078 | return; |
| 2079 | if (priv->module == NULL) |
| 2080 | return; |
| 2081 | |
| 2082 | /* optional */ |
| 2083 | g_module_symbol (priv->module, "fu_plugin_device_added", (gpointer *) &func); |
| 2084 | if (func == NULL) |
| 2085 | return; |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 2086 | g_debug ("fu_plugin_device_added(%s)", fu_plugin_get_name (self)); |
Richard Hughes | 6a07870 | 2020-05-09 20:36:33 +0100 | [diff] [blame] | 2087 | func (self, device); |
| 2088 | } |
| 2089 | |
| 2090 | /** |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 2091 | * fu_plugin_runner_device_removed: |
| 2092 | * @self: a #FuPlugin |
| 2093 | * @device: a #FuDevice |
| 2094 | * |
| 2095 | * Call the device_removed routine for the plugin |
| 2096 | * |
| 2097 | * Since: 1.1.2 |
| 2098 | **/ |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 2099 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2100 | fu_plugin_runner_device_removed (FuPlugin *self, FuDevice *device) |
Mario Limonciello | e260ead | 2018-09-01 09:19:24 -0500 | [diff] [blame] | 2101 | { |
| 2102 | g_autoptr(GError) error_local= NULL; |
| 2103 | |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2104 | if (!fu_plugin_runner_device_generic (self, device, |
Richard Hughes | 525f71f | 2021-02-09 14:52:47 +0000 | [diff] [blame] | 2105 | "fu_plugin_backend_device_removed", |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 2106 | NULL, |
Mario Limonciello | e260ead | 2018-09-01 09:19:24 -0500 | [diff] [blame] | 2107 | &error_local)) |
| 2108 | g_warning ("%s", error_local->message); |
| 2109 | } |
| 2110 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 2111 | /** |
| 2112 | * fu_plugin_runner_device_register: |
| 2113 | * @self: a #FuPlugin |
| 2114 | * @device: a #FuDevice |
| 2115 | * |
| 2116 | * Call the device_registered routine for the plugin |
| 2117 | * |
| 2118 | * Since: 0.9.7 |
| 2119 | **/ |
Mario Limonciello | e260ead | 2018-09-01 09:19:24 -0500 | [diff] [blame] | 2120 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2121 | fu_plugin_runner_device_register (FuPlugin *self, FuDevice *device) |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 2122 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2123 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 2124 | FuPluginDeviceRegisterFunc func = NULL; |
| 2125 | |
| 2126 | /* not enabled */ |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 2127 | if (fu_plugin_has_flag (self, FWUPD_PLUGIN_FLAG_DISABLED)) |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 2128 | return; |
Richard Hughes | 3483410 | 2017-11-21 21:55:00 +0000 | [diff] [blame] | 2129 | if (priv->module == NULL) |
| 2130 | return; |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 2131 | |
| 2132 | /* optional */ |
| 2133 | g_module_symbol (priv->module, "fu_plugin_device_registered", (gpointer *) &func); |
| 2134 | if (func != NULL) { |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 2135 | g_debug ("fu_plugin_device_registered(%s)", fu_plugin_get_name (self)); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2136 | func (self, device); |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 2137 | } |
| 2138 | } |
| 2139 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 2140 | /** |
Richard Hughes | 0f66a02 | 2020-02-19 18:54:38 +0000 | [diff] [blame] | 2141 | * fu_plugin_runner_device_created: |
| 2142 | * @self: a #FuPlugin |
| 2143 | * @device: a #FuDevice |
| 2144 | * @error: a #GError or NULL |
| 2145 | * |
| 2146 | * Call the device_created routine for the plugin |
| 2147 | * |
| 2148 | * Returns: #TRUE for success, #FALSE for failure |
| 2149 | * |
Mario Limonciello | 96117d1 | 2020-02-28 10:17:56 -0600 | [diff] [blame] | 2150 | * Since: 1.4.0 |
Richard Hughes | 0f66a02 | 2020-02-19 18:54:38 +0000 | [diff] [blame] | 2151 | **/ |
| 2152 | gboolean |
| 2153 | fu_plugin_runner_device_created (FuPlugin *self, FuDevice *device, GError **error) |
| 2154 | { |
| 2155 | FuPluginPrivate *priv = GET_PRIVATE (self); |
| 2156 | FuPluginDeviceFunc func = NULL; |
| 2157 | |
Richard Hughes | 6a489a9 | 2020-12-22 10:32:06 +0000 | [diff] [blame] | 2158 | g_return_val_if_fail (FU_IS_PLUGIN (self), FALSE); |
| 2159 | g_return_val_if_fail (FU_IS_DEVICE (device), FALSE); |
| 2160 | g_return_val_if_fail (error == NULL || *error == NULL, FALSE); |
| 2161 | |
Richard Hughes | 0f66a02 | 2020-02-19 18:54:38 +0000 | [diff] [blame] | 2162 | /* not enabled */ |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 2163 | if (fu_plugin_has_flag (self, FWUPD_PLUGIN_FLAG_DISABLED)) |
Richard Hughes | 0f66a02 | 2020-02-19 18:54:38 +0000 | [diff] [blame] | 2164 | return TRUE; |
| 2165 | if (priv->module == NULL) |
| 2166 | return TRUE; |
| 2167 | |
| 2168 | /* optional */ |
| 2169 | g_module_symbol (priv->module, "fu_plugin_device_created", (gpointer *) &func); |
| 2170 | if (func == NULL) |
| 2171 | return TRUE; |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 2172 | g_debug ("fu_plugin_device_created(%s)", fu_plugin_get_name (self)); |
Richard Hughes | 0f66a02 | 2020-02-19 18:54:38 +0000 | [diff] [blame] | 2173 | return func (self, device, error); |
| 2174 | } |
| 2175 | |
| 2176 | /** |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 2177 | * fu_plugin_runner_verify: |
| 2178 | * @self: a #FuPlugin |
| 2179 | * @device: a #FuDevice |
| 2180 | * @flags: #FuPluginVerifyFlags |
| 2181 | * @error: A #GError or NULL |
| 2182 | * |
| 2183 | * Call into the plugin's verify routine |
| 2184 | * |
| 2185 | * Returns: #TRUE for success, #FALSE for failure |
| 2186 | * |
| 2187 | * Since: 0.8.0 |
| 2188 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2189 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2190 | fu_plugin_runner_verify (FuPlugin *self, |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2191 | FuDevice *device, |
| 2192 | FuPluginVerifyFlags flags, |
| 2193 | GError **error) |
| 2194 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2195 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 2196 | FuPluginVerifyFunc func = NULL; |
Richard Hughes | ababbb7 | 2017-06-15 20:18:36 +0100 | [diff] [blame] | 2197 | GPtrArray *checksums; |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 2198 | g_autoptr(GError) error_local = NULL; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2199 | |
Richard Hughes | 6a489a9 | 2020-12-22 10:32:06 +0000 | [diff] [blame] | 2200 | g_return_val_if_fail (FU_IS_PLUGIN (self), FALSE); |
| 2201 | g_return_val_if_fail (FU_IS_DEVICE (device), FALSE); |
| 2202 | g_return_val_if_fail (error == NULL || *error == NULL, FALSE); |
| 2203 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2204 | /* not enabled */ |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 2205 | if (fu_plugin_has_flag (self, FWUPD_PLUGIN_FLAG_DISABLED)) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2206 | return TRUE; |
| 2207 | |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 2208 | /* no object loaded */ |
| 2209 | if (priv->module == NULL) |
| 2210 | return TRUE; |
| 2211 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2212 | /* optional */ |
| 2213 | g_module_symbol (priv->module, "fu_plugin_verify", (gpointer *) &func); |
Richard Hughes | 7f67721 | 2019-10-05 16:19:40 +0100 | [diff] [blame] | 2214 | if (func == NULL) { |
Richard Hughes | 7f67721 | 2019-10-05 16:19:40 +0100 | [diff] [blame] | 2215 | return fu_plugin_device_read_firmware (self, device, error); |
| 2216 | } |
Richard Hughes | 1812fc7 | 2018-12-14 11:37:54 +0000 | [diff] [blame] | 2217 | |
| 2218 | /* clear any existing verification checksums */ |
| 2219 | checksums = fu_device_get_checksums (device); |
| 2220 | g_ptr_array_set_size (checksums, 0); |
| 2221 | |
Richard Hughes | c9223be | 2019-03-18 08:46:42 +0000 | [diff] [blame] | 2222 | /* run additional detach */ |
| 2223 | if (!fu_plugin_runner_device_generic (self, device, |
Richard Hughes | 42f33df | 2019-10-05 20:52:33 +0100 | [diff] [blame] | 2224 | "fu_plugin_update_detach", |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 2225 | fu_plugin_device_detach, |
Richard Hughes | c9223be | 2019-03-18 08:46:42 +0000 | [diff] [blame] | 2226 | error)) |
| 2227 | return FALSE; |
| 2228 | |
Richard Hughes | 1812fc7 | 2018-12-14 11:37:54 +0000 | [diff] [blame] | 2229 | /* run vfunc */ |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 2230 | g_debug ("verify(%s)", fu_plugin_get_name (self)); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 2231 | if (!func (self, device, flags, &error_local)) { |
Richard Hughes | c9223be | 2019-03-18 08:46:42 +0000 | [diff] [blame] | 2232 | g_autoptr(GError) error_attach = NULL; |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 2233 | if (error_local == NULL) { |
Mario Limonciello | 67a8b89 | 2020-09-28 13:44:39 -0500 | [diff] [blame] | 2234 | g_critical ("unset plugin error in verify(%s)", |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 2235 | fu_plugin_get_name (self)); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 2236 | g_set_error_literal (&error_local, |
| 2237 | FWUPD_ERROR, |
| 2238 | FWUPD_ERROR_INTERNAL, |
| 2239 | "unspecified error"); |
| 2240 | } |
| 2241 | g_propagate_prefixed_error (error, g_steal_pointer (&error_local), |
| 2242 | "failed to verify using %s: ", |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 2243 | fu_plugin_get_name (self)); |
Richard Hughes | c9223be | 2019-03-18 08:46:42 +0000 | [diff] [blame] | 2244 | /* make the device "work" again, but don't prefix the error */ |
| 2245 | if (!fu_plugin_runner_device_generic (self, device, |
Richard Hughes | 42f33df | 2019-10-05 20:52:33 +0100 | [diff] [blame] | 2246 | "fu_plugin_update_attach", |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 2247 | fu_plugin_device_attach, |
Richard Hughes | c9223be | 2019-03-18 08:46:42 +0000 | [diff] [blame] | 2248 | &error_attach)) { |
| 2249 | g_warning ("failed to attach whilst aborting verify(): %s", |
| 2250 | error_attach->message); |
| 2251 | } |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 2252 | return FALSE; |
| 2253 | } |
Richard Hughes | c9223be | 2019-03-18 08:46:42 +0000 | [diff] [blame] | 2254 | |
| 2255 | /* run optional attach */ |
| 2256 | if (!fu_plugin_runner_device_generic (self, device, |
Richard Hughes | 42f33df | 2019-10-05 20:52:33 +0100 | [diff] [blame] | 2257 | "fu_plugin_update_attach", |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 2258 | fu_plugin_device_attach, |
Richard Hughes | c9223be | 2019-03-18 08:46:42 +0000 | [diff] [blame] | 2259 | error)) |
| 2260 | return FALSE; |
| 2261 | |
| 2262 | /* success */ |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 2263 | return TRUE; |
| 2264 | } |
| 2265 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 2266 | /** |
| 2267 | * fu_plugin_runner_activate: |
| 2268 | * @self: a #FuPlugin |
| 2269 | * @device: a #FuDevice |
| 2270 | * @error: A #GError or NULL |
| 2271 | * |
| 2272 | * Call into the plugin's activate routine |
| 2273 | * |
| 2274 | * Returns: #TRUE for success, #FALSE for failure |
| 2275 | * |
| 2276 | * Since: 1.2.6 |
| 2277 | **/ |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 2278 | gboolean |
Mario Limonciello | 96a0dd5 | 2019-02-25 13:50:03 -0600 | [diff] [blame] | 2279 | fu_plugin_runner_activate (FuPlugin *self, FuDevice *device, GError **error) |
| 2280 | { |
| 2281 | guint64 flags; |
| 2282 | |
Richard Hughes | 6a489a9 | 2020-12-22 10:32:06 +0000 | [diff] [blame] | 2283 | g_return_val_if_fail (FU_IS_PLUGIN (self), FALSE); |
| 2284 | g_return_val_if_fail (FU_IS_DEVICE (device), FALSE); |
| 2285 | g_return_val_if_fail (error == NULL || *error == NULL, FALSE); |
| 2286 | |
Mario Limonciello | 96a0dd5 | 2019-02-25 13:50:03 -0600 | [diff] [blame] | 2287 | /* final check */ |
| 2288 | flags = fu_device_get_flags (device); |
| 2289 | if ((flags & FWUPD_DEVICE_FLAG_NEEDS_ACTIVATION) == 0) { |
| 2290 | g_set_error (error, |
| 2291 | FWUPD_ERROR, |
| 2292 | FWUPD_ERROR_NOT_SUPPORTED, |
| 2293 | "Device %s does not need activation", |
| 2294 | fu_device_get_id (device)); |
| 2295 | return FALSE; |
| 2296 | } |
| 2297 | |
| 2298 | /* run vfunc */ |
| 2299 | if (!fu_plugin_runner_device_generic (self, device, |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 2300 | "fu_plugin_activate", |
| 2301 | fu_plugin_device_activate, |
| 2302 | error)) |
Mario Limonciello | 96a0dd5 | 2019-02-25 13:50:03 -0600 | [diff] [blame] | 2303 | return FALSE; |
| 2304 | |
| 2305 | /* update with correct flags */ |
| 2306 | fu_device_remove_flag (device, FWUPD_DEVICE_FLAG_NEEDS_ACTIVATION); |
| 2307 | fu_device_set_modified (device, (guint64) g_get_real_time () / G_USEC_PER_SEC); |
| 2308 | return TRUE; |
| 2309 | } |
| 2310 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 2311 | /** |
| 2312 | * fu_plugin_runner_unlock: |
| 2313 | * @self: a #FuPlugin |
| 2314 | * @device: a #FuDevice |
| 2315 | * @error: A #GError or NULL |
| 2316 | * |
| 2317 | * Call into the plugin's unlock routine |
| 2318 | * |
| 2319 | * Returns: #TRUE for success, #FALSE for failure |
| 2320 | * |
| 2321 | * Since: 0.8.0 |
| 2322 | **/ |
Mario Limonciello | 96a0dd5 | 2019-02-25 13:50:03 -0600 | [diff] [blame] | 2323 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2324 | fu_plugin_runner_unlock (FuPlugin *self, FuDevice *device, GError **error) |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 2325 | { |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2326 | guint64 flags; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2327 | |
Richard Hughes | 6a489a9 | 2020-12-22 10:32:06 +0000 | [diff] [blame] | 2328 | g_return_val_if_fail (FU_IS_PLUGIN (self), FALSE); |
| 2329 | g_return_val_if_fail (FU_IS_DEVICE (device), FALSE); |
| 2330 | g_return_val_if_fail (error == NULL || *error == NULL, FALSE); |
| 2331 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2332 | /* final check */ |
| 2333 | flags = fu_device_get_flags (device); |
| 2334 | if ((flags & FWUPD_DEVICE_FLAG_LOCKED) == 0) { |
| 2335 | g_set_error (error, |
| 2336 | FWUPD_ERROR, |
| 2337 | FWUPD_ERROR_NOT_SUPPORTED, |
| 2338 | "Device %s is not locked", |
| 2339 | fu_device_get_id (device)); |
| 2340 | return FALSE; |
| 2341 | } |
| 2342 | |
Richard Hughes | 9c4b531 | 2017-11-14 11:34:53 +0000 | [diff] [blame] | 2343 | /* run vfunc */ |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2344 | if (!fu_plugin_runner_device_generic (self, device, |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 2345 | "fu_plugin_unlock", |
| 2346 | NULL, |
| 2347 | error)) |
Richard Hughes | 9c4b531 | 2017-11-14 11:34:53 +0000 | [diff] [blame] | 2348 | return FALSE; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2349 | |
| 2350 | /* update with correct flags */ |
Richard Hughes | ed0af24 | 2021-02-22 21:27:16 +0000 | [diff] [blame^] | 2351 | fu_device_remove_flag (device, FWUPD_DEVICE_FLAG_LOCKED); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2352 | fu_device_set_modified (device, (guint64) g_get_real_time () / G_USEC_PER_SEC); |
| 2353 | return TRUE; |
| 2354 | } |
| 2355 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 2356 | /** |
| 2357 | * fu_plugin_runner_update: |
| 2358 | * @self: a #FuPlugin |
| 2359 | * @device: a #FuDevice |
| 2360 | * @blob_fw: A #GBytes |
| 2361 | * @flags: A #FwupdInstallFlags |
| 2362 | * @error: A #GError or NULL |
| 2363 | * |
| 2364 | * Call into the plugin's update routine |
| 2365 | * |
| 2366 | * Returns: #TRUE for success, #FALSE for failure |
| 2367 | * |
| 2368 | * Since: 0.8.0 |
| 2369 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2370 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2371 | fu_plugin_runner_update (FuPlugin *self, |
Richard Hughes | a785a1c | 2017-08-25 16:00:58 +0100 | [diff] [blame] | 2372 | FuDevice *device, |
Richard Hughes | a785a1c | 2017-08-25 16:00:58 +0100 | [diff] [blame] | 2373 | GBytes *blob_fw, |
| 2374 | FwupdInstallFlags flags, |
| 2375 | GError **error) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2376 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2377 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | a785a1c | 2017-08-25 16:00:58 +0100 | [diff] [blame] | 2378 | FuPluginUpdateFunc update_func; |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 2379 | g_autoptr(GError) error_local = NULL; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2380 | |
Richard Hughes | 6a489a9 | 2020-12-22 10:32:06 +0000 | [diff] [blame] | 2381 | g_return_val_if_fail (FU_IS_PLUGIN (self), FALSE); |
| 2382 | g_return_val_if_fail (FU_IS_DEVICE (device), FALSE); |
| 2383 | g_return_val_if_fail (error == NULL || *error == NULL, FALSE); |
| 2384 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2385 | /* not enabled */ |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 2386 | if (fu_plugin_has_flag (self, FWUPD_PLUGIN_FLAG_DISABLED)) { |
Richard Hughes | 41c1548 | 2018-02-01 22:07:21 +0000 | [diff] [blame] | 2387 | g_debug ("plugin not enabled, skipping"); |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 2388 | return TRUE; |
Richard Hughes | 41c1548 | 2018-02-01 22:07:21 +0000 | [diff] [blame] | 2389 | } |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 2390 | |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 2391 | /* no object loaded */ |
Richard Hughes | 41c1548 | 2018-02-01 22:07:21 +0000 | [diff] [blame] | 2392 | if (priv->module == NULL) { |
| 2393 | g_debug ("module not enabled, skipping"); |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 2394 | return TRUE; |
Richard Hughes | 41c1548 | 2018-02-01 22:07:21 +0000 | [diff] [blame] | 2395 | } |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 2396 | |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 2397 | /* optional */ |
Richard Hughes | a785a1c | 2017-08-25 16:00:58 +0100 | [diff] [blame] | 2398 | g_module_symbol (priv->module, "fu_plugin_update", (gpointer *) &update_func); |
| 2399 | if (update_func == NULL) { |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 2400 | g_debug ("superclassed write_firmware(%s)", fu_plugin_get_name (self)); |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 2401 | return fu_plugin_device_write_firmware (self, device, blob_fw, flags, error); |
Richard Hughes | a785a1c | 2017-08-25 16:00:58 +0100 | [diff] [blame] | 2402 | } |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 2403 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2404 | /* online */ |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 2405 | if (!update_func (self, device, blob_fw, flags, &error_local)) { |
| 2406 | if (error_local == NULL) { |
Mario Limonciello | 67a8b89 | 2020-09-28 13:44:39 -0500 | [diff] [blame] | 2407 | g_critical ("unset plugin error in update(%s)", |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 2408 | fu_plugin_get_name (self)); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 2409 | g_set_error_literal (&error_local, |
Richard Hughes | 3c8ada3 | 2018-10-12 10:08:58 +0100 | [diff] [blame] | 2410 | FWUPD_ERROR, |
| 2411 | FWUPD_ERROR_INTERNAL, |
| 2412 | "unspecified error"); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 2413 | return FALSE; |
Richard Hughes | 3c8ada3 | 2018-10-12 10:08:58 +0100 | [diff] [blame] | 2414 | } |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 2415 | fu_device_set_update_error (device, error_local->message); |
| 2416 | g_propagate_error (error, g_steal_pointer (&error_local)); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2417 | return FALSE; |
| 2418 | } |
| 2419 | |
Richard Hughes | f556d37 | 2017-06-15 19:49:18 +0100 | [diff] [blame] | 2420 | /* no longer valid */ |
Richard Hughes | f803964 | 2019-01-16 12:22:22 +0000 | [diff] [blame] | 2421 | if (!fu_device_has_flag (device, FWUPD_DEVICE_FLAG_NEEDS_REBOOT) && |
| 2422 | !fu_device_has_flag (device, FWUPD_DEVICE_FLAG_NEEDS_SHUTDOWN)) { |
Richard Hughes | 0843516 | 2018-12-12 10:34:16 +0000 | [diff] [blame] | 2423 | GPtrArray *checksums = fu_device_get_checksums (device); |
| 2424 | g_ptr_array_set_size (checksums, 0); |
| 2425 | } |
Richard Hughes | f556d37 | 2017-06-15 19:49:18 +0100 | [diff] [blame] | 2426 | |
Richard Hughes | 019a1bc | 2019-11-26 10:19:33 +0000 | [diff] [blame] | 2427 | /* success */ |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 2428 | return TRUE; |
| 2429 | } |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2430 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 2431 | /** |
| 2432 | * fu_plugin_runner_clear_results: |
| 2433 | * @self: a #FuPlugin |
| 2434 | * @device: a #FuDevice |
| 2435 | * @error: A #GError or NULL |
| 2436 | * |
| 2437 | * Call into the plugin's clear results routine |
| 2438 | * |
| 2439 | * Returns: #TRUE for success, #FALSE for failure |
| 2440 | * |
| 2441 | * Since: 0.8.0 |
| 2442 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2443 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2444 | fu_plugin_runner_clear_results (FuPlugin *self, FuDevice *device, GError **error) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2445 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2446 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 2447 | FuPluginDeviceFunc func = NULL; |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 2448 | g_autoptr(GError) error_local = NULL; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2449 | |
Richard Hughes | 6a489a9 | 2020-12-22 10:32:06 +0000 | [diff] [blame] | 2450 | g_return_val_if_fail (FU_IS_PLUGIN (self), FALSE); |
| 2451 | g_return_val_if_fail (FU_IS_DEVICE (device), FALSE); |
| 2452 | g_return_val_if_fail (error == NULL || *error == NULL, FALSE); |
| 2453 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2454 | /* not enabled */ |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 2455 | if (fu_plugin_has_flag (self, FWUPD_PLUGIN_FLAG_DISABLED)) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2456 | return TRUE; |
| 2457 | |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 2458 | /* no object loaded */ |
| 2459 | if (priv->module == NULL) |
| 2460 | return TRUE; |
| 2461 | |
Richard Hughes | 65e44ca | 2018-01-30 17:26:30 +0000 | [diff] [blame] | 2462 | /* optional */ |
Richard Hughes | cd64490 | 2019-11-01 12:35:17 +0000 | [diff] [blame] | 2463 | g_module_symbol (priv->module, "fu_plugin_clear_results", (gpointer *) &func); |
Richard Hughes | 65e44ca | 2018-01-30 17:26:30 +0000 | [diff] [blame] | 2464 | if (func == NULL) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2465 | return TRUE; |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 2466 | g_debug ("clear_result(%s)", fu_plugin_get_name (self)); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 2467 | if (!func (self, device, &error_local)) { |
| 2468 | if (error_local == NULL) { |
Mario Limonciello | 67a8b89 | 2020-09-28 13:44:39 -0500 | [diff] [blame] | 2469 | g_critical ("unset plugin error in clear_result(%s)", |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 2470 | fu_plugin_get_name (self)); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 2471 | g_set_error_literal (&error_local, |
| 2472 | FWUPD_ERROR, |
| 2473 | FWUPD_ERROR_INTERNAL, |
| 2474 | "unspecified error"); |
| 2475 | } |
| 2476 | g_propagate_prefixed_error (error, g_steal_pointer (&error_local), |
| 2477 | "failed to clear_result using %s: ", |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 2478 | fu_plugin_get_name (self)); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2479 | return FALSE; |
| 2480 | } |
Richard Hughes | 65e44ca | 2018-01-30 17:26:30 +0000 | [diff] [blame] | 2481 | return TRUE; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2482 | } |
| 2483 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 2484 | /** |
| 2485 | * fu_plugin_runner_get_results: |
| 2486 | * @self: a #FuPlugin |
| 2487 | * @device: a #FuDevice |
| 2488 | * @error: A #GError or NULL |
| 2489 | * |
| 2490 | * Call into the plugin's get results routine |
| 2491 | * |
| 2492 | * Returns: #TRUE for success, #FALSE for failure |
| 2493 | * |
| 2494 | * Since: 0.8.0 |
| 2495 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2496 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2497 | fu_plugin_runner_get_results (FuPlugin *self, FuDevice *device, GError **error) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2498 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2499 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 2500 | FuPluginDeviceFunc func = NULL; |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 2501 | g_autoptr(GError) error_local = NULL; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2502 | |
Richard Hughes | 6a489a9 | 2020-12-22 10:32:06 +0000 | [diff] [blame] | 2503 | g_return_val_if_fail (FU_IS_PLUGIN (self), FALSE); |
| 2504 | g_return_val_if_fail (FU_IS_DEVICE (device), FALSE); |
| 2505 | g_return_val_if_fail (error == NULL || *error == NULL, FALSE); |
| 2506 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2507 | /* not enabled */ |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 2508 | if (fu_plugin_has_flag (self, FWUPD_PLUGIN_FLAG_DISABLED)) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2509 | return TRUE; |
| 2510 | |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 2511 | /* no object loaded */ |
| 2512 | if (priv->module == NULL) |
| 2513 | return TRUE; |
| 2514 | |
Richard Hughes | 65e44ca | 2018-01-30 17:26:30 +0000 | [diff] [blame] | 2515 | /* optional */ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2516 | g_module_symbol (priv->module, "fu_plugin_get_results", (gpointer *) &func); |
Richard Hughes | 65e44ca | 2018-01-30 17:26:30 +0000 | [diff] [blame] | 2517 | if (func == NULL) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2518 | return TRUE; |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 2519 | g_debug ("get_results(%s)", fu_plugin_get_name (self)); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 2520 | if (!func (self, device, &error_local)) { |
| 2521 | if (error_local == NULL) { |
Mario Limonciello | 67a8b89 | 2020-09-28 13:44:39 -0500 | [diff] [blame] | 2522 | g_critical ("unset plugin error in get_results(%s)", |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 2523 | fu_plugin_get_name (self)); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 2524 | g_set_error_literal (&error_local, |
| 2525 | FWUPD_ERROR, |
| 2526 | FWUPD_ERROR_INTERNAL, |
| 2527 | "unspecified error"); |
| 2528 | } |
| 2529 | g_propagate_prefixed_error (error, g_steal_pointer (&error_local), |
| 2530 | "failed to get_results using %s: ", |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 2531 | fu_plugin_get_name (self)); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2532 | return FALSE; |
| 2533 | } |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2534 | return TRUE; |
| 2535 | } |
| 2536 | |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2537 | /** |
| 2538 | * fu_plugin_get_order: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 2539 | * @self: a #FuPlugin |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2540 | * |
| 2541 | * Gets the plugin order, where higher numbers are run after lower |
| 2542 | * numbers. |
| 2543 | * |
| 2544 | * Returns: the integer value |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 2545 | * |
| 2546 | * Since: 1.0.0 |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2547 | **/ |
| 2548 | guint |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2549 | fu_plugin_get_order (FuPlugin *self) |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2550 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2551 | FuPluginPrivate *priv = fu_plugin_get_instance_private (self); |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2552 | return priv->order; |
| 2553 | } |
| 2554 | |
| 2555 | /** |
| 2556 | * fu_plugin_set_order: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 2557 | * @self: a #FuPlugin |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2558 | * @order: a integer value |
| 2559 | * |
| 2560 | * Sets the plugin order, where higher numbers are run after lower |
| 2561 | * numbers. |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 2562 | * |
| 2563 | * Since: 1.0.0 |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2564 | **/ |
| 2565 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2566 | fu_plugin_set_order (FuPlugin *self, guint order) |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2567 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2568 | FuPluginPrivate *priv = fu_plugin_get_instance_private (self); |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2569 | priv->order = order; |
| 2570 | } |
| 2571 | |
| 2572 | /** |
Richard Hughes | 81c427c | 2018-08-06 15:20:17 +0100 | [diff] [blame] | 2573 | * fu_plugin_get_priority: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 2574 | * @self: a #FuPlugin |
Richard Hughes | 81c427c | 2018-08-06 15:20:17 +0100 | [diff] [blame] | 2575 | * |
| 2576 | * Gets the plugin priority, where higher numbers are better. |
| 2577 | * |
| 2578 | * Returns: the integer value |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 2579 | * |
| 2580 | * Since: 1.1.1 |
Richard Hughes | 81c427c | 2018-08-06 15:20:17 +0100 | [diff] [blame] | 2581 | **/ |
| 2582 | guint |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2583 | fu_plugin_get_priority (FuPlugin *self) |
Richard Hughes | 81c427c | 2018-08-06 15:20:17 +0100 | [diff] [blame] | 2584 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2585 | FuPluginPrivate *priv = fu_plugin_get_instance_private (self); |
Richard Hughes | 81c427c | 2018-08-06 15:20:17 +0100 | [diff] [blame] | 2586 | return priv->priority; |
| 2587 | } |
| 2588 | |
| 2589 | /** |
| 2590 | * fu_plugin_set_priority: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 2591 | * @self: a #FuPlugin |
Richard Hughes | 81c427c | 2018-08-06 15:20:17 +0100 | [diff] [blame] | 2592 | * @priority: a integer value |
| 2593 | * |
| 2594 | * Sets the plugin priority, where higher numbers are better. |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 2595 | * |
| 2596 | * Since: 1.0.0 |
Richard Hughes | 81c427c | 2018-08-06 15:20:17 +0100 | [diff] [blame] | 2597 | **/ |
| 2598 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2599 | fu_plugin_set_priority (FuPlugin *self, guint priority) |
Richard Hughes | 81c427c | 2018-08-06 15:20:17 +0100 | [diff] [blame] | 2600 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2601 | FuPluginPrivate *priv = fu_plugin_get_instance_private (self); |
Richard Hughes | 81c427c | 2018-08-06 15:20:17 +0100 | [diff] [blame] | 2602 | priv->priority = priority; |
| 2603 | } |
| 2604 | |
| 2605 | /** |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2606 | * fu_plugin_add_rule: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 2607 | * @self: a #FuPlugin |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2608 | * @rule: a #FuPluginRule, e.g. %FU_PLUGIN_RULE_CONFLICTS |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 2609 | * @name: a plugin name, e.g. `upower` |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2610 | * |
| 2611 | * If the plugin name is found, the rule will be used to sort the plugin list, |
| 2612 | * for example the plugin specified by @name will be ordered after this plugin |
| 2613 | * when %FU_PLUGIN_RULE_RUN_AFTER is used. |
| 2614 | * |
| 2615 | * NOTE: The depsolver is iterative and may not solve overly-complicated rules; |
| 2616 | * If depsolving fails then fwupd will not start. |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 2617 | * |
| 2618 | * Since: 1.0.0 |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2619 | **/ |
| 2620 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2621 | fu_plugin_add_rule (FuPlugin *self, FuPluginRule rule, const gchar *name) |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2622 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2623 | FuPluginPrivate *priv = fu_plugin_get_instance_private (self); |
Richard Hughes | 11c5941 | 2020-06-22 15:29:48 +0100 | [diff] [blame] | 2624 | if (priv->rules[rule] == NULL) |
| 2625 | priv->rules[rule] = g_ptr_array_new_with_free_func (g_free); |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2626 | g_ptr_array_add (priv->rules[rule], g_strdup (name)); |
Richard Hughes | 75b965d | 2018-11-15 13:51:21 +0000 | [diff] [blame] | 2627 | g_signal_emit (self, signals[SIGNAL_RULES_CHANGED], 0); |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2628 | } |
| 2629 | |
| 2630 | /** |
| 2631 | * fu_plugin_get_rules: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 2632 | * @self: a #FuPlugin |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2633 | * @rule: a #FuPluginRule, e.g. %FU_PLUGIN_RULE_CONFLICTS |
| 2634 | * |
| 2635 | * Gets the plugin IDs that should be run after this plugin. |
| 2636 | * |
Richard Hughes | 11c5941 | 2020-06-22 15:29:48 +0100 | [diff] [blame] | 2637 | * Returns: (element-type utf8) (transfer none) (nullable): the list of plugin names, e.g. ['appstream'] |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 2638 | * |
| 2639 | * Since: 1.0.0 |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2640 | **/ |
| 2641 | GPtrArray * |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2642 | fu_plugin_get_rules (FuPlugin *self, FuPluginRule rule) |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2643 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2644 | FuPluginPrivate *priv = fu_plugin_get_instance_private (self); |
Richard Hughes | dad3597 | 2019-12-06 11:00:25 +0000 | [diff] [blame] | 2645 | g_return_val_if_fail (rule < FU_PLUGIN_RULE_LAST, NULL); |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2646 | return priv->rules[rule]; |
| 2647 | } |
| 2648 | |
Richard Hughes | 80b79bb | 2018-01-11 21:11:06 +0000 | [diff] [blame] | 2649 | /** |
Richard Hughes | 5f3a56b | 2018-06-28 12:13:59 +0100 | [diff] [blame] | 2650 | * fu_plugin_has_rule: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 2651 | * @self: a #FuPlugin |
Richard Hughes | 5f3a56b | 2018-06-28 12:13:59 +0100 | [diff] [blame] | 2652 | * @rule: a #FuPluginRule, e.g. %FU_PLUGIN_RULE_CONFLICTS |
| 2653 | * @name: a plugin name, e.g. `upower` |
| 2654 | * |
Richard Hughes | 87fb9ff | 2018-06-28 12:55:59 +0100 | [diff] [blame] | 2655 | * Gets the plugin IDs that should be run after this plugin. |
Richard Hughes | 5f3a56b | 2018-06-28 12:13:59 +0100 | [diff] [blame] | 2656 | * |
| 2657 | * Returns: %TRUE if the name exists for the specific rule |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 2658 | * |
| 2659 | * Since: 1.0.0 |
Richard Hughes | 5f3a56b | 2018-06-28 12:13:59 +0100 | [diff] [blame] | 2660 | **/ |
| 2661 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2662 | fu_plugin_has_rule (FuPlugin *self, FuPluginRule rule, const gchar *name) |
Richard Hughes | 5f3a56b | 2018-06-28 12:13:59 +0100 | [diff] [blame] | 2663 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2664 | FuPluginPrivate *priv = fu_plugin_get_instance_private (self); |
Richard Hughes | 11c5941 | 2020-06-22 15:29:48 +0100 | [diff] [blame] | 2665 | if (priv->rules[rule] == NULL) |
| 2666 | return FALSE; |
Richard Hughes | 5f3a56b | 2018-06-28 12:13:59 +0100 | [diff] [blame] | 2667 | for (guint i = 0; i < priv->rules[rule]->len; i++) { |
| 2668 | const gchar *tmp = g_ptr_array_index (priv->rules[rule], i); |
| 2669 | if (g_strcmp0 (tmp, name) == 0) |
| 2670 | return TRUE; |
| 2671 | } |
| 2672 | return FALSE; |
| 2673 | } |
| 2674 | |
| 2675 | /** |
Richard Hughes | 80b79bb | 2018-01-11 21:11:06 +0000 | [diff] [blame] | 2676 | * fu_plugin_add_report_metadata: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 2677 | * @self: a #FuPlugin |
Richard Hughes | 80b79bb | 2018-01-11 21:11:06 +0000 | [diff] [blame] | 2678 | * @key: a string, e.g. `FwupdateVersion` |
| 2679 | * @value: a string, e.g. `10` |
| 2680 | * |
| 2681 | * Sets any additional metadata to be included in the firmware report to aid |
| 2682 | * debugging problems. |
| 2683 | * |
| 2684 | * Any data included here will be sent to the metadata server after user |
| 2685 | * confirmation. |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 2686 | * |
| 2687 | * Since: 1.0.4 |
Richard Hughes | 80b79bb | 2018-01-11 21:11:06 +0000 | [diff] [blame] | 2688 | **/ |
| 2689 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2690 | 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] | 2691 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2692 | FuPluginPrivate *priv = fu_plugin_get_instance_private (self); |
Richard Hughes | 1d900f7 | 2020-06-22 15:17:39 +0100 | [diff] [blame] | 2693 | if (priv->report_metadata == NULL) { |
| 2694 | priv->report_metadata = g_hash_table_new_full (g_str_hash, |
| 2695 | g_str_equal, |
| 2696 | g_free, |
| 2697 | g_free); |
| 2698 | } |
Richard Hughes | 80b79bb | 2018-01-11 21:11:06 +0000 | [diff] [blame] | 2699 | g_hash_table_insert (priv->report_metadata, g_strdup (key), g_strdup (value)); |
| 2700 | } |
| 2701 | |
| 2702 | /** |
| 2703 | * fu_plugin_get_report_metadata: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 2704 | * @self: a #FuPlugin |
Richard Hughes | 80b79bb | 2018-01-11 21:11:06 +0000 | [diff] [blame] | 2705 | * |
| 2706 | * Returns the list of additional metadata to be added when filing a report. |
| 2707 | * |
Richard Hughes | 1d900f7 | 2020-06-22 15:17:39 +0100 | [diff] [blame] | 2708 | * Returns: (transfer none) (nullable): the map of report metadata |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 2709 | * |
| 2710 | * Since: 1.0.4 |
Richard Hughes | 80b79bb | 2018-01-11 21:11:06 +0000 | [diff] [blame] | 2711 | **/ |
| 2712 | GHashTable * |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2713 | fu_plugin_get_report_metadata (FuPlugin *self) |
Richard Hughes | 80b79bb | 2018-01-11 21:11:06 +0000 | [diff] [blame] | 2714 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2715 | FuPluginPrivate *priv = fu_plugin_get_instance_private (self); |
Richard Hughes | 80b79bb | 2018-01-11 21:11:06 +0000 | [diff] [blame] | 2716 | return priv->report_metadata; |
| 2717 | } |
| 2718 | |
Mario Limonciello | 963dc42 | 2018-02-27 14:26:58 -0600 | [diff] [blame] | 2719 | /** |
| 2720 | * fu_plugin_get_config_value: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 2721 | * @self: a #FuPlugin |
Mario Limonciello | 963dc42 | 2018-02-27 14:26:58 -0600 | [diff] [blame] | 2722 | * @key: A settings key |
| 2723 | * |
| 2724 | * Return the value of a key if it's been configured |
| 2725 | * |
| 2726 | * Since: 1.0.6 |
| 2727 | **/ |
| 2728 | gchar * |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2729 | fu_plugin_get_config_value (FuPlugin *self, const gchar *key) |
Mario Limonciello | 963dc42 | 2018-02-27 14:26:58 -0600 | [diff] [blame] | 2730 | { |
Richard Hughes | 4be17d1 | 2018-05-30 20:36:29 +0100 | [diff] [blame] | 2731 | g_autofree gchar *conf_dir = NULL; |
Mario Limonciello | 963dc42 | 2018-02-27 14:26:58 -0600 | [diff] [blame] | 2732 | g_autofree gchar *conf_file = NULL; |
| 2733 | g_autofree gchar *conf_path = NULL; |
| 2734 | g_autoptr(GKeyFile) keyfile = NULL; |
| 2735 | const gchar *plugin_name; |
| 2736 | |
Richard Hughes | 4be17d1 | 2018-05-30 20:36:29 +0100 | [diff] [blame] | 2737 | conf_dir = fu_common_get_path (FU_PATH_KIND_SYSCONFDIR_PKG); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2738 | plugin_name = fu_plugin_get_name (self); |
Mario Limonciello | 963dc42 | 2018-02-27 14:26:58 -0600 | [diff] [blame] | 2739 | conf_file = g_strdup_printf ("%s.conf", plugin_name); |
Richard Hughes | 4be17d1 | 2018-05-30 20:36:29 +0100 | [diff] [blame] | 2740 | conf_path = g_build_filename (conf_dir, conf_file, NULL); |
Mario Limonciello | 963dc42 | 2018-02-27 14:26:58 -0600 | [diff] [blame] | 2741 | if (!g_file_test (conf_path, G_FILE_TEST_IS_REGULAR)) |
| 2742 | return NULL; |
| 2743 | keyfile = g_key_file_new (); |
| 2744 | if (!g_key_file_load_from_file (keyfile, conf_path, |
| 2745 | G_KEY_FILE_NONE, NULL)) |
| 2746 | return NULL; |
| 2747 | return g_key_file_get_string (keyfile, plugin_name, key, NULL); |
| 2748 | } |
| 2749 | |
Richard Hughes | 8c71a3f | 2018-05-22 19:19:52 +0100 | [diff] [blame] | 2750 | /** |
Richard Hughes | 334ba79 | 2020-02-19 20:44:56 +0000 | [diff] [blame] | 2751 | * fu_plugin_get_config_value_boolean: |
| 2752 | * @self: a #FuPlugin |
| 2753 | * @key: A settings key |
| 2754 | * |
| 2755 | * Return the boolean value of a key if it's been configured |
| 2756 | * |
| 2757 | * Returns: %TRUE if the value is `true` (case insensitive), %FALSE otherwise |
| 2758 | * |
Mario Limonciello | 96117d1 | 2020-02-28 10:17:56 -0600 | [diff] [blame] | 2759 | * Since: 1.4.0 |
Richard Hughes | 334ba79 | 2020-02-19 20:44:56 +0000 | [diff] [blame] | 2760 | **/ |
| 2761 | gboolean |
| 2762 | fu_plugin_get_config_value_boolean (FuPlugin *self, const gchar *key) |
| 2763 | { |
| 2764 | g_autofree gchar *tmp = fu_plugin_get_config_value (self, key); |
| 2765 | if (tmp == NULL) |
| 2766 | return FALSE; |
Richard Hughes | 5337a43 | 2020-02-21 12:04:32 +0000 | [diff] [blame] | 2767 | return g_ascii_strcasecmp (tmp, "true") == 0; |
Richard Hughes | 334ba79 | 2020-02-19 20:44:56 +0000 | [diff] [blame] | 2768 | } |
| 2769 | |
| 2770 | /** |
Richard Hughes | 8c71a3f | 2018-05-22 19:19:52 +0100 | [diff] [blame] | 2771 | * fu_plugin_name_compare: |
| 2772 | * @plugin1: first #FuPlugin to compare. |
| 2773 | * @plugin2: second #FuPlugin to compare. |
| 2774 | * |
| 2775 | * Compares two plugins by their names. |
| 2776 | * |
| 2777 | * Returns: 1, 0 or -1 if @plugin1 is greater, equal, or less than @plugin2. |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 2778 | * |
| 2779 | * Since: 1.0.8 |
Richard Hughes | 8c71a3f | 2018-05-22 19:19:52 +0100 | [diff] [blame] | 2780 | **/ |
| 2781 | gint |
| 2782 | fu_plugin_name_compare (FuPlugin *plugin1, FuPlugin *plugin2) |
| 2783 | { |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 2784 | return g_strcmp0 (fu_plugin_get_name (plugin1), fu_plugin_get_name (plugin2)); |
Richard Hughes | 8c71a3f | 2018-05-22 19:19:52 +0100 | [diff] [blame] | 2785 | } |
| 2786 | |
| 2787 | /** |
| 2788 | * fu_plugin_order_compare: |
| 2789 | * @plugin1: first #FuPlugin to compare. |
| 2790 | * @plugin2: second #FuPlugin to compare. |
| 2791 | * |
| 2792 | * Compares two plugins by their depsolved order. |
| 2793 | * |
| 2794 | * Returns: 1, 0 or -1 if @plugin1 is greater, equal, or less than @plugin2. |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 2795 | * |
| 2796 | * Since: 1.0.8 |
Richard Hughes | 8c71a3f | 2018-05-22 19:19:52 +0100 | [diff] [blame] | 2797 | **/ |
| 2798 | gint |
| 2799 | fu_plugin_order_compare (FuPlugin *plugin1, FuPlugin *plugin2) |
| 2800 | { |
| 2801 | FuPluginPrivate *priv1 = fu_plugin_get_instance_private (plugin1); |
| 2802 | FuPluginPrivate *priv2 = fu_plugin_get_instance_private (plugin2); |
| 2803 | if (priv1->order < priv2->order) |
| 2804 | return -1; |
| 2805 | if (priv1->order > priv2->order) |
| 2806 | return 1; |
| 2807 | return 0; |
| 2808 | } |
| 2809 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2810 | static void |
| 2811 | fu_plugin_class_init (FuPluginClass *klass) |
| 2812 | { |
| 2813 | GObjectClass *object_class = G_OBJECT_CLASS (klass); |
| 2814 | object_class->finalize = fu_plugin_finalize; |
| 2815 | signals[SIGNAL_DEVICE_ADDED] = |
| 2816 | g_signal_new ("device-added", |
| 2817 | G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, |
| 2818 | G_STRUCT_OFFSET (FuPluginClass, device_added), |
| 2819 | NULL, NULL, g_cclosure_marshal_VOID__OBJECT, |
| 2820 | G_TYPE_NONE, 1, FU_TYPE_DEVICE); |
| 2821 | signals[SIGNAL_DEVICE_REMOVED] = |
| 2822 | g_signal_new ("device-removed", |
| 2823 | G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, |
| 2824 | G_STRUCT_OFFSET (FuPluginClass, device_removed), |
| 2825 | NULL, NULL, g_cclosure_marshal_VOID__OBJECT, |
| 2826 | G_TYPE_NONE, 1, FU_TYPE_DEVICE); |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 2827 | signals[SIGNAL_DEVICE_REGISTER] = |
| 2828 | g_signal_new ("device-register", |
| 2829 | G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, |
| 2830 | G_STRUCT_OFFSET (FuPluginClass, device_register), |
| 2831 | NULL, NULL, g_cclosure_marshal_VOID__OBJECT, |
| 2832 | G_TYPE_NONE, 1, FU_TYPE_DEVICE); |
Richard Hughes | 362d6d7 | 2017-01-07 21:42:14 +0000 | [diff] [blame] | 2833 | signals[SIGNAL_RECOLDPLUG] = |
| 2834 | g_signal_new ("recoldplug", |
| 2835 | G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, |
| 2836 | G_STRUCT_OFFSET (FuPluginClass, recoldplug), |
| 2837 | NULL, NULL, g_cclosure_marshal_VOID__VOID, |
| 2838 | G_TYPE_NONE, 0); |
Richard Hughes | 399859e | 2020-05-11 19:44:03 +0100 | [diff] [blame] | 2839 | signals[SIGNAL_SECURITY_CHANGED] = |
| 2840 | g_signal_new ("security-changed", |
| 2841 | G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, |
| 2842 | G_STRUCT_OFFSET (FuPluginClass, security_changed), |
| 2843 | NULL, NULL, g_cclosure_marshal_VOID__VOID, |
| 2844 | G_TYPE_NONE, 0); |
Richard Hughes | b082903 | 2017-01-10 09:27:08 +0000 | [diff] [blame] | 2845 | signals[SIGNAL_SET_COLDPLUG_DELAY] = |
| 2846 | g_signal_new ("set-coldplug-delay", |
| 2847 | G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, |
| 2848 | G_STRUCT_OFFSET (FuPluginClass, set_coldplug_delay), |
| 2849 | NULL, NULL, g_cclosure_marshal_VOID__UINT, |
| 2850 | G_TYPE_NONE, 1, G_TYPE_UINT); |
Richard Hughes | aabdc37 | 2018-11-14 10:11:08 +0000 | [diff] [blame] | 2851 | signals[SIGNAL_CHECK_SUPPORTED] = |
| 2852 | g_signal_new ("check-supported", |
| 2853 | G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, |
| 2854 | G_STRUCT_OFFSET (FuPluginClass, check_supported), |
| 2855 | NULL, NULL, g_cclosure_marshal_generic, |
| 2856 | G_TYPE_BOOLEAN, 1, G_TYPE_STRING); |
Richard Hughes | 75b965d | 2018-11-15 13:51:21 +0000 | [diff] [blame] | 2857 | signals[SIGNAL_RULES_CHANGED] = |
| 2858 | g_signal_new ("rules-changed", |
| 2859 | G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, |
| 2860 | G_STRUCT_OFFSET (FuPluginClass, rules_changed), |
| 2861 | NULL, NULL, g_cclosure_marshal_VOID__VOID, |
| 2862 | G_TYPE_NONE, 0); |
Richard Hughes | 95c98a9 | 2019-10-22 16:03:15 +0100 | [diff] [blame] | 2863 | signals[SIGNAL_ADD_FIRMWARE_GTYPE] = |
| 2864 | g_signal_new ("add-firmware-gtype", |
| 2865 | G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, |
| 2866 | G_STRUCT_OFFSET (FuPluginClass, add_firmware_gtype), |
| 2867 | NULL, NULL, g_cclosure_marshal_generic, |
| 2868 | G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_GTYPE); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2869 | } |
| 2870 | |
| 2871 | static void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2872 | fu_plugin_init (FuPlugin *self) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2873 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2874 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | faf2afe | 2021-01-13 14:00:20 +0000 | [diff] [blame] | 2875 | g_rw_lock_init (&priv->cache_mutex); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2876 | } |
| 2877 | |
| 2878 | static void |
| 2879 | fu_plugin_finalize (GObject *object) |
| 2880 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2881 | FuPlugin *self = FU_PLUGIN (object); |
| 2882 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2883 | FuPluginInitFunc func = NULL; |
| 2884 | |
Richard Hughes | faf2afe | 2021-01-13 14:00:20 +0000 | [diff] [blame] | 2885 | g_rw_lock_clear (&priv->cache_mutex); |
Richard Hughes | aae22e4 | 2020-06-22 21:32:59 +0100 | [diff] [blame] | 2886 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2887 | /* optional */ |
| 2888 | if (priv->module != NULL) { |
| 2889 | g_module_symbol (priv->module, "fu_plugin_destroy", (gpointer *) &func); |
| 2890 | if (func != NULL) { |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 2891 | g_debug ("destroy(%s)", fu_plugin_get_name (self)); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2892 | func (self); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2893 | } |
| 2894 | } |
| 2895 | |
Richard Hughes | 11c5941 | 2020-06-22 15:29:48 +0100 | [diff] [blame] | 2896 | for (guint i = 0; i < FU_PLUGIN_RULE_LAST; i++) { |
| 2897 | if (priv->rules[i] != NULL) |
| 2898 | g_ptr_array_unref (priv->rules[i]); |
| 2899 | } |
Richard Hughes | 68ab1e4 | 2021-01-13 14:01:17 +0000 | [diff] [blame] | 2900 | if (priv->devices != NULL) |
| 2901 | g_ptr_array_unref (priv->devices); |
Richard Hughes | b8f8db2 | 2017-04-25 15:56:00 +0100 | [diff] [blame] | 2902 | if (priv->hwids != NULL) |
Richard Hughes | d7704d4 | 2017-08-08 20:29:09 +0100 | [diff] [blame] | 2903 | g_object_unref (priv->hwids); |
Richard Hughes | 9c028f0 | 2017-10-28 21:14:28 +0100 | [diff] [blame] | 2904 | if (priv->quirks != NULL) |
| 2905 | g_object_unref (priv->quirks); |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 2906 | if (priv->udev_subsystems != NULL) |
| 2907 | g_ptr_array_unref (priv->udev_subsystems); |
Richard Hughes | 49e5e05 | 2017-09-03 12:15:41 +0100 | [diff] [blame] | 2908 | if (priv->smbios != NULL) |
| 2909 | g_object_unref (priv->smbios); |
Richard Hughes | 275d3b4 | 2018-04-20 16:40:37 +0100 | [diff] [blame] | 2910 | if (priv->runtime_versions != NULL) |
| 2911 | g_hash_table_unref (priv->runtime_versions); |
Richard Hughes | 34e0dab | 2018-04-20 16:43:00 +0100 | [diff] [blame] | 2912 | if (priv->compile_versions != NULL) |
| 2913 | g_hash_table_unref (priv->compile_versions); |
Richard Hughes | 1d900f7 | 2020-06-22 15:17:39 +0100 | [diff] [blame] | 2914 | if (priv->report_metadata != NULL) |
| 2915 | g_hash_table_unref (priv->report_metadata); |
Richard Hughes | faf2afe | 2021-01-13 14:00:20 +0000 | [diff] [blame] | 2916 | if (priv->cache != NULL) |
| 2917 | g_hash_table_unref (priv->cache); |
Richard Hughes | 8499930 | 2019-05-02 10:18:32 +0100 | [diff] [blame] | 2918 | g_free (priv->build_hash); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2919 | g_free (priv->data); |
Mario Limonciello | 3f9a1c1 | 2018-06-06 14:06:40 -0500 | [diff] [blame] | 2920 | /* Must happen as the last step to avoid prematurely |
| 2921 | * freeing memory held by the plugin */ |
Richard Hughes | 862ec5c | 2020-05-22 14:38:02 +0100 | [diff] [blame] | 2922 | #ifdef RUNNING_ON_VALGRIND |
| 2923 | if (priv->module != NULL && RUNNING_ON_VALGRIND == 0) |
| 2924 | #else |
Mario Limonciello | 3f9a1c1 | 2018-06-06 14:06:40 -0500 | [diff] [blame] | 2925 | if (priv->module != NULL) |
Mario Limonciello | 3f9a1c1 | 2018-06-06 14:06:40 -0500 | [diff] [blame] | 2926 | #endif |
Richard Hughes | 862ec5c | 2020-05-22 14:38:02 +0100 | [diff] [blame] | 2927 | g_module_close (priv->module); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2928 | |
| 2929 | G_OBJECT_CLASS (fu_plugin_parent_class)->finalize (object); |
| 2930 | } |
| 2931 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 2932 | /** |
| 2933 | * fu_plugin_new: |
| 2934 | * |
| 2935 | * Creates a new #FuPlugin |
| 2936 | * |
| 2937 | * Since: 0.8.0 |
| 2938 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2939 | FuPlugin * |
| 2940 | fu_plugin_new (void) |
| 2941 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2942 | return FU_PLUGIN (g_object_new (FU_TYPE_PLUGIN, NULL)); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2943 | } |