mirror of
https://git.proxmox.com/git/fwupd
synced 2025-08-14 13:42:23 +00:00
thunderbolt: make sure that authorized to add updatable flag
If the device is not authorized, it may cause a composite update that it's part of to not behave properly. If device is authorized at runtime, add updatable flag at runtime as well See #2374 for more details
This commit is contained in:
parent
c756405529
commit
76cc23c736
@ -396,7 +396,7 @@ mock_tree_attach_device (gpointer user_data)
|
||||
"device", dev->id,
|
||||
"vendor", "042",
|
||||
"vendor_name", "GNOME.org",
|
||||
"authorized", "0",
|
||||
"authorized", "1",
|
||||
"nvm_authenticate", authenticate,
|
||||
"nvm_version", tree->nvm_version,
|
||||
"unique_id", tree->uuid,
|
||||
|
@ -110,6 +110,42 @@ fu_thunderbolt_device_read_status_block (FuThunderboltDevice *self, GError **err
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
fu_thunderbolt_device_check_authorized (FuThunderboltDevice *self, GError **error)
|
||||
{
|
||||
guint64 status;
|
||||
g_autofree gchar *attribute = NULL;
|
||||
const gchar *update_error = NULL;
|
||||
/* read directly from file to prevent udev caching */
|
||||
g_autofree gchar *safe_path = g_build_path ("/", self->devpath, "authorized", NULL);
|
||||
|
||||
if (!g_file_test (safe_path, G_FILE_TEST_EXISTS)) {
|
||||
g_set_error_literal (error,
|
||||
FWUPD_ERROR,
|
||||
FWUPD_ERROR_NOT_SUPPORTED,
|
||||
"missing authorized attribute");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!g_file_get_contents (safe_path, &attribute, NULL, error))
|
||||
return FALSE;
|
||||
status = g_ascii_strtoull (attribute, NULL, 16);
|
||||
if (status == G_MAXUINT64 && errno == ERANGE) {
|
||||
g_set_error (error, G_IO_ERROR,
|
||||
g_io_error_from_errno (errno),
|
||||
"failed to read 'authorized: %s",
|
||||
g_strerror (errno));
|
||||
return FALSE;
|
||||
}
|
||||
if (status == 1)
|
||||
fu_device_add_flag (FU_DEVICE (self), FWUPD_DEVICE_FLAG_UPDATABLE);
|
||||
else
|
||||
update_error = "Not authorized";
|
||||
fu_device_set_update_error (FU_DEVICE (self), update_error);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
fu_thunderbolt_device_can_update (FuThunderboltDevice *self)
|
||||
{
|
||||
@ -362,8 +398,12 @@ fu_thunderbolt_device_setup_controller (FuDevice *device, GError **error)
|
||||
(guint) vid,
|
||||
(guint) did,
|
||||
self->is_native ? "-native" : "");
|
||||
fu_device_add_flag (device, FWUPD_DEVICE_FLAG_UPDATABLE);
|
||||
fu_device_add_flag (device, FWUPD_DEVICE_FLAG_DUAL_IMAGE);
|
||||
|
||||
/* check if device is authorized */
|
||||
if (!fu_thunderbolt_device_check_authorized (self, error))
|
||||
return FALSE;
|
||||
|
||||
} else {
|
||||
device_id = g_strdup ("TBT-fixed");
|
||||
}
|
||||
@ -517,6 +557,11 @@ static gboolean
|
||||
fu_thunderbolt_device_rescan (FuDevice *device, GError **error)
|
||||
{
|
||||
FuThunderboltDevice *self = FU_THUNDERBOLT_DEVICE (device);
|
||||
|
||||
/* refresh updatability */
|
||||
if (!fu_thunderbolt_device_check_authorized (self, error))
|
||||
return FALSE;
|
||||
|
||||
/* refresh the version */
|
||||
return fu_thunderbolt_device_get_version (self, error);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user