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