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