#include "tpm_software_manager.hpp" #include "common/include/dbus_helper.hpp" #include "tpm_device.hpp" #include PHOSPHOR_LOG2_USING; namespace SoftwareInf = phosphor::software; void TPMSoftwareManager::start() { std::vector configIntfs = { "xyz.openbmc_project.Configuration.TPM2Firmware", }; ctx.spawn(initDevices(configIntfs)); ctx.run(); } sdbusplus::async::task TPMSoftwareManager::initDevice( const std::string& service, const std::string& path, SoftwareConfig& config) { const std::string configIface = "xyz.openbmc_project.Configuration." + config.configType; std::optional tpmIndex = co_await dbusGetRequiredProperty( ctx, service, path, configIface, "TPMIndex"); if (!tpmIndex.has_value()) { error("Missing property: TPMIndex"); co_return false; } std::optional type = co_await dbusGetRequiredProperty(ctx, service, path, configIface, "Type"); if (!type.has_value()) { error("Missing property: Type"); co_return false; } TPMType tpmType; if (!stringToTPMType(type.value(), tpmType)) { error("Invalid TPM type: {TYPE}", "TYPE", type.value()); co_return false; } debug("TPM device: TPM Index={INDEX}, Type={TYPE}", "INDEX", tpmIndex.value(), "TYPE", type.value()); auto tpmDevice = std::make_unique(ctx, tpmType, tpmIndex.value(), config, this); std::unique_ptr software = std::make_unique(ctx, *tpmDevice); software->setVersion(co_await tpmDevice->getVersion()); if (tpmDevice->isUpdateSupported()) { std::set allowedApplyTimes = { RequestedApplyTimes::OnReset}; software->enableUpdate(allowedApplyTimes); } tpmDevice->softwareCurrent = std::move(software); devices.insert({config.objectPath, std::move(tpmDevice)}); co_return true; } int main() { sdbusplus::async::context ctx; TPMSoftwareManager tpmSoftwareManager(ctx); tpmSoftwareManager.start(); return 0; }