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