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 | { |
Richard Hughes | afdba37 | 2019-11-23 12:57:35 +0000 | [diff] [blame^] | 1014 | g_autofree gchar *trigger = fu_common_get_path (FU_PATH_KIND_OFFLINE_TRIGGER); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1015 | g_autoptr(GError) error_local = NULL; |
| 1016 | g_autoptr(GFile) file1 = NULL; |
| 1017 | |
| 1018 | g_return_val_if_fail (error == NULL || *error == NULL, FALSE); |
| 1019 | |
Richard Hughes | afdba37 | 2019-11-23 12:57:35 +0000 | [diff] [blame^] | 1020 | file1 = g_file_new_for_path (trigger); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1021 | if (!g_file_query_exists (file1, NULL)) |
| 1022 | return TRUE; |
| 1023 | if (!g_file_delete (file1, NULL, &error_local)) { |
| 1024 | g_set_error (error, |
| 1025 | FWUPD_ERROR, |
| 1026 | FWUPD_ERROR_INTERNAL, |
| 1027 | "Cannot delete %s: %s", |
Richard Hughes | afdba37 | 2019-11-23 12:57:35 +0000 | [diff] [blame^] | 1028 | trigger, |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1029 | error_local->message); |
| 1030 | return FALSE; |
| 1031 | } |
| 1032 | return TRUE; |
| 1033 | } |
| 1034 | |
| 1035 | static gboolean |
| 1036 | fu_plugin_runner_offline_setup (GError **error) |
| 1037 | { |
| 1038 | gint rc; |
Richard Hughes | 484ee29 | 2019-03-22 16:10:50 +0000 | [diff] [blame] | 1039 | g_autofree gchar *filename = NULL; |
Mario Limonciello | e1b4b20 | 2019-04-30 10:01:19 -0500 | [diff] [blame] | 1040 | g_autofree gchar *symlink_target = fu_common_get_path (FU_PATH_KIND_LOCALSTATEDIR_PKG); |
Richard Hughes | afdba37 | 2019-11-23 12:57:35 +0000 | [diff] [blame^] | 1041 | g_autofree gchar *trigger = fu_common_get_path (FU_PATH_KIND_OFFLINE_TRIGGER); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1042 | |
| 1043 | g_return_val_if_fail (error == NULL || *error == NULL, FALSE); |
| 1044 | |
Richard Hughes | 484ee29 | 2019-03-22 16:10:50 +0000 | [diff] [blame] | 1045 | /* does already exist */ |
Richard Hughes | afdba37 | 2019-11-23 12:57:35 +0000 | [diff] [blame^] | 1046 | filename = fu_common_realpath (trigger, NULL); |
Richard Hughes | 484ee29 | 2019-03-22 16:10:50 +0000 | [diff] [blame] | 1047 | if (g_strcmp0 (filename, symlink_target) == 0) { |
| 1048 | g_debug ("%s already points to %s, skipping creation", |
Richard Hughes | afdba37 | 2019-11-23 12:57:35 +0000 | [diff] [blame^] | 1049 | trigger, symlink_target); |
Richard Hughes | 484ee29 | 2019-03-22 16:10:50 +0000 | [diff] [blame] | 1050 | return TRUE; |
| 1051 | } |
| 1052 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1053 | /* create symlink for the systemd-system-update-generator */ |
Richard Hughes | afdba37 | 2019-11-23 12:57:35 +0000 | [diff] [blame^] | 1054 | rc = symlink (symlink_target, trigger); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1055 | if (rc < 0) { |
| 1056 | g_set_error (error, |
| 1057 | FWUPD_ERROR, |
| 1058 | FWUPD_ERROR_INTERNAL, |
| 1059 | "Failed to create symlink %s to %s: %s", |
Richard Hughes | afdba37 | 2019-11-23 12:57:35 +0000 | [diff] [blame^] | 1060 | trigger, |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1061 | "/var/lib", strerror (errno)); |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1062 | return FALSE; |
| 1063 | } |
| 1064 | return TRUE; |
| 1065 | } |
| 1066 | |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1067 | static gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1068 | fu_plugin_runner_device_generic (FuPlugin *self, FuDevice *device, |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 1069 | const gchar *symbol_name, |
| 1070 | FuPluginDeviceFunc device_func, |
| 1071 | GError **error) |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1072 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1073 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1074 | FuPluginDeviceFunc func = NULL; |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1075 | g_autoptr(GError) error_local = NULL; |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1076 | |
| 1077 | /* not enabled */ |
| 1078 | if (!priv->enabled) |
| 1079 | return TRUE; |
| 1080 | |
Richard Hughes | d3d96cc | 2017-11-14 11:34:33 +0000 | [diff] [blame] | 1081 | /* no object loaded */ |
| 1082 | if (priv->module == NULL) |
| 1083 | return TRUE; |
| 1084 | |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1085 | /* optional */ |
| 1086 | g_module_symbol (priv->module, symbol_name, (gpointer *) &func); |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 1087 | if (func == NULL) { |
| 1088 | if (device_func != NULL) { |
| 1089 | g_debug ("running superclassed %s() on %s", |
| 1090 | symbol_name + 10, priv->name); |
| 1091 | return device_func (self, device, error); |
| 1092 | } |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1093 | return TRUE; |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 1094 | } |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1095 | g_debug ("performing %s() on %s", symbol_name + 10, priv->name); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1096 | if (!func (self, device, &error_local)) { |
| 1097 | if (error_local == NULL) { |
| 1098 | g_critical ("unset error in plugin %s for %s()", |
| 1099 | priv->name, symbol_name + 10); |
| 1100 | g_set_error_literal (&error_local, |
| 1101 | FWUPD_ERROR, |
| 1102 | FWUPD_ERROR_INTERNAL, |
| 1103 | "unspecified error"); |
| 1104 | } |
| 1105 | g_propagate_prefixed_error (error, g_steal_pointer (&error_local), |
| 1106 | "failed to %s using %s: ", |
| 1107 | symbol_name + 10, priv->name); |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1108 | return FALSE; |
| 1109 | } |
| 1110 | return TRUE; |
| 1111 | } |
| 1112 | |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 1113 | static gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1114 | fu_plugin_runner_flagged_device_generic (FuPlugin *self, FwupdInstallFlags flags, |
Mario Limonciello | e3b1a3f | 2018-08-21 13:01:45 -0500 | [diff] [blame] | 1115 | FuDevice *device, |
| 1116 | const gchar *symbol_name, GError **error) |
| 1117 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1118 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Mario Limonciello | e3b1a3f | 2018-08-21 13:01:45 -0500 | [diff] [blame] | 1119 | FuPluginFlaggedDeviceFunc func = NULL; |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1120 | g_autoptr(GError) error_local = NULL; |
Mario Limonciello | e3b1a3f | 2018-08-21 13:01:45 -0500 | [diff] [blame] | 1121 | |
| 1122 | /* not enabled */ |
| 1123 | if (!priv->enabled) |
| 1124 | return TRUE; |
| 1125 | |
| 1126 | /* no object loaded */ |
| 1127 | if (priv->module == NULL) |
| 1128 | return TRUE; |
| 1129 | |
| 1130 | /* optional */ |
| 1131 | g_module_symbol (priv->module, symbol_name, (gpointer *) &func); |
| 1132 | if (func == NULL) |
| 1133 | return TRUE; |
| 1134 | g_debug ("performing %s() on %s", symbol_name + 10, priv->name); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1135 | if (!func (self, flags, device, &error_local)) { |
| 1136 | if (error_local == NULL) { |
| 1137 | g_critical ("unset error in plugin %s for %s()", |
| 1138 | priv->name, symbol_name + 10); |
| 1139 | g_set_error_literal (&error_local, |
| 1140 | FWUPD_ERROR, |
| 1141 | FWUPD_ERROR_INTERNAL, |
| 1142 | "unspecified error"); |
| 1143 | } |
| 1144 | g_propagate_prefixed_error (error, g_steal_pointer (&error_local), |
| 1145 | "failed to %s using %s: ", |
| 1146 | symbol_name + 10, priv->name); |
Mario Limonciello | e3b1a3f | 2018-08-21 13:01:45 -0500 | [diff] [blame] | 1147 | return FALSE; |
| 1148 | } |
| 1149 | return TRUE; |
| 1150 | |
| 1151 | } |
| 1152 | |
| 1153 | static gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1154 | fu_plugin_runner_device_array_generic (FuPlugin *self, GPtrArray *devices, |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 1155 | const gchar *symbol_name, GError **error) |
| 1156 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1157 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 1158 | FuPluginDeviceArrayFunc func = NULL; |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1159 | g_autoptr(GError) error_local = NULL; |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 1160 | |
| 1161 | /* not enabled */ |
| 1162 | if (!priv->enabled) |
| 1163 | return TRUE; |
| 1164 | |
| 1165 | /* no object loaded */ |
| 1166 | if (priv->module == NULL) |
| 1167 | return TRUE; |
| 1168 | |
| 1169 | /* optional */ |
| 1170 | g_module_symbol (priv->module, symbol_name, (gpointer *) &func); |
| 1171 | if (func == NULL) |
| 1172 | return TRUE; |
| 1173 | g_debug ("performing %s() on %s", symbol_name + 10, priv->name); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1174 | if (!func (self, devices, &error_local)) { |
| 1175 | if (error_local == NULL) { |
| 1176 | g_critical ("unset error in plugin %s for %s()", |
| 1177 | priv->name, symbol_name + 10); |
| 1178 | g_set_error_literal (&error_local, |
| 1179 | FWUPD_ERROR, |
| 1180 | FWUPD_ERROR_INTERNAL, |
| 1181 | "unspecified error"); |
| 1182 | } |
| 1183 | g_propagate_prefixed_error (error, g_steal_pointer (&error_local), |
| 1184 | "failed to %s using %s: ", |
| 1185 | symbol_name + 10, priv->name); |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 1186 | return FALSE; |
| 1187 | } |
| 1188 | return TRUE; |
| 1189 | } |
| 1190 | |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1191 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1192 | fu_plugin_runner_coldplug (FuPlugin *self, GError **error) |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1193 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1194 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 1195 | FuPluginStartupFunc func = NULL; |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1196 | g_autoptr(GError) error_local = NULL; |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1197 | |
| 1198 | /* not enabled */ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1199 | if (!priv->enabled) |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1200 | return TRUE; |
| 1201 | |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 1202 | /* no object loaded */ |
| 1203 | if (priv->module == NULL) |
| 1204 | return TRUE; |
| 1205 | |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1206 | /* optional */ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1207 | g_module_symbol (priv->module, "fu_plugin_coldplug", (gpointer *) &func); |
| 1208 | if (func == NULL) |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1209 | return TRUE; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1210 | g_debug ("performing coldplug() on %s", priv->name); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1211 | if (!func (self, &error_local)) { |
| 1212 | if (error_local == NULL) { |
| 1213 | g_critical ("unset error in plugin %s for coldplug()", |
| 1214 | priv->name); |
| 1215 | g_set_error_literal (&error_local, |
| 1216 | FWUPD_ERROR, |
| 1217 | FWUPD_ERROR_INTERNAL, |
| 1218 | "unspecified error"); |
| 1219 | } |
| 1220 | g_propagate_prefixed_error (error, g_steal_pointer (&error_local), |
| 1221 | "failed to coldplug using %s: ", priv->name); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1222 | return FALSE; |
| 1223 | } |
| 1224 | return TRUE; |
| 1225 | } |
| 1226 | |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 1227 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1228 | fu_plugin_runner_recoldplug (FuPlugin *self, GError **error) |
Richard Hughes | 2de8f13 | 2018-01-17 09:12:02 +0000 | [diff] [blame] | 1229 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1230 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 2de8f13 | 2018-01-17 09:12:02 +0000 | [diff] [blame] | 1231 | FuPluginStartupFunc func = NULL; |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1232 | g_autoptr(GError) error_local = NULL; |
Richard Hughes | 2de8f13 | 2018-01-17 09:12:02 +0000 | [diff] [blame] | 1233 | |
| 1234 | /* not enabled */ |
| 1235 | if (!priv->enabled) |
| 1236 | return TRUE; |
| 1237 | |
| 1238 | /* no object loaded */ |
| 1239 | if (priv->module == NULL) |
| 1240 | return TRUE; |
| 1241 | |
| 1242 | /* optional */ |
| 1243 | g_module_symbol (priv->module, "fu_plugin_recoldplug", (gpointer *) &func); |
| 1244 | if (func == NULL) |
| 1245 | return TRUE; |
| 1246 | g_debug ("performing recoldplug() on %s", priv->name); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1247 | if (!func (self, &error_local)) { |
| 1248 | if (error_local == NULL) { |
| 1249 | g_critical ("unset error in plugin %s for recoldplug()", |
| 1250 | priv->name); |
| 1251 | g_set_error_literal (&error_local, |
| 1252 | FWUPD_ERROR, |
| 1253 | FWUPD_ERROR_INTERNAL, |
| 1254 | "unspecified error"); |
| 1255 | } |
| 1256 | g_propagate_prefixed_error (error, g_steal_pointer (&error_local), |
| 1257 | "failed to recoldplug using %s: ", |
| 1258 | priv->name); |
Richard Hughes | 2de8f13 | 2018-01-17 09:12:02 +0000 | [diff] [blame] | 1259 | return FALSE; |
| 1260 | } |
| 1261 | return TRUE; |
| 1262 | } |
| 1263 | |
| 1264 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1265 | fu_plugin_runner_coldplug_prepare (FuPlugin *self, GError **error) |
Richard Hughes | 46487c9 | 2017-01-07 21:26:34 +0000 | [diff] [blame] | 1266 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1267 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 46487c9 | 2017-01-07 21:26:34 +0000 | [diff] [blame] | 1268 | FuPluginStartupFunc func = NULL; |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1269 | g_autoptr(GError) error_local = NULL; |
Richard Hughes | 46487c9 | 2017-01-07 21:26:34 +0000 | [diff] [blame] | 1270 | |
| 1271 | /* not enabled */ |
| 1272 | if (!priv->enabled) |
| 1273 | return TRUE; |
| 1274 | |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 1275 | /* no object loaded */ |
| 1276 | if (priv->module == NULL) |
| 1277 | return TRUE; |
| 1278 | |
Richard Hughes | 46487c9 | 2017-01-07 21:26:34 +0000 | [diff] [blame] | 1279 | /* optional */ |
| 1280 | g_module_symbol (priv->module, "fu_plugin_coldplug_prepare", (gpointer *) &func); |
| 1281 | if (func == NULL) |
| 1282 | return TRUE; |
| 1283 | g_debug ("performing coldplug_prepare() on %s", priv->name); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1284 | if (!func (self, &error_local)) { |
| 1285 | if (error_local == NULL) { |
| 1286 | g_critical ("unset error in plugin %s for coldplug_prepare()", |
| 1287 | priv->name); |
| 1288 | g_set_error_literal (&error_local, |
| 1289 | FWUPD_ERROR, |
| 1290 | FWUPD_ERROR_INTERNAL, |
| 1291 | "unspecified error"); |
| 1292 | } |
| 1293 | g_propagate_prefixed_error (error, g_steal_pointer (&error_local), |
| 1294 | "failed to coldplug_prepare using %s: ", |
| 1295 | priv->name); |
Richard Hughes | 46487c9 | 2017-01-07 21:26:34 +0000 | [diff] [blame] | 1296 | return FALSE; |
| 1297 | } |
| 1298 | return TRUE; |
| 1299 | } |
| 1300 | |
| 1301 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1302 | fu_plugin_runner_coldplug_cleanup (FuPlugin *self, GError **error) |
Richard Hughes | 46487c9 | 2017-01-07 21:26:34 +0000 | [diff] [blame] | 1303 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1304 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 46487c9 | 2017-01-07 21:26:34 +0000 | [diff] [blame] | 1305 | FuPluginStartupFunc func = NULL; |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1306 | g_autoptr(GError) error_local = NULL; |
Richard Hughes | 46487c9 | 2017-01-07 21:26:34 +0000 | [diff] [blame] | 1307 | |
| 1308 | /* not enabled */ |
| 1309 | if (!priv->enabled) |
| 1310 | return TRUE; |
| 1311 | |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 1312 | /* no object loaded */ |
| 1313 | if (priv->module == NULL) |
| 1314 | return TRUE; |
| 1315 | |
Richard Hughes | 46487c9 | 2017-01-07 21:26:34 +0000 | [diff] [blame] | 1316 | /* optional */ |
| 1317 | g_module_symbol (priv->module, "fu_plugin_coldplug_cleanup", (gpointer *) &func); |
| 1318 | if (func == NULL) |
| 1319 | return TRUE; |
| 1320 | g_debug ("performing coldplug_cleanup() on %s", priv->name); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1321 | if (!func (self, &error_local)) { |
| 1322 | if (error_local == NULL) { |
| 1323 | g_critical ("unset error in plugin %s for coldplug_cleanup()", |
| 1324 | priv->name); |
| 1325 | g_set_error_literal (&error_local, |
| 1326 | FWUPD_ERROR, |
| 1327 | FWUPD_ERROR_INTERNAL, |
| 1328 | "unspecified error"); |
| 1329 | } |
| 1330 | g_propagate_prefixed_error (error, g_steal_pointer (&error_local), |
| 1331 | "failed to coldplug_cleanup using %s: ", |
| 1332 | priv->name); |
Richard Hughes | 46487c9 | 2017-01-07 21:26:34 +0000 | [diff] [blame] | 1333 | return FALSE; |
| 1334 | } |
| 1335 | return TRUE; |
| 1336 | } |
| 1337 | |
| 1338 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1339 | fu_plugin_runner_composite_prepare (FuPlugin *self, GPtrArray *devices, GError **error) |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 1340 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1341 | return fu_plugin_runner_device_array_generic (self, devices, |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 1342 | "fu_plugin_composite_prepare", |
| 1343 | error); |
| 1344 | } |
| 1345 | |
| 1346 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1347 | fu_plugin_runner_composite_cleanup (FuPlugin *self, GPtrArray *devices, GError **error) |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 1348 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1349 | return fu_plugin_runner_device_array_generic (self, devices, |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 1350 | "fu_plugin_composite_cleanup", |
| 1351 | error); |
| 1352 | } |
| 1353 | |
| 1354 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1355 | fu_plugin_runner_update_prepare (FuPlugin *self, FwupdInstallFlags flags, FuDevice *device, |
Mario Limonciello | e3b1a3f | 2018-08-21 13:01:45 -0500 | [diff] [blame] | 1356 | GError **error) |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 1357 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1358 | return fu_plugin_runner_flagged_device_generic (self, flags, device, |
Mario Limonciello | e3b1a3f | 2018-08-21 13:01:45 -0500 | [diff] [blame] | 1359 | "fu_plugin_update_prepare", |
| 1360 | error); |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 1361 | } |
| 1362 | |
| 1363 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1364 | fu_plugin_runner_update_cleanup (FuPlugin *self, FwupdInstallFlags flags, FuDevice *device, |
Mario Limonciello | e3b1a3f | 2018-08-21 13:01:45 -0500 | [diff] [blame] | 1365 | GError **error) |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 1366 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1367 | return fu_plugin_runner_flagged_device_generic (self, flags, device, |
Mario Limonciello | e3b1a3f | 2018-08-21 13:01:45 -0500 | [diff] [blame] | 1368 | "fu_plugin_update_cleanup", |
| 1369 | error); |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1370 | } |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 1371 | |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1372 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1373 | fu_plugin_runner_update_attach (FuPlugin *self, FuDevice *device, GError **error) |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1374 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1375 | return fu_plugin_runner_device_generic (self, device, |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 1376 | "fu_plugin_update_attach", |
| 1377 | fu_plugin_device_attach, |
| 1378 | error); |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1379 | } |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 1380 | |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1381 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1382 | fu_plugin_runner_update_detach (FuPlugin *self, FuDevice *device, GError **error) |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1383 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1384 | return fu_plugin_runner_device_generic (self, device, |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 1385 | "fu_plugin_update_detach", |
| 1386 | fu_plugin_device_detach, |
| 1387 | error); |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1388 | } |
| 1389 | |
| 1390 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1391 | fu_plugin_runner_update_reload (FuPlugin *self, FuDevice *device, GError **error) |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1392 | { |
Richard Hughes | 42f33df | 2019-10-05 20:52:33 +0100 | [diff] [blame] | 1393 | FuPluginPrivate *priv = GET_PRIVATE (self); |
| 1394 | g_autoptr(FuDeviceLocker) locker = NULL; |
| 1395 | |
| 1396 | /* not enabled */ |
| 1397 | if (!priv->enabled) |
| 1398 | return TRUE; |
| 1399 | |
| 1400 | /* no object loaded */ |
| 1401 | locker = fu_device_locker_new (device, error); |
| 1402 | if (locker == NULL) |
| 1403 | return FALSE; |
| 1404 | return fu_device_reload (device, error); |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 1405 | } |
| 1406 | |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 1407 | /** |
| 1408 | * fu_plugin_add_udev_subsystem: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 1409 | * @self: a #FuPlugin |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 1410 | * @subsystem: a subsystem name, e.g. `pciport` |
| 1411 | * |
| 1412 | * Registers the udev subsystem to be watched by the daemon. |
| 1413 | * |
| 1414 | * Plugins can use this method only in fu_plugin_init() |
| 1415 | **/ |
| 1416 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1417 | fu_plugin_add_udev_subsystem (FuPlugin *self, const gchar *subsystem) |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 1418 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1419 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 1420 | for (guint i = 0; i < priv->udev_subsystems->len; i++) { |
| 1421 | const gchar *subsystem_tmp = g_ptr_array_index (priv->udev_subsystems, i); |
| 1422 | if (g_strcmp0 (subsystem_tmp, subsystem) == 0) |
| 1423 | return; |
| 1424 | } |
| 1425 | g_debug ("added udev subsystem watch of %s", subsystem); |
| 1426 | g_ptr_array_add (priv->udev_subsystems, g_strdup (subsystem)); |
| 1427 | } |
| 1428 | |
Richard Hughes | 989acf1 | 2019-10-05 20:16:47 +0100 | [diff] [blame] | 1429 | /** |
| 1430 | * fu_plugin_set_device_gtype: |
| 1431 | * @self: a #FuPlugin |
| 1432 | * @device_gtype: a #GType `FU_TYPE_DEVICE` |
| 1433 | * |
| 1434 | * Sets the device #GType which is used when creating devices. |
| 1435 | * |
| 1436 | * If this method is used then fu_plugin_usb_device_added() is not called, and |
| 1437 | * instead the object is created in the daemon for the plugin. |
| 1438 | * |
| 1439 | * Plugins can use this method only in fu_plugin_init() |
| 1440 | * |
| 1441 | * Since: 1.3.3 |
| 1442 | **/ |
| 1443 | void |
| 1444 | fu_plugin_set_device_gtype (FuPlugin *self, GType device_gtype) |
| 1445 | { |
| 1446 | FuPluginPrivate *priv = GET_PRIVATE (self); |
| 1447 | priv->device_gtype = device_gtype; |
| 1448 | } |
| 1449 | |
Richard Hughes | 95c98a9 | 2019-10-22 16:03:15 +0100 | [diff] [blame] | 1450 | void |
| 1451 | fu_plugin_add_firmware_gtype (FuPlugin *self, const gchar *id, GType gtype) |
| 1452 | { |
| 1453 | g_signal_emit (self, signals[SIGNAL_ADD_FIRMWARE_GTYPE], 0, id, gtype); |
| 1454 | } |
| 1455 | |
Richard Hughes | 989acf1 | 2019-10-05 20:16:47 +0100 | [diff] [blame] | 1456 | static gboolean |
Richard Hughes | d8a8d5e | 2019-10-08 13:05:02 +0100 | [diff] [blame] | 1457 | fu_plugin_check_supported_device (FuPlugin *self, FuDevice *device) |
| 1458 | { |
| 1459 | GPtrArray *instance_ids = fu_device_get_instance_ids (device); |
| 1460 | for (guint i = 0; i < instance_ids->len; i++) { |
| 1461 | const gchar *instance_id = g_ptr_array_index (instance_ids, i); |
| 1462 | g_autofree gchar *guid = fwupd_guid_hash_string (instance_id); |
| 1463 | if (fu_plugin_check_supported (self, guid)) |
| 1464 | return TRUE; |
| 1465 | } |
| 1466 | return FALSE; |
| 1467 | } |
| 1468 | |
| 1469 | static gboolean |
Richard Hughes | 989acf1 | 2019-10-05 20:16:47 +0100 | [diff] [blame] | 1470 | fu_plugin_usb_device_added (FuPlugin *self, FuUsbDevice *device, GError **error) |
| 1471 | { |
| 1472 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | d8a8d5e | 2019-10-08 13:05:02 +0100 | [diff] [blame] | 1473 | GType device_gtype = fu_device_get_specialized_gtype (FU_DEVICE (device)); |
Richard Hughes | 989acf1 | 2019-10-05 20:16:47 +0100 | [diff] [blame] | 1474 | g_autoptr(FuDevice) dev = NULL; |
| 1475 | g_autoptr(FuDeviceLocker) locker = NULL; |
Richard Hughes | d8a8d5e | 2019-10-08 13:05:02 +0100 | [diff] [blame] | 1476 | |
| 1477 | /* fall back to plugin default */ |
| 1478 | if (device_gtype == G_TYPE_INVALID) |
| 1479 | device_gtype = priv->device_gtype; |
| 1480 | |
| 1481 | /* create new device and incorporate existing properties */ |
| 1482 | dev = g_object_new (device_gtype, NULL); |
| 1483 | fu_device_incorporate (dev, FU_DEVICE (device)); |
| 1484 | |
| 1485 | /* there are a lot of different devices that match, but not all respond |
| 1486 | * well to opening -- so limit some ones with issued updates */ |
| 1487 | if (fu_device_has_flag (dev, FWUPD_DEVICE_FLAG_ONLY_SUPPORTED)) { |
| 1488 | if (!fu_device_probe (dev, error)) |
| 1489 | return FALSE; |
| 1490 | fu_device_convert_instance_ids (dev); |
| 1491 | if (!fu_plugin_check_supported_device (self, dev)) { |
| 1492 | g_autofree gchar *guids = fu_device_get_guids_as_str (dev); |
| 1493 | g_debug ("%s has no updates, so ignoring device", guids); |
| 1494 | return TRUE; |
| 1495 | } |
| 1496 | } |
| 1497 | |
| 1498 | /* open and add */ |
| 1499 | locker = fu_device_locker_new (dev, error); |
| 1500 | if (locker == NULL) |
| 1501 | return FALSE; |
| 1502 | fu_plugin_device_add (self, dev); |
| 1503 | return TRUE; |
| 1504 | } |
| 1505 | |
| 1506 | static gboolean |
| 1507 | fu_plugin_udev_device_added (FuPlugin *self, FuUdevDevice *device, GError **error) |
| 1508 | { |
| 1509 | FuPluginPrivate *priv = GET_PRIVATE (self); |
| 1510 | GType device_gtype = fu_device_get_specialized_gtype (FU_DEVICE (device)); |
| 1511 | g_autoptr(FuDevice) dev = NULL; |
| 1512 | g_autoptr(FuDeviceLocker) locker = NULL; |
| 1513 | |
| 1514 | /* fall back to plugin default */ |
| 1515 | if (device_gtype == G_TYPE_INVALID) |
| 1516 | device_gtype = priv->device_gtype; |
| 1517 | |
| 1518 | /* create new device and incorporate existing properties */ |
| 1519 | dev = g_object_new (device_gtype, NULL); |
Richard Hughes | 989acf1 | 2019-10-05 20:16:47 +0100 | [diff] [blame] | 1520 | fu_device_incorporate (FU_DEVICE (dev), FU_DEVICE (device)); |
Richard Hughes | d8a8d5e | 2019-10-08 13:05:02 +0100 | [diff] [blame] | 1521 | |
| 1522 | /* there are a lot of different devices that match, but not all respond |
| 1523 | * well to opening -- so limit some ones with issued updates */ |
| 1524 | if (fu_device_has_flag (dev, FWUPD_DEVICE_FLAG_ONLY_SUPPORTED)) { |
| 1525 | if (!fu_device_probe (dev, error)) |
| 1526 | return FALSE; |
| 1527 | fu_device_convert_instance_ids (dev); |
| 1528 | if (!fu_plugin_check_supported_device (self, dev)) { |
| 1529 | g_autofree gchar *guids = fu_device_get_guids_as_str (dev); |
| 1530 | g_debug ("%s has no updates, so ignoring device", guids); |
| 1531 | return TRUE; |
| 1532 | } |
| 1533 | } |
| 1534 | |
| 1535 | /* open and add */ |
Richard Hughes | 989acf1 | 2019-10-05 20:16:47 +0100 | [diff] [blame] | 1536 | locker = fu_device_locker_new (dev, error); |
| 1537 | if (locker == NULL) |
| 1538 | return FALSE; |
| 1539 | fu_plugin_device_add (self, FU_DEVICE (dev)); |
| 1540 | return TRUE; |
| 1541 | } |
| 1542 | |
Richard Hughes | 104f651 | 2017-11-24 11:44:57 +0000 | [diff] [blame] | 1543 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1544 | fu_plugin_runner_usb_device_added (FuPlugin *self, FuUsbDevice *device, GError **error) |
Richard Hughes | 104f651 | 2017-11-24 11:44:57 +0000 | [diff] [blame] | 1545 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1546 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 104f651 | 2017-11-24 11:44:57 +0000 | [diff] [blame] | 1547 | FuPluginUsbDeviceAddedFunc func = NULL; |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1548 | g_autoptr(GError) error_local = NULL; |
Richard Hughes | 104f651 | 2017-11-24 11:44:57 +0000 | [diff] [blame] | 1549 | |
| 1550 | /* not enabled */ |
| 1551 | if (!priv->enabled) |
| 1552 | return TRUE; |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 1553 | |
| 1554 | /* no object loaded */ |
Richard Hughes | 104f651 | 2017-11-24 11:44:57 +0000 | [diff] [blame] | 1555 | if (priv->module == NULL) |
| 1556 | return TRUE; |
| 1557 | |
| 1558 | /* optional */ |
| 1559 | g_module_symbol (priv->module, "fu_plugin_usb_device_added", (gpointer *) &func); |
Richard Hughes | 989acf1 | 2019-10-05 20:16:47 +0100 | [diff] [blame] | 1560 | if (func == NULL) { |
Richard Hughes | d8a8d5e | 2019-10-08 13:05:02 +0100 | [diff] [blame] | 1561 | if (priv->device_gtype != G_TYPE_INVALID || |
| 1562 | fu_device_get_specialized_gtype (FU_DEVICE (device)) != G_TYPE_INVALID) { |
Mario Limonciello | 0e50032 | 2019-10-17 18:41:04 -0500 | [diff] [blame] | 1563 | if (!fu_plugin_usb_device_added (self, device, error)) |
Mario Limonciello | a9be536 | 2019-10-12 13:17:45 -0500 | [diff] [blame] | 1564 | return FALSE; |
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 | return TRUE; |
Richard Hughes | 989acf1 | 2019-10-05 20:16:47 +0100 | [diff] [blame] | 1567 | } |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1568 | g_debug ("performing usb_device_added() on %s", priv->name); |
| 1569 | if (!func (self, device, &error_local)) { |
| 1570 | if (error_local == NULL) { |
| 1571 | g_critical ("unset error in plugin %s for usb_device_added()", |
| 1572 | priv->name); |
| 1573 | g_set_error_literal (&error_local, |
| 1574 | FWUPD_ERROR, |
| 1575 | FWUPD_ERROR_INTERNAL, |
| 1576 | "unspecified error"); |
| 1577 | } |
| 1578 | g_propagate_prefixed_error (error, g_steal_pointer (&error_local), |
| 1579 | "failed to add device using on %s: ", |
| 1580 | priv->name); |
| 1581 | return FALSE; |
Richard Hughes | 104f651 | 2017-11-24 11:44:57 +0000 | [diff] [blame] | 1582 | } |
| 1583 | return TRUE; |
| 1584 | } |
| 1585 | |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 1586 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1587 | fu_plugin_runner_udev_device_added (FuPlugin *self, FuUdevDevice *device, GError **error) |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 1588 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1589 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 1590 | FuPluginUdevDeviceAddedFunc func = NULL; |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1591 | g_autoptr(GError) error_local = NULL; |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 1592 | |
| 1593 | /* not enabled */ |
| 1594 | if (!priv->enabled) |
| 1595 | return TRUE; |
| 1596 | |
| 1597 | /* no object loaded */ |
| 1598 | if (priv->module == NULL) |
| 1599 | return TRUE; |
| 1600 | |
| 1601 | /* optional */ |
| 1602 | g_module_symbol (priv->module, "fu_plugin_udev_device_added", (gpointer *) &func); |
Richard Hughes | d8a8d5e | 2019-10-08 13:05:02 +0100 | [diff] [blame] | 1603 | if (func == NULL) { |
| 1604 | if (priv->device_gtype != G_TYPE_INVALID || |
| 1605 | fu_device_get_specialized_gtype (FU_DEVICE (device)) != G_TYPE_INVALID) { |
Mario Limonciello | 0e50032 | 2019-10-17 18:41:04 -0500 | [diff] [blame] | 1606 | if (!fu_plugin_udev_device_added (self, device, error)) |
Mario Limonciello | a9be536 | 2019-10-12 13:17:45 -0500 | [diff] [blame] | 1607 | return FALSE; |
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 | return TRUE; |
Richard Hughes | d8a8d5e | 2019-10-08 13:05:02 +0100 | [diff] [blame] | 1610 | } |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1611 | g_debug ("performing udev_device_added() on %s", priv->name); |
| 1612 | if (!func (self, device, &error_local)) { |
| 1613 | if (error_local == NULL) { |
| 1614 | g_critical ("unset error in plugin %s for udev_device_added()", |
| 1615 | priv->name); |
| 1616 | g_set_error_literal (&error_local, |
| 1617 | FWUPD_ERROR, |
| 1618 | FWUPD_ERROR_INTERNAL, |
| 1619 | "unspecified error"); |
| 1620 | } |
| 1621 | g_propagate_prefixed_error (error, g_steal_pointer (&error_local), |
| 1622 | "failed to add device using on %s: ", |
| 1623 | priv->name); |
| 1624 | return FALSE; |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 1625 | } |
| 1626 | return TRUE; |
| 1627 | } |
| 1628 | |
Richard Hughes | 5e952ce | 2019-08-26 11:09:46 +0100 | [diff] [blame] | 1629 | gboolean |
| 1630 | fu_plugin_runner_udev_device_changed (FuPlugin *self, FuUdevDevice *device, GError **error) |
| 1631 | { |
| 1632 | FuPluginPrivate *priv = GET_PRIVATE (self); |
| 1633 | FuPluginUdevDeviceAddedFunc func = NULL; |
| 1634 | g_autoptr(GError) error_local = NULL; |
| 1635 | |
| 1636 | /* not enabled */ |
| 1637 | if (!priv->enabled) |
| 1638 | return TRUE; |
| 1639 | |
| 1640 | /* no object loaded */ |
| 1641 | if (priv->module == NULL) |
| 1642 | return TRUE; |
| 1643 | |
| 1644 | /* optional */ |
| 1645 | g_module_symbol (priv->module, "fu_plugin_udev_device_changed", (gpointer *) &func); |
| 1646 | if (func == NULL) |
| 1647 | return TRUE; |
| 1648 | g_debug ("performing udev_device_changed() on %s", priv->name); |
| 1649 | if (!func (self, device, &error_local)) { |
| 1650 | if (error_local == NULL) { |
| 1651 | g_critical ("unset error in plugin %s for udev_device_changed()", |
| 1652 | priv->name); |
| 1653 | g_set_error_literal (&error_local, |
| 1654 | FWUPD_ERROR, |
| 1655 | FWUPD_ERROR_INTERNAL, |
| 1656 | "unspecified error"); |
| 1657 | } |
| 1658 | g_propagate_prefixed_error (error, g_steal_pointer (&error_local), |
| 1659 | "failed to change device on %s: ", |
| 1660 | priv->name); |
| 1661 | return FALSE; |
| 1662 | } |
| 1663 | return TRUE; |
| 1664 | } |
| 1665 | |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 1666 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1667 | fu_plugin_runner_device_removed (FuPlugin *self, FuDevice *device) |
Mario Limonciello | e260ead | 2018-09-01 09:19:24 -0500 | [diff] [blame] | 1668 | { |
| 1669 | g_autoptr(GError) error_local= NULL; |
| 1670 | |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1671 | if (!fu_plugin_runner_device_generic (self, device, |
Mario Limonciello | e260ead | 2018-09-01 09:19:24 -0500 | [diff] [blame] | 1672 | "fu_plugin_device_removed", |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 1673 | NULL, |
Mario Limonciello | e260ead | 2018-09-01 09:19:24 -0500 | [diff] [blame] | 1674 | &error_local)) |
| 1675 | g_warning ("%s", error_local->message); |
| 1676 | } |
| 1677 | |
| 1678 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1679 | fu_plugin_runner_device_register (FuPlugin *self, FuDevice *device) |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 1680 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1681 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 1682 | FuPluginDeviceRegisterFunc func = NULL; |
| 1683 | |
| 1684 | /* not enabled */ |
| 1685 | if (!priv->enabled) |
| 1686 | return; |
Richard Hughes | 3483410 | 2017-11-21 21:55:00 +0000 | [diff] [blame] | 1687 | if (priv->module == NULL) |
| 1688 | return; |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 1689 | |
Mario Limonciello | 4910b24 | 2018-06-22 15:04:21 -0500 | [diff] [blame] | 1690 | /* don't notify plugins on their own devices */ |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1691 | 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] | 1692 | return; |
| 1693 | |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 1694 | /* optional */ |
| 1695 | g_module_symbol (priv->module, "fu_plugin_device_registered", (gpointer *) &func); |
| 1696 | if (func != NULL) { |
Richard Hughes | 1bf7ff9 | 2018-08-24 20:21:35 +0100 | [diff] [blame] | 1697 | g_debug ("performing fu_plugin_device_registered() on %s", priv->name); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1698 | func (self, device); |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 1699 | } |
| 1700 | } |
| 1701 | |
Richard Hughes | c6c312f | 2019-02-01 16:37:14 +0000 | [diff] [blame] | 1702 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1703 | fu_plugin_runner_schedule_update (FuPlugin *self, |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1704 | FuDevice *device, |
Richard Hughes | 994b4d9 | 2019-03-25 14:28:30 +0000 | [diff] [blame] | 1705 | FwupdRelease *release, |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1706 | GBytes *blob_cab, |
Richard Hughes | 5cbb5cf | 2019-04-26 16:48:03 +0100 | [diff] [blame] | 1707 | FwupdInstallFlags flags, |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1708 | GError **error) |
| 1709 | { |
Richard Hughes | 0a90626 | 2019-05-16 13:38:47 +0100 | [diff] [blame] | 1710 | gchar tmpname[] = {"XXXXXX.cab"}; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1711 | g_autofree gchar *dirname = NULL; |
| 1712 | g_autofree gchar *filename = NULL; |
Richard Hughes | 780ef3f | 2018-01-12 16:20:31 +0000 | [diff] [blame] | 1713 | g_autoptr(FuHistory) history = NULL; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1714 | g_autoptr(GFile) file = NULL; |
| 1715 | |
| 1716 | /* id already exists */ |
Richard Hughes | 780ef3f | 2018-01-12 16:20:31 +0000 | [diff] [blame] | 1717 | history = fu_history_new (); |
Richard Hughes | 5cbb5cf | 2019-04-26 16:48:03 +0100 | [diff] [blame] | 1718 | if ((flags & FWUPD_INSTALL_FLAG_FORCE) == 0) { |
| 1719 | g_autoptr(FuDevice) res_tmp = NULL; |
| 1720 | res_tmp = fu_history_get_device_by_id (history, fu_device_get_id (device), NULL); |
| 1721 | if (res_tmp != NULL && |
| 1722 | fu_device_get_update_state (res_tmp) == FWUPD_UPDATE_STATE_PENDING) { |
| 1723 | g_set_error (error, |
| 1724 | FWUPD_ERROR, |
| 1725 | FWUPD_ERROR_ALREADY_PENDING, |
| 1726 | "%s is already scheduled to be updated", |
| 1727 | fu_device_get_id (device)); |
| 1728 | return FALSE; |
| 1729 | } |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1730 | } |
| 1731 | |
| 1732 | /* create directory */ |
Richard Hughes | 4be17d1 | 2018-05-30 20:36:29 +0100 | [diff] [blame] | 1733 | dirname = fu_common_get_path (FU_PATH_KIND_LOCALSTATEDIR_PKG); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1734 | file = g_file_new_for_path (dirname); |
| 1735 | if (!g_file_query_exists (file, NULL)) { |
| 1736 | if (!g_file_make_directory_with_parents (file, NULL, error)) |
| 1737 | return FALSE; |
| 1738 | } |
| 1739 | |
| 1740 | /* get a random filename */ |
| 1741 | for (guint i = 0; i < 6; i++) |
| 1742 | tmpname[i] = (gchar) g_random_int_range ('A', 'Z'); |
| 1743 | filename = g_build_filename (dirname, tmpname, NULL); |
| 1744 | |
| 1745 | /* just copy to the temp file */ |
Richard Hughes | 23135eb | 2017-11-30 21:01:25 +0000 | [diff] [blame] | 1746 | fu_device_set_status (device, FWUPD_STATUS_SCHEDULING); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1747 | if (!g_file_set_contents (filename, |
| 1748 | g_bytes_get_data (blob_cab, NULL), |
| 1749 | (gssize) g_bytes_get_size (blob_cab), |
| 1750 | error)) |
| 1751 | return FALSE; |
| 1752 | |
| 1753 | /* schedule for next boot */ |
| 1754 | g_debug ("schedule %s to be installed to %s on next boot", |
| 1755 | filename, fu_device_get_id (device)); |
Richard Hughes | 994b4d9 | 2019-03-25 14:28:30 +0000 | [diff] [blame] | 1756 | fwupd_release_set_filename (release, filename); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1757 | |
| 1758 | /* add to database */ |
Richard Hughes | 809abea | 2019-03-23 11:06:18 +0000 | [diff] [blame] | 1759 | fu_device_add_flag (device, FWUPD_DEVICE_FLAG_NEEDS_REBOOT); |
Richard Hughes | 3e90a58 | 2018-01-06 22:38:09 +0000 | [diff] [blame] | 1760 | fu_device_set_update_state (device, FWUPD_UPDATE_STATE_PENDING); |
Richard Hughes | 994b4d9 | 2019-03-25 14:28:30 +0000 | [diff] [blame] | 1761 | if (!fu_history_add_device (history, device, release, error)) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1762 | return FALSE; |
| 1763 | |
| 1764 | /* next boot we run offline */ |
Richard Hughes | db69c81 | 2019-03-22 16:10:15 +0000 | [diff] [blame] | 1765 | fu_device_set_progress (device, 100); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1766 | return fu_plugin_runner_offline_setup (error); |
| 1767 | } |
| 1768 | |
| 1769 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1770 | fu_plugin_runner_verify (FuPlugin *self, |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1771 | FuDevice *device, |
| 1772 | FuPluginVerifyFlags flags, |
| 1773 | GError **error) |
| 1774 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1775 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 1776 | FuPluginVerifyFunc func = NULL; |
Richard Hughes | ababbb7 | 2017-06-15 20:18:36 +0100 | [diff] [blame] | 1777 | GPtrArray *checksums; |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1778 | g_autoptr(GError) error_local = NULL; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1779 | |
| 1780 | /* not enabled */ |
| 1781 | if (!priv->enabled) |
| 1782 | return TRUE; |
| 1783 | |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 1784 | /* no object loaded */ |
| 1785 | if (priv->module == NULL) |
| 1786 | return TRUE; |
| 1787 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1788 | /* optional */ |
| 1789 | g_module_symbol (priv->module, "fu_plugin_verify", (gpointer *) &func); |
Richard Hughes | 7f67721 | 2019-10-05 16:19:40 +0100 | [diff] [blame] | 1790 | if (func == NULL) { |
Richard Hughes | 7f67721 | 2019-10-05 16:19:40 +0100 | [diff] [blame] | 1791 | return fu_plugin_device_read_firmware (self, device, error); |
| 1792 | } |
Richard Hughes | 1812fc7 | 2018-12-14 11:37:54 +0000 | [diff] [blame] | 1793 | |
| 1794 | /* clear any existing verification checksums */ |
| 1795 | checksums = fu_device_get_checksums (device); |
| 1796 | g_ptr_array_set_size (checksums, 0); |
| 1797 | |
Richard Hughes | c9223be | 2019-03-18 08:46:42 +0000 | [diff] [blame] | 1798 | /* run additional detach */ |
| 1799 | if (!fu_plugin_runner_device_generic (self, device, |
Richard Hughes | 42f33df | 2019-10-05 20:52:33 +0100 | [diff] [blame] | 1800 | "fu_plugin_update_detach", |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 1801 | fu_plugin_device_detach, |
Richard Hughes | c9223be | 2019-03-18 08:46:42 +0000 | [diff] [blame] | 1802 | error)) |
| 1803 | return FALSE; |
| 1804 | |
Richard Hughes | 1812fc7 | 2018-12-14 11:37:54 +0000 | [diff] [blame] | 1805 | /* run vfunc */ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1806 | g_debug ("performing verify() on %s", priv->name); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1807 | if (!func (self, device, flags, &error_local)) { |
Richard Hughes | c9223be | 2019-03-18 08:46:42 +0000 | [diff] [blame] | 1808 | g_autoptr(GError) error_attach = NULL; |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1809 | if (error_local == NULL) { |
| 1810 | g_critical ("unset error in plugin %s for verify()", |
| 1811 | priv->name); |
| 1812 | g_set_error_literal (&error_local, |
| 1813 | FWUPD_ERROR, |
| 1814 | FWUPD_ERROR_INTERNAL, |
| 1815 | "unspecified error"); |
| 1816 | } |
| 1817 | g_propagate_prefixed_error (error, g_steal_pointer (&error_local), |
| 1818 | "failed to verify using %s: ", |
| 1819 | priv->name); |
Richard Hughes | c9223be | 2019-03-18 08:46:42 +0000 | [diff] [blame] | 1820 | /* make the device "work" again, but don't prefix the error */ |
| 1821 | if (!fu_plugin_runner_device_generic (self, device, |
Richard Hughes | 42f33df | 2019-10-05 20:52:33 +0100 | [diff] [blame] | 1822 | "fu_plugin_update_attach", |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 1823 | fu_plugin_device_attach, |
Richard Hughes | c9223be | 2019-03-18 08:46:42 +0000 | [diff] [blame] | 1824 | &error_attach)) { |
| 1825 | g_warning ("failed to attach whilst aborting verify(): %s", |
| 1826 | error_attach->message); |
| 1827 | } |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1828 | return FALSE; |
| 1829 | } |
Richard Hughes | c9223be | 2019-03-18 08:46:42 +0000 | [diff] [blame] | 1830 | |
| 1831 | /* run optional attach */ |
| 1832 | if (!fu_plugin_runner_device_generic (self, device, |
Richard Hughes | 42f33df | 2019-10-05 20:52:33 +0100 | [diff] [blame] | 1833 | "fu_plugin_update_attach", |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 1834 | fu_plugin_device_attach, |
Richard Hughes | c9223be | 2019-03-18 08:46:42 +0000 | [diff] [blame] | 1835 | error)) |
| 1836 | return FALSE; |
| 1837 | |
| 1838 | /* success */ |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1839 | return TRUE; |
| 1840 | } |
| 1841 | |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1842 | gboolean |
Mario Limonciello | 96a0dd5 | 2019-02-25 13:50:03 -0600 | [diff] [blame] | 1843 | fu_plugin_runner_activate (FuPlugin *self, FuDevice *device, GError **error) |
| 1844 | { |
| 1845 | guint64 flags; |
| 1846 | |
| 1847 | /* final check */ |
| 1848 | flags = fu_device_get_flags (device); |
| 1849 | if ((flags & FWUPD_DEVICE_FLAG_NEEDS_ACTIVATION) == 0) { |
| 1850 | g_set_error (error, |
| 1851 | FWUPD_ERROR, |
| 1852 | FWUPD_ERROR_NOT_SUPPORTED, |
| 1853 | "Device %s does not need activation", |
| 1854 | fu_device_get_id (device)); |
| 1855 | return FALSE; |
| 1856 | } |
| 1857 | |
| 1858 | /* run vfunc */ |
| 1859 | if (!fu_plugin_runner_device_generic (self, device, |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 1860 | "fu_plugin_activate", |
| 1861 | fu_plugin_device_activate, |
| 1862 | error)) |
Mario Limonciello | 96a0dd5 | 2019-02-25 13:50:03 -0600 | [diff] [blame] | 1863 | return FALSE; |
| 1864 | |
| 1865 | /* update with correct flags */ |
| 1866 | fu_device_remove_flag (device, FWUPD_DEVICE_FLAG_NEEDS_ACTIVATION); |
| 1867 | fu_device_set_modified (device, (guint64) g_get_real_time () / G_USEC_PER_SEC); |
| 1868 | return TRUE; |
| 1869 | } |
| 1870 | |
| 1871 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1872 | fu_plugin_runner_unlock (FuPlugin *self, FuDevice *device, GError **error) |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1873 | { |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1874 | guint64 flags; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1875 | |
| 1876 | /* final check */ |
| 1877 | flags = fu_device_get_flags (device); |
| 1878 | if ((flags & FWUPD_DEVICE_FLAG_LOCKED) == 0) { |
| 1879 | g_set_error (error, |
| 1880 | FWUPD_ERROR, |
| 1881 | FWUPD_ERROR_NOT_SUPPORTED, |
| 1882 | "Device %s is not locked", |
| 1883 | fu_device_get_id (device)); |
| 1884 | return FALSE; |
| 1885 | } |
| 1886 | |
Richard Hughes | 9c4b531 | 2017-11-14 11:34:53 +0000 | [diff] [blame] | 1887 | /* run vfunc */ |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1888 | if (!fu_plugin_runner_device_generic (self, device, |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 1889 | "fu_plugin_unlock", |
| 1890 | NULL, |
| 1891 | error)) |
Richard Hughes | 9c4b531 | 2017-11-14 11:34:53 +0000 | [diff] [blame] | 1892 | return FALSE; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1893 | |
| 1894 | /* update with correct flags */ |
| 1895 | flags = fu_device_get_flags (device); |
| 1896 | fu_device_set_flags (device, flags &= ~FWUPD_DEVICE_FLAG_LOCKED); |
| 1897 | fu_device_set_modified (device, (guint64) g_get_real_time () / G_USEC_PER_SEC); |
| 1898 | return TRUE; |
| 1899 | } |
| 1900 | |
| 1901 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1902 | fu_plugin_runner_update (FuPlugin *self, |
Richard Hughes | a785a1c | 2017-08-25 16:00:58 +0100 | [diff] [blame] | 1903 | FuDevice *device, |
Richard Hughes | a785a1c | 2017-08-25 16:00:58 +0100 | [diff] [blame] | 1904 | GBytes *blob_fw, |
| 1905 | FwupdInstallFlags flags, |
| 1906 | GError **error) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1907 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1908 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | a785a1c | 2017-08-25 16:00:58 +0100 | [diff] [blame] | 1909 | FuPluginUpdateFunc update_func; |
Richard Hughes | 780ef3f | 2018-01-12 16:20:31 +0000 | [diff] [blame] | 1910 | g_autoptr(FuHistory) history = NULL; |
Richard Hughes | 68982c6 | 2017-09-13 15:40:14 +0100 | [diff] [blame] | 1911 | g_autoptr(FuDevice) device_pending = NULL; |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1912 | g_autoptr(GError) error_local = NULL; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1913 | |
| 1914 | /* not enabled */ |
Richard Hughes | 41c1548 | 2018-02-01 22:07:21 +0000 | [diff] [blame] | 1915 | if (!priv->enabled) { |
| 1916 | g_debug ("plugin not enabled, skipping"); |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1917 | return TRUE; |
Richard Hughes | 41c1548 | 2018-02-01 22:07:21 +0000 | [diff] [blame] | 1918 | } |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1919 | |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 1920 | /* no object loaded */ |
Richard Hughes | 41c1548 | 2018-02-01 22:07:21 +0000 | [diff] [blame] | 1921 | if (priv->module == NULL) { |
| 1922 | g_debug ("module not enabled, skipping"); |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 1923 | return TRUE; |
Richard Hughes | 41c1548 | 2018-02-01 22:07:21 +0000 | [diff] [blame] | 1924 | } |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 1925 | |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1926 | /* optional */ |
Richard Hughes | a785a1c | 2017-08-25 16:00:58 +0100 | [diff] [blame] | 1927 | g_module_symbol (priv->module, "fu_plugin_update", (gpointer *) &update_func); |
| 1928 | if (update_func == NULL) { |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 1929 | g_debug ("running superclassed write_firmware() on %s", priv->name); |
| 1930 | return fu_plugin_device_write_firmware (self, device, blob_fw, flags, error); |
Richard Hughes | a785a1c | 2017-08-25 16:00:58 +0100 | [diff] [blame] | 1931 | } |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1932 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1933 | /* cancel the pending action */ |
| 1934 | if (!fu_plugin_runner_offline_invalidate (error)) |
| 1935 | return FALSE; |
| 1936 | |
| 1937 | /* online */ |
Richard Hughes | 780ef3f | 2018-01-12 16:20:31 +0000 | [diff] [blame] | 1938 | history = fu_history_new (); |
Richard Hughes | 0b9d996 | 2018-01-12 16:31:28 +0000 | [diff] [blame] | 1939 | 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] | 1940 | if (!update_func (self, device, blob_fw, flags, &error_local)) { |
| 1941 | if (error_local == NULL) { |
| 1942 | g_critical ("unset error in plugin %s for update()", |
| 1943 | priv->name); |
| 1944 | g_set_error_literal (&error_local, |
Richard Hughes | 3c8ada3 | 2018-10-12 10:08:58 +0100 | [diff] [blame] | 1945 | FWUPD_ERROR, |
| 1946 | FWUPD_ERROR_INTERNAL, |
| 1947 | "unspecified error"); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1948 | return FALSE; |
Richard Hughes | 3c8ada3 | 2018-10-12 10:08:58 +0100 | [diff] [blame] | 1949 | } |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1950 | fu_device_set_update_error (device, error_local->message); |
| 1951 | g_propagate_error (error, g_steal_pointer (&error_local)); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1952 | return FALSE; |
| 1953 | } |
| 1954 | |
Richard Hughes | f556d37 | 2017-06-15 19:49:18 +0100 | [diff] [blame] | 1955 | /* no longer valid */ |
Richard Hughes | f803964 | 2019-01-16 12:22:22 +0000 | [diff] [blame] | 1956 | if (!fu_device_has_flag (device, FWUPD_DEVICE_FLAG_NEEDS_REBOOT) && |
| 1957 | !fu_device_has_flag (device, FWUPD_DEVICE_FLAG_NEEDS_SHUTDOWN)) { |
Richard Hughes | 0843516 | 2018-12-12 10:34:16 +0000 | [diff] [blame] | 1958 | GPtrArray *checksums = fu_device_get_checksums (device); |
| 1959 | g_ptr_array_set_size (checksums, 0); |
| 1960 | } |
Richard Hughes | f556d37 | 2017-06-15 19:49:18 +0100 | [diff] [blame] | 1961 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1962 | /* cleanup */ |
Richard Hughes | 68982c6 | 2017-09-13 15:40:14 +0100 | [diff] [blame] | 1963 | if (device_pending != NULL) { |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1964 | const gchar *tmp; |
Richard Hughes | bc3a4e1 | 2018-01-06 22:41:47 +0000 | [diff] [blame] | 1965 | FwupdRelease *release; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1966 | |
Richard Hughes | 780ef3f | 2018-01-12 16:20:31 +0000 | [diff] [blame] | 1967 | /* update history database */ |
Richard Hughes | c0cd023 | 2018-01-31 15:02:00 +0000 | [diff] [blame] | 1968 | fu_device_set_update_state (device, FWUPD_UPDATE_STATE_SUCCESS); |
Richard Hughes | 0bbef29 | 2019-11-01 12:15:15 +0000 | [diff] [blame] | 1969 | if (!fu_history_modify_device (history, device, error)) |
Richard Hughes | 0b9d996 | 2018-01-12 16:31:28 +0000 | [diff] [blame] | 1970 | return FALSE; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1971 | |
| 1972 | /* delete cab file */ |
Richard Hughes | bc3a4e1 | 2018-01-06 22:41:47 +0000 | [diff] [blame] | 1973 | release = fu_device_get_release_default (device_pending); |
| 1974 | tmp = fwupd_release_get_filename (release); |
Richard Hughes | 668ee21 | 2019-11-22 09:17:46 +0000 | [diff] [blame] | 1975 | if (tmp != NULL && g_str_has_prefix (tmp, FWUPD_LIBEXECDIR)) { |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1976 | g_autoptr(GError) error_delete = NULL; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1977 | g_autoptr(GFile) file = NULL; |
| 1978 | file = g_file_new_for_path (tmp); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1979 | if (!g_file_delete (file, NULL, &error_delete)) { |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1980 | g_set_error (error, |
| 1981 | FWUPD_ERROR, |
| 1982 | FWUPD_ERROR_INVALID_FILE, |
| 1983 | "Failed to delete %s: %s", |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1984 | tmp, error_delete->message); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1985 | return FALSE; |
| 1986 | } |
| 1987 | } |
| 1988 | } |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1989 | return TRUE; |
| 1990 | } |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1991 | |
| 1992 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1993 | fu_plugin_runner_clear_results (FuPlugin *self, FuDevice *device, GError **error) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1994 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1995 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 1996 | FuPluginDeviceFunc func = NULL; |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1997 | g_autoptr(GError) error_local = NULL; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1998 | |
| 1999 | /* not enabled */ |
| 2000 | if (!priv->enabled) |
| 2001 | return TRUE; |
| 2002 | |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 2003 | /* no object loaded */ |
| 2004 | if (priv->module == NULL) |
| 2005 | return TRUE; |
| 2006 | |
Richard Hughes | 65e44ca | 2018-01-30 17:26:30 +0000 | [diff] [blame] | 2007 | /* optional */ |
Richard Hughes | cd64490 | 2019-11-01 12:35:17 +0000 | [diff] [blame] | 2008 | g_module_symbol (priv->module, "fu_plugin_clear_results", (gpointer *) &func); |
Richard Hughes | 65e44ca | 2018-01-30 17:26:30 +0000 | [diff] [blame] | 2009 | if (func == NULL) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2010 | return TRUE; |
Richard Hughes | 65e44ca | 2018-01-30 17:26:30 +0000 | [diff] [blame] | 2011 | g_debug ("performing clear_result() on %s", priv->name); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 2012 | if (!func (self, device, &error_local)) { |
| 2013 | if (error_local == NULL) { |
| 2014 | g_critical ("unset error in plugin %s for clear_result()", |
| 2015 | priv->name); |
| 2016 | g_set_error_literal (&error_local, |
| 2017 | FWUPD_ERROR, |
| 2018 | FWUPD_ERROR_INTERNAL, |
| 2019 | "unspecified error"); |
| 2020 | } |
| 2021 | g_propagate_prefixed_error (error, g_steal_pointer (&error_local), |
| 2022 | "failed to clear_result using %s: ", |
| 2023 | priv->name); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2024 | return FALSE; |
| 2025 | } |
Richard Hughes | 65e44ca | 2018-01-30 17:26:30 +0000 | [diff] [blame] | 2026 | return TRUE; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2027 | } |
| 2028 | |
| 2029 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2030 | fu_plugin_runner_get_results (FuPlugin *self, FuDevice *device, GError **error) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2031 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2032 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 2033 | FuPluginDeviceFunc func = NULL; |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 2034 | g_autoptr(GError) error_local = NULL; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2035 | |
| 2036 | /* not enabled */ |
| 2037 | if (!priv->enabled) |
| 2038 | return TRUE; |
| 2039 | |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 2040 | /* no object loaded */ |
| 2041 | if (priv->module == NULL) |
| 2042 | return TRUE; |
| 2043 | |
Richard Hughes | 65e44ca | 2018-01-30 17:26:30 +0000 | [diff] [blame] | 2044 | /* optional */ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2045 | g_module_symbol (priv->module, "fu_plugin_get_results", (gpointer *) &func); |
Richard Hughes | 65e44ca | 2018-01-30 17:26:30 +0000 | [diff] [blame] | 2046 | if (func == NULL) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2047 | return TRUE; |
Richard Hughes | 65e44ca | 2018-01-30 17:26:30 +0000 | [diff] [blame] | 2048 | g_debug ("performing get_results() on %s", priv->name); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 2049 | if (!func (self, device, &error_local)) { |
| 2050 | if (error_local == NULL) { |
| 2051 | g_critical ("unset error in plugin %s for get_results()", |
| 2052 | priv->name); |
| 2053 | g_set_error_literal (&error_local, |
| 2054 | FWUPD_ERROR, |
| 2055 | FWUPD_ERROR_INTERNAL, |
| 2056 | "unspecified error"); |
| 2057 | } |
| 2058 | g_propagate_prefixed_error (error, g_steal_pointer (&error_local), |
| 2059 | "failed to get_results using %s: ", |
| 2060 | priv->name); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2061 | return FALSE; |
| 2062 | } |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2063 | return TRUE; |
| 2064 | } |
| 2065 | |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2066 | /** |
| 2067 | * fu_plugin_get_order: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 2068 | * @self: a #FuPlugin |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2069 | * |
| 2070 | * Gets the plugin order, where higher numbers are run after lower |
| 2071 | * numbers. |
| 2072 | * |
| 2073 | * Returns: the integer value |
| 2074 | **/ |
| 2075 | guint |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2076 | fu_plugin_get_order (FuPlugin *self) |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2077 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2078 | FuPluginPrivate *priv = fu_plugin_get_instance_private (self); |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2079 | return priv->order; |
| 2080 | } |
| 2081 | |
| 2082 | /** |
| 2083 | * fu_plugin_set_order: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 2084 | * @self: a #FuPlugin |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2085 | * @order: a integer value |
| 2086 | * |
| 2087 | * Sets the plugin order, where higher numbers are run after lower |
| 2088 | * numbers. |
| 2089 | **/ |
| 2090 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2091 | fu_plugin_set_order (FuPlugin *self, guint order) |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2092 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2093 | FuPluginPrivate *priv = fu_plugin_get_instance_private (self); |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2094 | priv->order = order; |
| 2095 | } |
| 2096 | |
| 2097 | /** |
Richard Hughes | 81c427c | 2018-08-06 15:20:17 +0100 | [diff] [blame] | 2098 | * fu_plugin_get_priority: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 2099 | * @self: a #FuPlugin |
Richard Hughes | 81c427c | 2018-08-06 15:20:17 +0100 | [diff] [blame] | 2100 | * |
| 2101 | * Gets the plugin priority, where higher numbers are better. |
| 2102 | * |
| 2103 | * Returns: the integer value |
| 2104 | **/ |
| 2105 | guint |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2106 | fu_plugin_get_priority (FuPlugin *self) |
Richard Hughes | 81c427c | 2018-08-06 15:20:17 +0100 | [diff] [blame] | 2107 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2108 | FuPluginPrivate *priv = fu_plugin_get_instance_private (self); |
Richard Hughes | 81c427c | 2018-08-06 15:20:17 +0100 | [diff] [blame] | 2109 | return priv->priority; |
| 2110 | } |
| 2111 | |
| 2112 | /** |
| 2113 | * fu_plugin_set_priority: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 2114 | * @self: a #FuPlugin |
Richard Hughes | 81c427c | 2018-08-06 15:20:17 +0100 | [diff] [blame] | 2115 | * @priority: a integer value |
| 2116 | * |
| 2117 | * Sets the plugin priority, where higher numbers are better. |
| 2118 | **/ |
| 2119 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2120 | fu_plugin_set_priority (FuPlugin *self, guint priority) |
Richard Hughes | 81c427c | 2018-08-06 15:20:17 +0100 | [diff] [blame] | 2121 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2122 | FuPluginPrivate *priv = fu_plugin_get_instance_private (self); |
Richard Hughes | 81c427c | 2018-08-06 15:20:17 +0100 | [diff] [blame] | 2123 | priv->priority = priority; |
| 2124 | } |
| 2125 | |
| 2126 | /** |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2127 | * fu_plugin_add_rule: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 2128 | * @self: a #FuPlugin |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2129 | * @rule: a #FuPluginRule, e.g. %FU_PLUGIN_RULE_CONFLICTS |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 2130 | * @name: a plugin name, e.g. `upower` |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2131 | * |
| 2132 | * If the plugin name is found, the rule will be used to sort the plugin list, |
| 2133 | * for example the plugin specified by @name will be ordered after this plugin |
| 2134 | * when %FU_PLUGIN_RULE_RUN_AFTER is used. |
| 2135 | * |
| 2136 | * NOTE: The depsolver is iterative and may not solve overly-complicated rules; |
| 2137 | * If depsolving fails then fwupd will not start. |
| 2138 | **/ |
| 2139 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2140 | fu_plugin_add_rule (FuPlugin *self, FuPluginRule rule, const gchar *name) |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2141 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2142 | FuPluginPrivate *priv = fu_plugin_get_instance_private (self); |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2143 | g_ptr_array_add (priv->rules[rule], g_strdup (name)); |
Richard Hughes | 75b965d | 2018-11-15 13:51:21 +0000 | [diff] [blame] | 2144 | g_signal_emit (self, signals[SIGNAL_RULES_CHANGED], 0); |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2145 | } |
| 2146 | |
| 2147 | /** |
| 2148 | * fu_plugin_get_rules: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 2149 | * @self: a #FuPlugin |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2150 | * @rule: a #FuPluginRule, e.g. %FU_PLUGIN_RULE_CONFLICTS |
| 2151 | * |
| 2152 | * Gets the plugin IDs that should be run after this plugin. |
| 2153 | * |
| 2154 | * Returns: (element-type utf8) (transfer none): the list of plugin names, e.g. ['appstream'] |
| 2155 | **/ |
| 2156 | GPtrArray * |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2157 | fu_plugin_get_rules (FuPlugin *self, FuPluginRule rule) |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2158 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2159 | FuPluginPrivate *priv = fu_plugin_get_instance_private (self); |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2160 | return priv->rules[rule]; |
| 2161 | } |
| 2162 | |
Richard Hughes | 80b79bb | 2018-01-11 21:11:06 +0000 | [diff] [blame] | 2163 | /** |
Richard Hughes | 5f3a56b | 2018-06-28 12:13:59 +0100 | [diff] [blame] | 2164 | * fu_plugin_has_rule: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 2165 | * @self: a #FuPlugin |
Richard Hughes | 5f3a56b | 2018-06-28 12:13:59 +0100 | [diff] [blame] | 2166 | * @rule: a #FuPluginRule, e.g. %FU_PLUGIN_RULE_CONFLICTS |
| 2167 | * @name: a plugin name, e.g. `upower` |
| 2168 | * |
Richard Hughes | 87fb9ff | 2018-06-28 12:55:59 +0100 | [diff] [blame] | 2169 | * Gets the plugin IDs that should be run after this plugin. |
Richard Hughes | 5f3a56b | 2018-06-28 12:13:59 +0100 | [diff] [blame] | 2170 | * |
| 2171 | * Returns: %TRUE if the name exists for the specific rule |
| 2172 | **/ |
| 2173 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2174 | fu_plugin_has_rule (FuPlugin *self, FuPluginRule rule, const gchar *name) |
Richard Hughes | 5f3a56b | 2018-06-28 12:13:59 +0100 | [diff] [blame] | 2175 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2176 | FuPluginPrivate *priv = fu_plugin_get_instance_private (self); |
Richard Hughes | 5f3a56b | 2018-06-28 12:13:59 +0100 | [diff] [blame] | 2177 | for (guint i = 0; i < priv->rules[rule]->len; i++) { |
| 2178 | const gchar *tmp = g_ptr_array_index (priv->rules[rule], i); |
| 2179 | if (g_strcmp0 (tmp, name) == 0) |
| 2180 | return TRUE; |
| 2181 | } |
| 2182 | return FALSE; |
| 2183 | } |
| 2184 | |
| 2185 | /** |
Richard Hughes | 80b79bb | 2018-01-11 21:11:06 +0000 | [diff] [blame] | 2186 | * fu_plugin_add_report_metadata: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 2187 | * @self: a #FuPlugin |
Richard Hughes | 80b79bb | 2018-01-11 21:11:06 +0000 | [diff] [blame] | 2188 | * @key: a string, e.g. `FwupdateVersion` |
| 2189 | * @value: a string, e.g. `10` |
| 2190 | * |
| 2191 | * Sets any additional metadata to be included in the firmware report to aid |
| 2192 | * debugging problems. |
| 2193 | * |
| 2194 | * Any data included here will be sent to the metadata server after user |
| 2195 | * confirmation. |
| 2196 | **/ |
| 2197 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2198 | 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] | 2199 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2200 | FuPluginPrivate *priv = fu_plugin_get_instance_private (self); |
Richard Hughes | 80b79bb | 2018-01-11 21:11:06 +0000 | [diff] [blame] | 2201 | g_hash_table_insert (priv->report_metadata, g_strdup (key), g_strdup (value)); |
| 2202 | } |
| 2203 | |
| 2204 | /** |
| 2205 | * fu_plugin_get_report_metadata: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 2206 | * @self: a #FuPlugin |
Richard Hughes | 80b79bb | 2018-01-11 21:11:06 +0000 | [diff] [blame] | 2207 | * |
| 2208 | * Returns the list of additional metadata to be added when filing a report. |
| 2209 | * |
| 2210 | * Returns: (transfer none): the map of report metadata |
| 2211 | **/ |
| 2212 | GHashTable * |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2213 | fu_plugin_get_report_metadata (FuPlugin *self) |
Richard Hughes | 80b79bb | 2018-01-11 21:11:06 +0000 | [diff] [blame] | 2214 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2215 | FuPluginPrivate *priv = fu_plugin_get_instance_private (self); |
Richard Hughes | 80b79bb | 2018-01-11 21:11:06 +0000 | [diff] [blame] | 2216 | return priv->report_metadata; |
| 2217 | } |
| 2218 | |
Mario Limonciello | 963dc42 | 2018-02-27 14:26:58 -0600 | [diff] [blame] | 2219 | /** |
| 2220 | * fu_plugin_get_config_value: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 2221 | * @self: a #FuPlugin |
Mario Limonciello | 963dc42 | 2018-02-27 14:26:58 -0600 | [diff] [blame] | 2222 | * @key: A settings key |
| 2223 | * |
| 2224 | * Return the value of a key if it's been configured |
| 2225 | * |
| 2226 | * Since: 1.0.6 |
| 2227 | **/ |
| 2228 | gchar * |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2229 | fu_plugin_get_config_value (FuPlugin *self, const gchar *key) |
Mario Limonciello | 963dc42 | 2018-02-27 14:26:58 -0600 | [diff] [blame] | 2230 | { |
Richard Hughes | 4be17d1 | 2018-05-30 20:36:29 +0100 | [diff] [blame] | 2231 | g_autofree gchar *conf_dir = NULL; |
Mario Limonciello | 963dc42 | 2018-02-27 14:26:58 -0600 | [diff] [blame] | 2232 | g_autofree gchar *conf_file = NULL; |
| 2233 | g_autofree gchar *conf_path = NULL; |
| 2234 | g_autoptr(GKeyFile) keyfile = NULL; |
| 2235 | const gchar *plugin_name; |
| 2236 | |
Richard Hughes | 4be17d1 | 2018-05-30 20:36:29 +0100 | [diff] [blame] | 2237 | conf_dir = fu_common_get_path (FU_PATH_KIND_SYSCONFDIR_PKG); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2238 | plugin_name = fu_plugin_get_name (self); |
Mario Limonciello | 963dc42 | 2018-02-27 14:26:58 -0600 | [diff] [blame] | 2239 | conf_file = g_strdup_printf ("%s.conf", plugin_name); |
Richard Hughes | 4be17d1 | 2018-05-30 20:36:29 +0100 | [diff] [blame] | 2240 | conf_path = g_build_filename (conf_dir, conf_file, NULL); |
Mario Limonciello | 963dc42 | 2018-02-27 14:26:58 -0600 | [diff] [blame] | 2241 | if (!g_file_test (conf_path, G_FILE_TEST_IS_REGULAR)) |
| 2242 | return NULL; |
| 2243 | keyfile = g_key_file_new (); |
| 2244 | if (!g_key_file_load_from_file (keyfile, conf_path, |
| 2245 | G_KEY_FILE_NONE, NULL)) |
| 2246 | return NULL; |
| 2247 | return g_key_file_get_string (keyfile, plugin_name, key, NULL); |
| 2248 | } |
| 2249 | |
Richard Hughes | 8c71a3f | 2018-05-22 19:19:52 +0100 | [diff] [blame] | 2250 | /** |
| 2251 | * fu_plugin_name_compare: |
| 2252 | * @plugin1: first #FuPlugin to compare. |
| 2253 | * @plugin2: second #FuPlugin to compare. |
| 2254 | * |
| 2255 | * Compares two plugins by their names. |
| 2256 | * |
| 2257 | * Returns: 1, 0 or -1 if @plugin1 is greater, equal, or less than @plugin2. |
| 2258 | **/ |
| 2259 | gint |
| 2260 | fu_plugin_name_compare (FuPlugin *plugin1, FuPlugin *plugin2) |
| 2261 | { |
| 2262 | FuPluginPrivate *priv1 = fu_plugin_get_instance_private (plugin1); |
| 2263 | FuPluginPrivate *priv2 = fu_plugin_get_instance_private (plugin2); |
| 2264 | return g_strcmp0 (priv1->name, priv2->name); |
| 2265 | } |
| 2266 | |
| 2267 | /** |
| 2268 | * fu_plugin_order_compare: |
| 2269 | * @plugin1: first #FuPlugin to compare. |
| 2270 | * @plugin2: second #FuPlugin to compare. |
| 2271 | * |
| 2272 | * Compares two plugins by their depsolved order. |
| 2273 | * |
| 2274 | * Returns: 1, 0 or -1 if @plugin1 is greater, equal, or less than @plugin2. |
| 2275 | **/ |
| 2276 | gint |
| 2277 | fu_plugin_order_compare (FuPlugin *plugin1, FuPlugin *plugin2) |
| 2278 | { |
| 2279 | FuPluginPrivate *priv1 = fu_plugin_get_instance_private (plugin1); |
| 2280 | FuPluginPrivate *priv2 = fu_plugin_get_instance_private (plugin2); |
| 2281 | if (priv1->order < priv2->order) |
| 2282 | return -1; |
| 2283 | if (priv1->order > priv2->order) |
| 2284 | return 1; |
| 2285 | return 0; |
| 2286 | } |
| 2287 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2288 | static void |
| 2289 | fu_plugin_class_init (FuPluginClass *klass) |
| 2290 | { |
| 2291 | GObjectClass *object_class = G_OBJECT_CLASS (klass); |
| 2292 | object_class->finalize = fu_plugin_finalize; |
| 2293 | signals[SIGNAL_DEVICE_ADDED] = |
| 2294 | g_signal_new ("device-added", |
| 2295 | G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, |
| 2296 | G_STRUCT_OFFSET (FuPluginClass, device_added), |
| 2297 | NULL, NULL, g_cclosure_marshal_VOID__OBJECT, |
| 2298 | G_TYPE_NONE, 1, FU_TYPE_DEVICE); |
| 2299 | signals[SIGNAL_DEVICE_REMOVED] = |
| 2300 | g_signal_new ("device-removed", |
| 2301 | G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, |
| 2302 | G_STRUCT_OFFSET (FuPluginClass, device_removed), |
| 2303 | NULL, NULL, g_cclosure_marshal_VOID__OBJECT, |
| 2304 | G_TYPE_NONE, 1, FU_TYPE_DEVICE); |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 2305 | signals[SIGNAL_DEVICE_REGISTER] = |
| 2306 | g_signal_new ("device-register", |
| 2307 | G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, |
| 2308 | G_STRUCT_OFFSET (FuPluginClass, device_register), |
| 2309 | NULL, NULL, g_cclosure_marshal_VOID__OBJECT, |
| 2310 | G_TYPE_NONE, 1, FU_TYPE_DEVICE); |
Richard Hughes | 362d6d7 | 2017-01-07 21:42:14 +0000 | [diff] [blame] | 2311 | signals[SIGNAL_RECOLDPLUG] = |
| 2312 | g_signal_new ("recoldplug", |
| 2313 | G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, |
| 2314 | G_STRUCT_OFFSET (FuPluginClass, recoldplug), |
| 2315 | NULL, NULL, g_cclosure_marshal_VOID__VOID, |
| 2316 | G_TYPE_NONE, 0); |
Richard Hughes | b082903 | 2017-01-10 09:27:08 +0000 | [diff] [blame] | 2317 | signals[SIGNAL_SET_COLDPLUG_DELAY] = |
| 2318 | g_signal_new ("set-coldplug-delay", |
| 2319 | G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, |
| 2320 | G_STRUCT_OFFSET (FuPluginClass, set_coldplug_delay), |
| 2321 | NULL, NULL, g_cclosure_marshal_VOID__UINT, |
| 2322 | G_TYPE_NONE, 1, G_TYPE_UINT); |
Richard Hughes | aabdc37 | 2018-11-14 10:11:08 +0000 | [diff] [blame] | 2323 | signals[SIGNAL_CHECK_SUPPORTED] = |
| 2324 | g_signal_new ("check-supported", |
| 2325 | G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, |
| 2326 | G_STRUCT_OFFSET (FuPluginClass, check_supported), |
| 2327 | NULL, NULL, g_cclosure_marshal_generic, |
| 2328 | G_TYPE_BOOLEAN, 1, G_TYPE_STRING); |
Richard Hughes | 75b965d | 2018-11-15 13:51:21 +0000 | [diff] [blame] | 2329 | signals[SIGNAL_RULES_CHANGED] = |
| 2330 | g_signal_new ("rules-changed", |
| 2331 | G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, |
| 2332 | G_STRUCT_OFFSET (FuPluginClass, rules_changed), |
| 2333 | NULL, NULL, g_cclosure_marshal_VOID__VOID, |
| 2334 | G_TYPE_NONE, 0); |
Richard Hughes | 95c98a9 | 2019-10-22 16:03:15 +0100 | [diff] [blame] | 2335 | signals[SIGNAL_ADD_FIRMWARE_GTYPE] = |
| 2336 | g_signal_new ("add-firmware-gtype", |
| 2337 | G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, |
| 2338 | G_STRUCT_OFFSET (FuPluginClass, add_firmware_gtype), |
| 2339 | NULL, NULL, g_cclosure_marshal_generic, |
| 2340 | G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_GTYPE); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2341 | } |
| 2342 | |
| 2343 | static void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2344 | fu_plugin_init (FuPlugin *self) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2345 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2346 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2347 | priv->enabled = TRUE; |
Richard Hughes | b106542 | 2019-08-15 16:44:34 +0100 | [diff] [blame] | 2348 | priv->udev_subsystems = g_ptr_array_new_with_free_func (g_free); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2349 | priv->devices = g_hash_table_new_full (g_str_hash, g_str_equal, |
| 2350 | g_free, (GDestroyNotify) g_object_unref); |
Richard Hughes | 161e9b5 | 2019-06-12 14:22:45 +0100 | [diff] [blame] | 2351 | g_rw_lock_init (&priv->devices_mutex); |
Richard Hughes | 80b79bb | 2018-01-11 21:11:06 +0000 | [diff] [blame] | 2352 | 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] | 2353 | for (guint i = 0; i < FU_PLUGIN_RULE_LAST; i++) |
| 2354 | priv->rules[i] = g_ptr_array_new_with_free_func (g_free); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2355 | } |
| 2356 | |
| 2357 | static void |
| 2358 | fu_plugin_finalize (GObject *object) |
| 2359 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2360 | FuPlugin *self = FU_PLUGIN (object); |
| 2361 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2362 | FuPluginInitFunc func = NULL; |
| 2363 | |
| 2364 | /* optional */ |
| 2365 | if (priv->module != NULL) { |
| 2366 | g_module_symbol (priv->module, "fu_plugin_destroy", (gpointer *) &func); |
| 2367 | if (func != NULL) { |
| 2368 | g_debug ("performing destroy() on %s", priv->name); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2369 | func (self); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2370 | } |
| 2371 | } |
| 2372 | |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2373 | for (guint i = 0; i < FU_PLUGIN_RULE_LAST; i++) |
| 2374 | g_ptr_array_unref (priv->rules[i]); |
| 2375 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2376 | if (priv->usb_ctx != NULL) |
| 2377 | g_object_unref (priv->usb_ctx); |
Richard Hughes | b8f8db2 | 2017-04-25 15:56:00 +0100 | [diff] [blame] | 2378 | if (priv->hwids != NULL) |
Richard Hughes | d7704d4 | 2017-08-08 20:29:09 +0100 | [diff] [blame] | 2379 | g_object_unref (priv->hwids); |
Richard Hughes | 9c028f0 | 2017-10-28 21:14:28 +0100 | [diff] [blame] | 2380 | if (priv->quirks != NULL) |
| 2381 | g_object_unref (priv->quirks); |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 2382 | if (priv->udev_subsystems != NULL) |
| 2383 | g_ptr_array_unref (priv->udev_subsystems); |
Richard Hughes | 49e5e05 | 2017-09-03 12:15:41 +0100 | [diff] [blame] | 2384 | if (priv->smbios != NULL) |
| 2385 | g_object_unref (priv->smbios); |
Richard Hughes | 275d3b4 | 2018-04-20 16:40:37 +0100 | [diff] [blame] | 2386 | if (priv->runtime_versions != NULL) |
| 2387 | g_hash_table_unref (priv->runtime_versions); |
Richard Hughes | 34e0dab | 2018-04-20 16:43:00 +0100 | [diff] [blame] | 2388 | if (priv->compile_versions != NULL) |
| 2389 | g_hash_table_unref (priv->compile_versions); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2390 | g_hash_table_unref (priv->devices); |
Richard Hughes | 80b79bb | 2018-01-11 21:11:06 +0000 | [diff] [blame] | 2391 | g_hash_table_unref (priv->report_metadata); |
Richard Hughes | 161e9b5 | 2019-06-12 14:22:45 +0100 | [diff] [blame] | 2392 | g_rw_lock_clear (&priv->devices_mutex); |
Richard Hughes | 8499930 | 2019-05-02 10:18:32 +0100 | [diff] [blame] | 2393 | g_free (priv->build_hash); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2394 | g_free (priv->name); |
| 2395 | g_free (priv->data); |
Mario Limonciello | 3f9a1c1 | 2018-06-06 14:06:40 -0500 | [diff] [blame] | 2396 | /* Must happen as the last step to avoid prematurely |
| 2397 | * freeing memory held by the plugin */ |
| 2398 | #ifndef RUNNING_ON_VALGRIND |
| 2399 | if (priv->module != NULL) |
| 2400 | g_module_close (priv->module); |
| 2401 | #endif |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2402 | |
| 2403 | G_OBJECT_CLASS (fu_plugin_parent_class)->finalize (object); |
| 2404 | } |
| 2405 | |
| 2406 | FuPlugin * |
| 2407 | fu_plugin_new (void) |
| 2408 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2409 | return FU_PLUGIN (g_object_new (FU_TYPE_PLUGIN, NULL)); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2410 | } |