コード例 #1
0
ファイル: uefirtauthvar.c プロジェクト: ahs3/fwts-sbbr
static int check_fw_support(fwts_framework *fw, uint64_t status)
{
	if ((status == EFI_INVALID_PARAMETER) &&
		((attributes & FWTS_UEFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS) ||
		(attributes & FWTS_UEFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS) ||
		(attributes & FWTS_UEFI_VARIABLE_APPEND_WRITE))) {
		fwts_uefi_print_status_info(fw, status);
		fwts_skipped(fw,
			"EFI_INVALID_PARAMETER shall be returned, "
			"when firmware doesn't support these operations "
			"with EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS, "
			"EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS "
			"or EFI_VARIABLE_APPEND_WRITE attributes is set.");
		return FWTS_SKIP;
	}
	if (status == EFI_OUT_OF_RESOURCES) {
		fwts_uefi_print_status_info(fw, status);
		fwts_skipped(fw,
			"Run out of resources for SetVariable "
			"UEFI runtime interface: cannot test.");
		fwts_advice(fw,
			"Firmware may reclaim some resources "
			"after rebooting. Reboot and test "
			"again may be helpful to continue "
			"the test.");
		return FWTS_SKIP;
	}
	return FWTS_OK;
}
コード例 #2
0
ファイル: version.c プロジェクト: 9elements/fwts
static int version_test1(fwts_framework *fw)
{
	char *str;
	fwts_release *release;

	release = fwts_release_get();
        if (release) {
		bool not_ubuntu = strcmp(release->distributor, "Ubuntu");

		fwts_release_free(release);
		/* Following is Ubuntu specific, so don't fail */
		if (not_ubuntu) {
			fwts_skipped(fw, "Information not available with this kernel.");
			return FWTS_OK;
		}
        }

	if ((str = fwts_get("/proc/version_signature")) == NULL)
		fwts_skipped(fw,
			"Cannot get version signature info from "
			"/proc/version_signature");
	else {
		fwts_chop_newline(str);
		fwts_log_info(fw, "Signature: %s", str);
		free(str);
	}

	fwts_infoonly(fw);

	return FWTS_OK;
}
コード例 #3
0
ファイル: power_mgmt_info.c プロジェクト: 9elements/fwts
static int power_mgmt_init(fwts_framework *fw)
{
	int ret;

	if (fwts_firmware_detect() != FWTS_FIRMWARE_OPAL) {
		fwts_skipped(fw,
			"The firmware type detected was non OPAL "
			"so skipping the OPAL Power Management DT checks.");
		return FWTS_SKIP;
	}

	if (!fw->fdt) {
		fwts_failed(fw, LOG_LEVEL_HIGH, "NoDeviceTree",
			"Device tree not found");
		return FWTS_ERROR;
	}

	ret = get_proc_gen(fw);
	if (ret != FWTS_OK) {
		fwts_failed(fw, LOG_LEVEL_HIGH, "ProcGenFail",
			"Failed to get the Processor generation");
		return FWTS_ERROR;
	}

	return FWTS_OK;
}
コード例 #4
0
ファイル: uefirttime.c プロジェクト: 9elements/fwts
static int uefirttime_test_setwakeuptime_invalid(
	fwts_framework *fw,
	struct efi_setwakeuptime *setwakeuptime
)
{
	long ioret;
	uint64_t status;

	setwakeuptime->status = &status;

	ioret = ioctl(fd, EFI_RUNTIME_SET_WAKETIME, setwakeuptime);
	if (ioret == -1) {
		if (status == EFI_UNSUPPORTED) {
			fwts_skipped(fw, "Skipping test, GetWakeupTime runtime "
				"service is not supported on this platform.");
			return FWTS_OK;
		}
		if (status == EFI_INVALID_PARAMETER) {
			fwts_passed(fw, "UEFI runtime service SetTimeWakeupTime interface test "
				"passed, returned EFI_INVALID_PARAMETER as expected.");
			return FWTS_OK;
		} else {
			fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetWakeupTime",
				"Failed to get correct return status from UEFI runtime service, "
				"expecting EFI_INVALID_PARAMETER.");
			fwts_uefi_print_status_info(fw, status);
			return FWTS_ERROR;
		}
	}
	fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetWakeupTime",
		"Failed to get error return status from UEFI runtime service, expected EFI_INVALID_PARAMETER.");
	return FWTS_ERROR;
}
コード例 #5
0
ファイル: uefirttime.c プロジェクト: 9elements/fwts
static int uefirttime_test18(fwts_framework *fw)
{
	long ioret;
	struct efi_getwakeuptime getwakeuptime;
	uint64_t status;
	uint8_t enabled, pending;
	EFI_TIME efi_time;

	getwakeuptime.Enabled = &enabled;
	getwakeuptime.Pending = &pending;
	getwakeuptime.Time = &efi_time;
	getwakeuptime.status = &status;

	ioret = ioctl(fd, EFI_RUNTIME_GET_WAKETIME, &getwakeuptime);
	if (ioret == -1) {
		if (status == EFI_UNSUPPORTED) {
			fwts_skipped(fw, "Skipping test, GetWakeupTime runtime "
				"service is not supported on this platform.");
			return FWTS_OK;
		}
		fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetWakeupTime",
			"Failed to get wakeup time with UEFI runtime service.");
		fwts_uefi_print_status_info(fw, status);
		return FWTS_ERROR;
	}

	if (!checktimefields(fw, getwakeuptime.Time))
		return FWTS_ERROR;

	fwts_passed(fw, "UEFI runtime service GetWakeupTime interface test passed.");

	return FWTS_OK;
}
コード例 #6
0
ファイル: uefirtauthvar.c プロジェクト: ahs3/fwts-sbbr
/*
 * After updated, set the old data and timestamp authenticated variable,
 * AuthVarCreate, expect EFI_SECURITY_VIOLATION returned.
 */
