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