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