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