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