static int uefirtauthvar_test6(fwts_framework *fw)
{
	long ioret;
	uint64_t status;

	if (!(data_exist & E_AUTHVARUPDATE)) {
		fwts_skipped(fw,"The test variable, AuthVarUpdate, doesn't exist, skip the test.");
		return FWTS_SKIP;
	}

	ioret = setvar(&gtestguid, attributes, sizeof(AuthVarCreate), AuthVarCreate, &status);

	if (ioret == -1) {
		int supcheck = check_fw_support(fw, status);

		if (supcheck != FWTS_OK)
			return supcheck;

		if (status == EFI_SECURITY_VIOLATION) {
			fwts_passed(fw, "Authenticated variable test with old authenticated variable passed.");
			return FWTS_OK;
		}

		fwts_failed(fw, LOG_LEVEL_MEDIUM,
			"UEFISetOldAuthVar",
			"Set authenticated variable fail");
			fwts_uefi_print_status_info(fw, status);
	}

	fwts_failed(fw, LOG_LEVEL_HIGH,
		"UEFISetOldAuthVar",
		"Set authenticated variable expected fail but success");

	return FWTS_ERROR;
}
コード例 #7
0
ファイル: uefirtauthvar.c プロジェクト: ahs3/fwts-sbbr
/*
 * Delete the test authenticated variable.
 */
