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