blob: 85a28b61d8462ca2c51c08b29864afcfd54258f7 [file] [log] [blame] [edit]
#include "types.hpp"
#include "utils.hpp"
#include <ipmid/api.hpp>
#include <regex>
namespace ipmi
{
namespace iei
{
namespace firmware_version
{
void registerIEIFirmwareVersionFunctions() __attribute__((constructor));
static constexpr auto versionInterface = "xyz.openbmc_project.Software.Version";
std::string getBMCVersionValue(ipmi::Context::ptr ctx,
const std::string& objPath,
const std::string& interface)
{
std::string value{};
auto cc = iei::getDbusProperty(ctx, objPath, interface, "Version", value);
if (cc)
{
return "";
}
const std::regex patternId("v[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}");
std::smatch result;
if (!std::regex_search(value, result, patternId))
{
return "";
}
std::string versionStr = result[0];
return versionStr.substr(1);
}
std::string getFWVersionValue(ipmi::Context::ptr ctx,
const std::string& objPath,
const std::string& interface)
{
std::string value{};
auto cc = iei::getDbusProperty(ctx, objPath, interface, "Version", value);
if (cc)
{
return "";
}
return value;
}
enum FirmwareType : uint8_t
{
BMC = 0x01,
BIOS = 0x03,
};
RspType<std::string> ipmiIEIGetFWVersion(
ipmi::Context::ptr ctx, uint8_t fwIndex, uint8_t /* devIndex */)
{
std::string fwPath{};
std::string value{};
switch (fwIndex)
{
case BMC:
{
fwPath = "/xyz/openbmc_project/software/bmc_active";
value = getBMCVersionValue(ctx, fwPath, versionInterface);
break;
}
case BIOS:
{
fwPath = "/xyz/openbmc_project/software/bios_active";
value = getFWVersionValue(ctx, fwPath, versionInterface);
break;
}
default:
return ipmi::responseParmOutOfRange();
}
return ipmi::responseSuccess(value);
}
void registerIEIFirmwareVersionFunctions()
{
ipmi::registerHandler(prioOemBase, netFnIEI, cmdGetFWVersion,
ipmi::Privilege::User, ipmiIEIGetFWVersion);
}
} // namespace firmware_version
} // namespace iei
} // namespace ipmi