static int uefirtauthvar_test7(fwts_framework *fw)
{
	long ioret;

	uint8_t data[getvar_buf_size];
	uint64_t getdatasize = sizeof(data);
	uint64_t status;
	uint32_t attributestest;

	if (!(data_exist & E_AUTHVARCREATE)) {
		fwts_skipped(fw,"The test data, AuthVarCreate, doesn't exist, skip the test.");
		return FWTS_SKIP;
	}

	ioret = setvar(&gtestguid, attributes, sizeof(AuthVarDel), AuthVarDel, &status);

	if (ioret == -1) {
		int supcheck = check_fw_support(fw, status);

		if (supcheck != FWTS_OK)
			return supcheck;

		fwts_failed(fw, LOG_LEVEL_HIGH,
			"UEFIDelAuthVar",
			"Failed to delete authenticated variable with UEFI "
			"runtime service.");
		fwts_uefi_print_status_info(fw, status);
		return FWTS_ERROR;
	}

	ioret = getvar(&gtestguid, &attributestest, &getdatasize, data, &status);
	if (ioret == -1) {
		if (status == EFI_NOT_FOUND) {
			fwts_passed(fw, "Delete authenticated variable tests passed.");
			return FWTS_OK;
		}

		fwts_failed(fw, LOG_LEVEL_MEDIUM,
			"UEFIDelAuthVar",
			"Failed to get authenticated variable with UEFI "
			"runtime service.");
		fwts_uefi_print_status_info(fw, status);
		return FWTS_ERROR;
	}

	fwts_failed(fw, LOG_LEVEL_HIGH,
		"UEFIDelAuthVar",
		"Failed to delete authenticated variable still get the test"
		"authenticated variable.");

	return FWTS_ERROR;
}
コード例 #8
0
ファイル: reserv_mem.c プロジェクト: 9elements/fwts
static int reserv_mem_init(fwts_framework *fw)
{
	if (fwts_firmware_detect() != FWTS_FIRMWARE_OPAL) {
		fwts_skipped(fw,
			"The firmware type detected was non OPAL "
			"so skipping the OPAL Reserve Memory DT checks.");
		return FWTS_SKIP;
	}

	/* On an OPAL based system Device tree should be present */
	if (!fw->fdt) {
		fwts_failed(fw, LOG_LEVEL_HIGH, "NoDeviceTree",
			"Device tree not found");
		return FWTS_ERROR;
	}

	return FWTS_OK;
}
コード例 #9
0
ファイル: uefivarinfo.c プロジェクト: ColinIanKing/fwts
static int uefivarinfo_test1(fwts_framework *fw)
{
	uint64_t status;
	uint64_t remvarstoragesize;
	uint64_t maxvariablesize;
	uint64_t maxvarstoragesize;

	uint64_t usedvars;
	uint64_t usedvarssize;

	if (do_queryvariableinfo(&status, &maxvarstoragesize, &remvarstoragesize, &maxvariablesize) == FWTS_ERROR) {
		if (status == EFI_UNSUPPORTED) {
			fwts_skipped(fw,
				"QueryVariableInfo UEFI runtime interface not supported: cannot test.");
			fwts_advice(fw,
				"Firmware also needs to check if the revision "
				"of system table is correct or not. Linux "
				"kernel returns EFI_UNSUPPORTED as well, if "
				"the FirmwareRevision of system table is less "
				"than EFI_2_00_SYSTEM_TABLE_REVISION.");
			return FWTS_SKIP;
		} else {
			fwts_log_info(fw, "Failed to query variable info with UEFI runtime service.");
			fwts_uefi_print_status_info(fw, status);
			return FWTS_ERROR;
		}
	}

	fwts_log_info_verbatim(fw, "UEFI NVRAM storage:");
	fwts_log_info_verbatim(fw, "  Maximum storage:       %8" PRIu64 " bytes", maxvarstoragesize);
	fwts_log_info_verbatim(fw, "  Remaining storage:     %8" PRIu64 " bytes", remvarstoragesize);
	fwts_log_info_verbatim(fw, "  Maximum variable size: %8" PRIu64 " bytes", maxvariablesize);

	if (do_checkvariables(fw, &usedvars, &usedvarssize, maxvariablesize) == FWTS_OK) {
		fwts_log_info_verbatim(fw, "Currently used:");
		fwts_log_info_verbatim(fw, "  %" PRIu64 " variables, storage used: %" PRIu64 " bytes", usedvars, usedvarssize);
	}

	return FWTS_OK;
}
コード例 #10
0
ファイル: reserv_mem.c プロジェクト: 9elements/fwts
static int reserv_mem_limits_test(fwts_framework *fw)
{
	bool ok = true;
	char *region_names;
	const uint64_t *ranges;
	reserve_region_t *regions;
	int  offset, len, nr_regions, rc, j;
	plat_config_t configstruct = {0, 0, 0};

	get_config(fw, CONFIG_FILENAME, &configstruct);

	offset = fdt_path_offset(fw->fdt, root_node);
	if (offset < 0) {
		fwts_failed(fw, LOG_LEVEL_MEDIUM, "DTNodeMissing",
			"DT root node %s is missing", root_node);
		return FWTS_ERROR;
	}

	/* Get the number of memory reserved regions */
	nr_regions = fwts_dt_stringlist_count(fw, fw->fdt, offset,
				"reserved-names");

	/* Check for the reservd-names property */
	region_names = (char *)fdt_getprop(fw->fdt, offset,
					"reserved-names", &len);
	if (!region_names) {
		fwts_failed(fw, LOG_LEVEL_MEDIUM, "DTPropertyMissing",
			"DT Property reserved-names is missing %s",
			fdt_strerror(len));
		return FWTS_ERROR;
	}

	regions = malloc(nr_regions*sizeof(reserve_region_t));
	if (!regions) {
		fwts_skipped(fw,
			"Unable to allocate memory "
			"for reserv_region_t structure");
		return FWTS_SKIP;
	}

	for (j = 0; j < nr_regions; j++) {
		regions[j].name = strdup(region_names);
		region_names += strlen(regions[j].name) + 1;
	}

	/* Check for the reserved-ranges property */
	ranges = fdt_getprop(fw->fdt, offset, "reserved-ranges", &len);
	if (!ranges) {
		fwts_failed(fw, LOG_LEVEL_MEDIUM, "DTPropertyMissing",
			"DT Property reserved-ranges is missing %s",
			fdt_strerror(len));
		rc = FWTS_ERROR;
		goto out_free_regions;
	}

	for (j = 0; j < nr_regions; j++) {
		regions[j].start = (uint64_t)be64toh(ranges[2 * j]);
		regions[j].len = (uint64_t)be64toh(ranges[2 * j + 1]);
		fwts_log_info(fw, "Region name %80s"
			" start: 0x%08" PRIx64 ", len: 0x%08" PRIx64 "\n",
			regions[j].name, regions[j].start, regions[j].len);
	}

	offset = fdt_path_offset(fw->fdt, reserv_mem_node);
	if (offset < 0) {
		fwts_failed(fw, LOG_LEVEL_MEDIUM, "DTNodeMissing",
			"reserve memory node %s is missing", reserv_mem_node);
		rc = FWTS_ERROR;
		goto out_free_regions;
	}

	/* Validate different cases */
	for (j = 0; j < nr_regions; j++) {
		char *buf = NULL;

		/* Check for zero offset's */
		if (regions[j].start == 0) {
			fwts_failed(fw, LOG_LEVEL_MEDIUM, "ZeroStartAddress",
				"memory region got zero start address");
			ok = false;
		}

		/* Check for zero region sizes */
		if (regions[j].len == 0) {
			fwts_failed(fw, LOG_LEVEL_MEDIUM, "ZeroRegionSize",
				"memory region got zero size");
			ok = false;
		}

		/* Form the reserved-memory sub nodes for all the regions*/
		if (!strstr(regions[j].name, "@"))
			buf = make_message("%s%s@%lx", reserv_mem_node,
					regions[j].name, regions[j].start);
		else
			buf = make_message("/%s/%s", reserv_mem_node,
					regions[j].name);

		if (!buf) {
			fwts_skipped(fw,
				"Unable to allocate memory for buffer");
			rc = FWTS_SKIP;
			goto out_free_regions;
		}

		/* Check all nodes got created for all the sub regions */
		offset = fdt_path_offset(fw->fdt, buf);
		if (offset < 0) {
			fwts_failed(fw, LOG_LEVEL_MEDIUM, "DTNodeMissing",
				"reserve memory region node %s is missing",
				buf);
			ok = false;
		}

		if (skip)
			continue;

		/* Validate different Known image fixed sizes here */
		if (strstr(regions[j].name, "homer-image")) {
			if (regions[j].len != configstruct.homer) {
				fwts_failed(fw, LOG_LEVEL_MEDIUM,
					"ImageSizeMismatch",
					"Mismatch in homer-image size, "
					"expected: 0x%" PRIx64 ", actual: 0x%" PRIx64,
					configstruct.homer, regions[j].len);
				ok = false;
			} else
				fwts_log_info(fw,
					"homer-image size is validated");
		}

		if (strstr(regions[j].name, "slw-image")) {
			if (regions[j].len != configstruct.slw) {
				fwts_failed(fw, LOG_LEVEL_MEDIUM,
					"ImageSizeMismatch",
					"Mismatch in slw-image size, "
					"expected: 0x%" PRIx64 ", actual: 0x%" PRIx64,
					configstruct.slw, regions[j].len);
				ok = false;
			} else
				fwts_log_info(fw,
					"slw-image size is validated");
		}

		if (strstr(regions[j].name, "occ-common-area")) {
			if (regions[j].len != configstruct.occ_common) {
				fwts_failed(fw, LOG_LEVEL_MEDIUM,
					"ImageSizeMismatch",
					"Mismatch in occ-common-area size, "
					"expected: 0x%" PRIx64 ", actual: 0x%" PRIx64,
					configstruct.occ_common,
					regions[j].len);
				ok = false;
			} else
				fwts_log_info(fw,
					"occ-common-area size is validated");
		}
	}

	if (ok) {
		rc = FWTS_OK;
		fwts_passed(fw, "Reserved memory validation tests passed");
	} else {
		rc = FWTS_ERROR;
		fwts_failed(fw, LOG_LEVEL_HIGH, "ReservMemTestFail",
			"One or few Reserved Memory DT"
			" validation tests failed");
	}

out_free_regions:
	free(regions);
	return rc;
}
コード例 #11
0
ファイル: crs.c プロジェクト: 9elements/fwts
static int crs_test1(fwts_framework *fw)
{
	fwts_list *klog;
	int day, mon, year;
	char *cmdline;

	if ((cmdline = fwts_get("/proc/cmdline")) == NULL) {
		fwts_log_error(fw, "Cannot read /proc/cmdline");
		return FWTS_ERROR;
	}

	if (crs_get_bios_date(fw, &day, &mon, &year) != FWTS_OK) {
		fwts_log_error(fw, "Cannot determine age of BIOS.");
		free(cmdline);
		return FWTS_ERROR;
	}

	if ((klog = fwts_klog_read()) == NULL) {
		fwts_log_error(fw, "Cannot read kernel log.");
		free(cmdline);
		return FWTS_ERROR;
	}

        if (fwts_klog_regex_find(fw, klog,
		"PCI: Ignoring host bridge windows from ACPI;") > 0) {
		if (strstr(cmdline, "pci=nocrs") != NULL) {
			fwts_skipped(fw, "Kernel was booted with pci=nocrs, Ignoring host bridge windows _CRS settings from ACPI, skipping test.");
		}
		else {
			if (year == 0) {
				fwts_failed(fw, LOG_LEVEL_MEDIUM,
					"BIOSTooOld",
					"The kernel could not determine the BIOS age "
					"and has assumed that your BIOS is too old to correctly "
					"specify the host bridge MMIO aperture using _CRS.");
				fwts_log_advice(fw, "You can override this by booting with \"pci=use_crs\".");
			} else if (year < 2008) {
				fwts_passed(fw,
					"The kernel has detected an old BIOS (%d/%d/%d) "
					"and has assumed that your BIOS is too old to correctly "
					"specify the host bridge MMIO aperture using _CRS.", mon, day, year);
				fwts_log_advice(fw, "You can override this by booting with \"pci=use_crs\".");
			} else {
				fwts_failed(fw, LOG_LEVEL_MEDIUM,
					"HostBridgeWindows",
					"The kernel is ignoring host bridge windows from ACPI for some unknown reason. "
					"pci=nocrs has not been used as a boot parameter and the BIOS may be recent enough "
					"to support this (%d/%d/%d)", mon, day, year);
			}
		}
	} else if (fwts_klog_regex_find(fw, klog, "PCI: Using host bridge windows from ACPI;") > 0) {
		if (strstr(cmdline, "pci=use_crs") != NULL) {
			if (year == 0)  {
				fwts_failed(fw, LOG_LEVEL_MEDIUM,
					"BIOSNoReleaseDate",
					"The BIOS does not seem to have release date, hence pci=use_crs was required.");
			} else if (year < 2008) {
				fwts_passed(fw,
					"The BIOS is relatively old (%d/%d/%d) and hence pci=use_crs was required to "
					"enable host bridge windows _CRS settings from ACPI.", mon, day, year);
			} else {
				fwts_failed(fw, LOG_LEVEL_LOW,
					"BIOSSupportBridgeWindows",
					"Kernel was booted with pci=use_crs but this may be uncessary as "
					"the BIOS is new enough to support automatic bridge windows configuring using _CRS from ACPI. "
					"However, the workaround may be necessary because _CRS is incorrect or not implemented in the "
					"DSDT.");
			}
		}
		else {
			fwts_passed(fw,
				"The kernel has detected a BIOS newer than the end of 2007 (%d/%d/%d) "
				"and has assumed that your BIOS can correctly "
				"specify the host bridge MMIO aperture using _CRS.  If this does not work "
				"correctly you can override this by booting with \"pci=nocrs\".", mon, day, year);
		}
	} else {
		fwts_skipped(fw, "Cannot find host bridge message in kernel log, skipping test.");
	}

	fwts_list_free(klog, free);
	free(cmdline);

	return FWTS_OK;
}
コード例 #12
0
ファイル: uefirttime.c プロジェクト: 9elements/fwts
static int uefirttime_test_setwakeuptime_invalid_time(
	fwts_framework *fw,
	EFI_TIME *time)
{
	struct efi_getwakeuptime getwakeuptime;
	struct efi_setwakeuptime setwakeuptime;
	EFI_TIME oldtime, newtime;
	uint64_t status;
	uint8_t pending, enabled;
	int ret, ioret;

	getwakeuptime.Enabled = &enabled;
	getwakeuptime.Pending = &pending;
	getwakeuptime.Time = &oldtime;
	getwakeuptime.status = &status;

	ioret = ioctl(fd, EFI_RUNTIME_GET_WAKETIME, &getwakeuptime);
	if (ioret == -1) {
		if (status == EFI_UNSUPPORTED) {
			fwts_skipped(fw, "Skipping test, GetWakeupTime runtime "
				"service is not supported on this platform.");
			return FWTS_OK;
		}
		fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetWakeupTime",
			"Failed to get wakeup time with UEFI runtime service.");
		fwts_uefi_print_status_info(fw, status);
		return FWTS_ERROR;
	}

	memcpy(&newtime, &oldtime, sizeof(EFI_TIME));
	if (time->Year != 0xffff)
		newtime.Year = time->Year;
	if (time->Month != 0xff)
		newtime.Month = time->Month;
	if (time->Day != 0xff)
		newtime.Day = time->Day;
	if (time->Hour != 0xff)
		newtime.Hour = time->Hour;
	if (time->Minute != 0xff)
		newtime.Minute = time->Minute;
	if (time->Second != 0xff)
		newtime.Second = time->Second;
	if (time->Nanosecond != 0xffffffff)
		newtime.Nanosecond = time->Nanosecond;
	if ((uint16_t)time->TimeZone != 0xffff)
		newtime.TimeZone = time->TimeZone;

	setwakeuptime.Time = &newtime;
	setwakeuptime.status = &status;
	setwakeuptime.Enabled = true;

	ret = uefirttime_test_setwakeuptime_invalid(fw, &setwakeuptime);

	/* Restore original time */
	setwakeuptime.Time = &oldtime;
	setwakeuptime.status = &status;
	setwakeuptime.Enabled = true;
	ioret = ioctl(fd, EFI_RUNTIME_SET_WAKETIME, &setwakeuptime);
	if (ioret == -1) {
		fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetWakeupTime",
			"Failed to set wakeup time with UEFI runtime service.");
		fwts_uefi_print_status_info(fw, status);
		return FWTS_ERROR;
	}
	return ret;
}
コード例 #13
0
ファイル: uefirttime.c プロジェクト: 9elements/fwts
static int uefirttime_test23(fwts_framework *fw)
{
	long ioret;
	struct efi_setwakeuptime setwakeuptime;
	uint64_t status;
	EFI_TIME oldtime;
	EFI_TIME newtime;

	struct efi_gettime gettime;
	EFI_TIME_CAPABILITIES efi_time_cap;

	struct efi_getwakeuptime getwakeuptime;
	uint8_t enabled, pending;

	gettime.Capabilities = &efi_time_cap;
	gettime.Time = &oldtime;
	gettime.status = &status;

	ioret = ioctl(fd, EFI_RUNTIME_GET_TIME, &gettime);

	if (ioret == -1) {
		fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetTime",
			"Failed to get time with UEFI runtime service.");
		fwts_uefi_print_status_info(fw, status);
		return FWTS_ERROR;
	}

	/* change the hour, add 1 hour*/
	addonehour(&oldtime);

	setwakeuptime.Time = &oldtime;
	setwakeuptime.status = &status;
	setwakeuptime.Enabled = true;

	ioret = ioctl(fd, EFI_RUNTIME_SET_WAKETIME, &setwakeuptime);
	if (ioret == -1) {
		if (status == EFI_UNSUPPORTED) {
			fwts_skipped(fw, "Skipping test, GetWakeupTime runtime "
				"service is not supported on this platform.");
			return FWTS_OK;
		}
		fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetWakeupTime",
			"Failed to set wakeup time with UEFI runtime service.");
		fwts_uefi_print_status_info(fw, status);
		return FWTS_ERROR;
	}

	sleep(1);

	getwakeuptime.Enabled = &enabled;
	getwakeuptime.Pending = &pending;
	getwakeuptime.Time = &newtime;
	getwakeuptime.status = &status;

	ioret = ioctl(fd, EFI_RUNTIME_GET_WAKETIME, &getwakeuptime);
	if (ioret == -1) {
		if (status == EFI_UNSUPPORTED) {
			fwts_skipped(fw, "Skipping test, GetWakeupTime runtime "
				"service is not supported on this platform.");
			return FWTS_OK;
		}
		fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetWakeupTime",
			"Failed to get wakeup time with UEFI runtime service.");
		fwts_uefi_print_status_info(fw, status);
		return FWTS_ERROR;
	}

	if (*getwakeuptime.Enabled != true) {
		fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetWakeupTimeEnable",
			"Failed to set wakeup alarm clock, wakeup timer should be enabled.");
		return FWTS_ERROR;
	}

	if (*getwakeuptime.Pending != false) {
		fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetWakeupTimePending",
			"Get error alarm signle status.");
		return FWTS_ERROR;
	}

	if ((oldtime.Year != newtime.Year) || (oldtime.Month != newtime.Month) ||
		(oldtime.Day != newtime.Day) || (oldtime.Hour != newtime.Hour)) {
		fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetWakeupTimeVerify",
			"Failed to verify wakeup time after change.");
		return FWTS_ERROR;
	}

	setwakeuptime.Enabled = false;

	ioret = ioctl(fd, EFI_RUNTIME_SET_WAKETIME, &setwakeuptime);
	if (ioret == -1) {
		fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetWakeupTime",
			"Failed to set wakeup time with UEFI runtime service.");
		fwts_uefi_print_status_info(fw, status);
		return FWTS_ERROR;
	}

	sleep(1);

	ioret = ioctl(fd, EFI_RUNTIME_GET_WAKETIME, &getwakeuptime);
	if (ioret == -1) {
		if (status == EFI_UNSUPPORTED) {
			fwts_skipped(fw, "Skipping test, GetWakeupTime runtime "
				"service is not supported on this platform.");
			return FWTS_OK;
		}
		fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetWakeupTime",
			"Failed to get wakeup time with UEFI runtime service.");
		fwts_uefi_print_status_info(fw, status);
		return FWTS_ERROR;
	}

	if (*getwakeuptime.Enabled != false) {
		fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetWakeupTimeEnable",
			"Failed to set wakeup alarm clock, wakeup timer should be disabled.");
		return FWTS_ERROR;
	}

	fwts_passed(fw, "UEFI runtime service SetWakeupTime interface test passed.");

	return FWTS_OK;
}
コード例 #14
0
ファイル: uefirtauthvar.c プロジェクト: ahs3/fwts-sbbr
/*
 * Update the new authenticated variable by using the same key but a new
 * timestamp and data.
 */
