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