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