static int uefirtauthvar_test5(fwts_framework *fw)
{
	long ioret;

	uint8_t data[getvar_buf_size];
	uint64_t getdatasize = sizeof(data);
	uint64_t status;
	uint32_t attributestest;
	size_t i;

	if (!(data_exist & E_AUTHVARAPPEND)) {
		fwts_skipped(fw,"The test data, AuthVarAppend, doesn't exist, skip the test.");
		return FWTS_SKIP;
	}

	ioret = setvar(&gtestguid, attributes, sizeof(AuthVarUpdate), AuthVarUpdate, &status);

	if (ioret == -1) {
		int supcheck = check_fw_support(fw, status);

		if (supcheck != FWTS_OK)
			return supcheck;

		fwts_failed(fw, LOG_LEVEL_HIGH,
			"UEFIUpdateAuthVar",
			"Failed to update authenticated variable with UEFI "
			"runtime service.");

		fwts_uefi_print_status_info(fw, status);
		return FWTS_ERROR;
	}

	ioret = getvar(&gtestguid, &attributestest, &getdatasize, data, &status);
	if (ioret == -1) {
		fwts_failed(fw, LOG_LEVEL_HIGH,
			"UEFIUpdateAuthVar",
			"Failed to get authenticated variable with UEFI "
			"runtime service.");
		fwts_uefi_print_status_info(fw, status);
		return FWTS_ERROR;
	}

	if (getdatasize != sizeof(AuthVarUpdateData)) {
		fwts_failed(fw, LOG_LEVEL_HIGH,
			"UEFIUpdateAuthVar",
			"Get authenticated variable data size is not the "
			"same as it set.");
		return FWTS_ERROR;
	}

	for (i = 0; i < getdatasize; i++) {
		if (data[i] != AuthVarUpdateData[i]) {
			fwts_failed(fw, LOG_LEVEL_HIGH,
			"UEFIUpdateAuthVar",
			"Get authenticated variable data are not the "
			"same as it set.");
			return FWTS_ERROR;
		}
	}

	data_exist |= E_AUTHVARUPDATE;

	fwts_passed(fw, "Update authenticated variable tests passed.");

	return FWTS_OK;
}
コード例 #15
0
ファイル: uefirtauthvar.c プロジェクト: ahs3/fwts-sbbr
/*
 * Execute the normal append operation.
 */
