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