fwupd/plugins/ata/fu-self-test.c
Richard Hughes dbcc8e1137 ata: Include a vendor ID for ATA hardware
Some vendors want to ship updates for ATA hardware, but there are currently no
lock-down restrictions in place for these kind of devices.

There is the OUI from the WWN block which is supposed to identify the vendor,
but this is not always set and so we have to be a little creative. We can match
90% of hardware using the vendor name prefix, and the last 10% can be detected
with a heuristic that was the result of comparing over 900 drive models.

I'm not including very old drive models, media converters, raid controllers,
or external 'portable' drives as I don't think it is useful. Also, if the drive
contains a Dell vendor block just hardcode this as Dell rather than trying to
be clever.

Also ask the user to contribute OUI values if this data is found with no quirk
data as this is the only real sane way to manage this data long term.
The list of OUIs can be found here: http://standards-oui.ieee.org/oui.txt
2020-02-20 16:02:44 +00:00

81 lines
2.5 KiB
C

/*
* Copyright (C) 2019 Richard Hughes <richard@hughsie.com>
*
* SPDX-License-Identifier: LGPL-2.1+
*/
#include "config.h"
#include <fwupd.h>
#include "fu-ata-device.h"
#include "fu-device-private.h"
static void
fu_ata_id_func (void)
{
gboolean ret;
gsize sz;
g_autofree gchar *data = NULL;
g_autofree gchar *path = NULL;
g_autoptr(FuAtaDevice) dev = NULL;
g_autoptr(GError) error = NULL;
path = g_build_filename (TESTDATADIR, "StarDrive-SBFM61.2.bin", NULL);
ret = g_file_get_contents (path, &data, &sz, &error);
g_assert_no_error (error);
g_assert (ret);
dev = fu_ata_device_new_from_blob ((guint8 *)data, sz, &error);
g_assert_no_error (error);
g_assert_nonnull (dev);
g_assert_cmpint (fu_ata_device_get_transfer_mode (dev), ==, 0xe);
g_assert_cmpint (fu_ata_device_get_transfer_blocks (dev), ==, 0x1);
g_assert_cmpstr (fu_device_get_serial (FU_DEVICE (dev)), ==, "A45A078A198600476509");
g_assert_cmpstr (fu_device_get_name (FU_DEVICE (dev)), ==, "SATA SSD");
g_assert_cmpstr (fu_device_get_version (FU_DEVICE (dev)), ==, "SBFM61.2");
}
static void
fu_ata_oui_func (void)
{
gboolean ret;
gsize sz;
g_autofree gchar *data = NULL;
g_autofree gchar *path = NULL;
g_autofree gchar *str = NULL;
g_autoptr(FuAtaDevice) dev = NULL;
g_autoptr(GError) error = NULL;
path = g_build_filename (TESTDATADIR, "Samsung SSD 860 EVO 500GB.bin", NULL);
ret = g_file_get_contents (path, &data, &sz, &error);
g_assert_no_error (error);
g_assert (ret);
dev = fu_ata_device_new_from_blob ((guint8 *)data, sz, &error);
g_assert_no_error (error);
g_assert_nonnull (dev);
fu_ata_device_set_unknown_oui_report (dev, FALSE);
fu_device_convert_instance_ids (FU_DEVICE (dev));
str = fu_device_to_string (FU_DEVICE (dev));
g_debug ("%s", str);
g_assert_true (fu_device_has_guid (FU_DEVICE (dev), "OUI\\002538"));
g_assert_cmpint (fu_ata_device_get_transfer_mode (dev), ==, 0xe);
g_assert_cmpint (fu_ata_device_get_transfer_blocks (dev), ==, 0x1);
g_assert_cmpstr (fu_device_get_serial (FU_DEVICE (dev)), ==, "S3Z1NB0K862928X");
g_assert_cmpstr (fu_device_get_name (FU_DEVICE (dev)), ==, "SSD 860 EVO 500GB");
g_assert_cmpstr (fu_device_get_version (FU_DEVICE (dev)), ==, "RVT01B6Q");
}
int
main (int argc, char **argv)
{
g_test_init (&argc, &argv, NULL);
/* only critical and error are fatal */
g_log_set_fatal_mask (NULL, G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL);
/* tests go here */
g_test_add_func ("/fwupd/ata/id", fu_ata_id_func);
g_test_add_func ("/fwupd/ata/oui", fu_ata_oui_func);
return g_test_run ();
}