ACK: [PATCH 1/2] acpi: add MSDM table test (LP: #1470538)
ivanhu
ivan.hu at canonical.com
Fri Jul 3 09:04:04 UTC 2015
On 2015年07月01日 23:02, Colin King wrote:
> From: Colin Ian King <colin.king at canonical.com>
>
> Signed-off-by: Colin Ian King <colin.king at canonical.com>
> ---
> src/Makefile.am | 1 +
> src/acpi/msdm/msdm.c | 173 ++++++++++++++++++++++++++++++++++++++++++++
> src/lib/include/fwts_acpi.h | 15 ++++
> 3 files changed, 189 insertions(+)
> create mode 100644 src/acpi/msdm/msdm.c
>
> diff --git a/src/Makefile.am b/src/Makefile.am
> index e178f3f..539ff94 100644
> --- a/src/Makefile.am
> +++ b/src/Makefile.am
> @@ -58,6 +58,7 @@ fwts_SOURCES = main.c \
> acpi/lpit/lpit.c \
> acpi/madt/madt.c \
> acpi/mcfg/mcfg.c \
> + acpi/msdm/msdm.c \
> acpi/method/method.c \
> acpi/osilinux/osilinux.c \
> acpi/pcc/pcc.c \
> diff --git a/src/acpi/msdm/msdm.c b/src/acpi/msdm/msdm.c
> new file mode 100644
> index 0000000..4a46da1
> --- /dev/null
> +++ b/src/acpi/msdm/msdm.c
> @@ -0,0 +1,173 @@
> +/*
> + * Copyright (C) 2015 Canonical
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License
> + * as published by the Free Software Foundation; either version 2
> + * of the License, or (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
> + *
> + */
> +#include "fwts.h"
> +
> +#include <stdlib.h>
> +#include <stdio.h>
> +#include <unistd.h>
> +#include <inttypes.h>
> +#include <string.h>
> +#include <ctype.h>
> +
> +fwts_acpi_table_info *table;
> +
> +static int msdm_init(fwts_framework *fw)
> +{
> +
> + if (fwts_acpi_find_table(fw, "MSDM", 0, &table) != FWTS_OK) {
> + fwts_log_error(fw, "Cannot read ACPI tables.");
> + return FWTS_ERROR;
> + }
> + if (table == NULL || (table && table->length == 0)) {
> + fwts_log_error(fw, "ACPI MSDM table does not exist, skipping test");
> + return FWTS_SKIP;
> + }
> +
> + return FWTS_OK;
> +}
> +
> +/*
> + * Microsoft Data Management (MSDM) Table
> + * http://feishare.com/attachments/article/265/microsoft-software-licensing-tables.pdf
> + * and derived from other sources.
> + */
> +static int msdm_test1(fwts_framework *fw)
> +{
> + fwts_acpi_table_msdm *msdm = (fwts_acpi_table_msdm *)table->data;
> + bool passed = true;
> +
> + /* Size sanity check #1, got enough table to get initial header */
> + if (table->length < sizeof(fwts_acpi_table_msdm)) {
> + passed = false;
> + fwts_failed(fw, LOG_LEVEL_HIGH,
> + "MSDMTooShort",
> + "MSDM table too short, must be at least %zu bytes, "
> + "instead got %zu bytes",
> + sizeof(fwts_acpi_table_msdm), table->length);
> + goto done;
> + }
> + fwts_log_info_verbatum(fw, " Reserved: 0x%8.8" PRIx32, msdm->reserved);
> + fwts_log_info_verbatum(fw, " Data Type: 0x%8.8" PRIx32, msdm->data_type);
> + fwts_log_info_verbatum(fw, " Data Reserved: 0x%8.8" PRIx32, msdm->data_reserved);
> + fwts_log_info_verbatum(fw, " Data Length: 0x%8.8" PRIx32, msdm->data_length);
> +
> + if (msdm->reserved) {
> + passed = false;
> + fwts_failed(fw, LOG_LEVEL_HIGH,
> + "MSDMReservedNonZero",
> + "MSDM Reserved field should be zero, got 0x%8.8" PRIx32
> + " instead",
> + msdm->reserved);
> + }
> + if (msdm->data_reserved) {
> + passed = false;
> + fwts_failed(fw, LOG_LEVEL_HIGH,
> + "MSDMDataReservedNonZero",
> + "MSDM Data Reserved field should be zero, got 0x%8.8" PRIx32
> + " instead",
> + msdm->data_reserved);
> + }
> +
> + /* Now check table is big enough for the data payload */
> + if (table->length < sizeof(fwts_acpi_table_msdm) + msdm->data_length) {
> + passed = false;
> + fwts_failed(fw, LOG_LEVEL_HIGH,
> + "MSDMDataLengthInvalid",
> + "MSDM Data Length field states that the data "
> + " is %" PRIu32 " bytes long, but the table is only "
> + "%zu bytes in total",
> + msdm->data_length, table->length);
> + goto done;
> + }
> +
> + /*
> + * Based on inspection of a few hundred tables
> + */
> + switch (msdm->data_type) {
> + case 0x0001:
> + /* Check license key size */
> + if (msdm->data_length != 0x1d) {
> + passed = false;
> + fwts_failed(fw, LOG_LEVEL_HIGH,
> + "MSDMDataLengthInvalid",
> + "MSDM Data Length field should be 0x0000001d, got 0x8.8%" PRIx32
> + " instead",
> + msdm->data_length);
> + } else {
> + size_t i;
> + bool invalid = false;
> + /* Note, no checks to see if this is a valid key! */
> +
> + fwts_log_info_verbatum(fw, " Data: '%*.*s'",
> + msdm->data_length, msdm->data_length, msdm->data);
> + /* Expect XXXXX-XXXXX-XXXXX-XXXXX-XXXXX */
> +
> + for (i = 0; i < 29; i++) {
> + if ((i % 6) == 5) {
> + if (msdm->data[i] != '-')
> + invalid = true;
> + } else {
> + if (!isdigit(msdm->data[i]) &&
> + !isupper(msdm->data[i]))
> + invalid = true;
> + }
> + }
> + if (invalid) {
> + passed = false;
> + fwts_failed(fw, LOG_LEVEL_HIGH,
> + "MSDMDataLengthInvalid",
> + "MSDM Data field did not contain digits, uppercase letters and "
> + "- characters in the form XXXXX-XXXXX-XXXXX-XXXXX-XXXXX");
> + }
> + }
> + break;
> + default:
> + passed = false;
> + fwts_failed(fw, LOG_LEVEL_HIGH,
> + "MSDMDataTypeInvalid",
> + "MSDM Data Type field should be 0x00000001, got 0x8.8%" PRIx32
> + " instead",
> + msdm->data_type);
> + break;
> + }
> +
> +done:
> + /*
> + * Until this format is described somewhere, the checks
> + * will be totally minimal.
> + */
> + fwts_log_info(fw, "MSDM has had minimal check due to proprietary nature of the table");
> + if (passed)
> + fwts_passed(fw, "No issues found in MSDM table.");
> +
> + return FWTS_OK;
> +}
> +
> +static fwts_framework_minor_test msdm_tests[] = {
> + { msdm_test1, "MSDM Microsoft Data Management Table test." },
> + { NULL, NULL }
> +};
> +
> +static fwts_framework_ops msdm_ops = {
> + .description = "MSDM Microsoft Data Management Table test.",
> + .init = msdm_init,
> + .minor_tests = msdm_tests
> +};
> +
> +FWTS_REGISTER("msdm", &msdm_ops, FWTS_TEST_ANYTIME, FWTS_FLAG_BATCH | FWTS_FLAG_TEST_ACPI)
> diff --git a/src/lib/include/fwts_acpi.h b/src/lib/include/fwts_acpi.h
> index 5706e2f..93d3817 100644
> --- a/src/lib/include/fwts_acpi.h
> +++ b/src/lib/include/fwts_acpi.h
> @@ -1132,4 +1132,19 @@ typedef struct {
> uint32_t flags;
> } __attribute__ ((packed)) fwts_acpi_table_waet;
>
> +
> +/*
> + * Microsoft Data Management (MSDM) Table
> + * http://feishare.com/attachments/article/265/microsoft-software-licensing-tables.pdf
> + */
> +typedef struct {
> + fwts_acpi_table_header header;
> + uint32_t version;
> + uint32_t reserved;
> + uint32_t data_type;
> + uint32_t data_reserved;
> + uint32_t data_length;
> + uint8_t data[0]; /* Proprietary data */
> +} __attribute__ ((packed)) fwts_acpi_table_msdm;
> +
> #endif
Acked-by: Ivan Hu<ivan.hu at canonical.com>
More information about the fwts-devel
mailing list