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