static int uefirtauthvar_test4(fwts_framework *fw)
{
	long ioret;

	uint8_t data[getvar_buf_size];
	uint64_t getdatasize = sizeof(data);
	uint64_t status;
	uint32_t attributestest;
	size_t i;
	uint32_t attribappend = attributes | FWTS_UEFI_VARIABLE_APPEND_WRITE;

	if (!(data_exist & E_AUTHVARCREATE)) {
		fwts_skipped(fw,"The test variable, AuthVarCreate, doesn't exist, skip the test.");
		return FWTS_SKIP;
	}

	ioret = setvar(&gtestguid, attribappend, sizeof(AuthVarAppend), AuthVarAppend, &status);

	if (ioret == -1) {
		int supcheck = check_fw_support(fw, status);

		if (supcheck != FWTS_OK)
			return supcheck;

		fwts_failed(fw, LOG_LEVEL_HIGH,
			"UEFIAppendAuthVar",
			"Failed to append authenticated variable with UEFI "
			"runtime service.");

		fwts_uefi_print_status_info(fw, status);
		return FWTS_ERROR;
	}

	ioret = getvar(&gtestguid, &attributestest, &getdatasize, data, &status);
	if (ioret == -1) {
		fwts_failed(fw, LOG_LEVEL_HIGH,
			"UEFIAppendAuthVar",
			"Failed to get authenticated variable with UEFI "
			"runtime service.");
		fwts_uefi_print_status_info(fw, status);
		return FWTS_ERROR;
	}

	if (getdatasize != (sizeof(AuthVarCreateData) + sizeof(AuthVarAppendData))) {
		fwts_failed(fw, LOG_LEVEL_HIGH,
			"UEFIAppendAuthVar",
			"Get total authenticated variable data size is not the "
			"same as it set and appended.");
		return FWTS_ERROR;
	}

	for (i = 0; i < getdatasize; i++) {
		if (i < sizeof(AuthVarCreateData)) {
			if (data[i] != AuthVarCreateData[i]) {
				fwts_failed(fw, LOG_LEVEL_HIGH,
				"UEFIAppendAuthVar",
				"Get authenticated variable data are not the "
				"same as it set.");
				return FWTS_ERROR;
			}
		} else {
			if (data[i] != AuthVarAppendData[i - sizeof(AuthVarCreateData)]) {
				fwts_failed(fw, LOG_LEVEL_HIGH,
				"UEFIAppendAuthVar",
				"Get authenticated variable data are not the "
				"same as it set.");
				return FWTS_ERROR;
			}
		}
	}

	data_exist |= E_AUTHVARAPPEND;

	fwts_passed(fw, "Append authenticated variable tests passed.");

	return FWTS_OK;
}