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