diff options
author | Tom Joseph <tomjoseph@in.ibm.com> | 2016-12-06 16:56:04 +0530 |
---|---|---|
committer | Patrick Williams <patrick@stwcx.xyz> | 2016-12-16 18:55:33 +0000 |
commit | f8da32adc673d622e24219e436bedcb2f46a02f3 (patch) | |
tree | c81ab0dbf90c8090428b9b0c07bd1b79119423c5 /command | |
parent | d3e7a61727c1b5cdf6ca236c6f46620f5d5e4a70 (diff) | |
download | phosphor-net-ipmid-f8da32adc673d622e24219e436bedcb2f46a02f3.tar.gz phosphor-net-ipmid-f8da32adc673d622e24219e436bedcb2f46a02f3.zip |
Implementation to read System UUID from Chassis DBUS object
Implementation for reading system UUID which would be consumed
by RAKP12, RAKP34 and System GUID commands.
Change-Id: Ibee1c398368f67055cdba2a0f4d16c981e38c035
Signed-off-by: Tom Joseph <tomjoseph@in.ibm.com>
Diffstat (limited to 'command')
-rw-r--r-- | command/guid.cpp | 79 | ||||
-rw-r--r-- | command/guid.hpp | 21 |
2 files changed, 100 insertions, 0 deletions
diff --git a/command/guid.cpp b/command/guid.cpp new file mode 100644 index 0000000..556484d --- /dev/null +++ b/command/guid.cpp @@ -0,0 +1,79 @@ +#include "guid.hpp" + +#include <iostream> +#include <sstream> +#include <string> + +#include <host-ipmid/ipmid-api.h> +#include <mapper.h> + +namespace command +{ + +std::array<uint8_t, BMC_GUID_LEN> getSystemGUID() +{ + // Canned System GUID for QEMU where the Chassis DBUS object is not + // populated + std::array<uint8_t, BMC_GUID_LEN> guid = { 0x01, 0x02, 0x03, 0x04, + 0x05, 0x06, 0x07, 0x08, + 0x09, 0x0A, 0x0B, 0x0C, + 0x0D, 0x0E, 0x0F, 0x10 + }; + + constexpr auto objname = "/org/openbmc/control/chassis0"; + constexpr auto interface = "org.freedesktop.DBus.Properties"; + constexpr auto chassisIntf = "org.openbmc.control.Chassis"; + + sd_bus_message* reply = nullptr; + sd_bus_error error = SD_BUS_ERROR_NULL; + sd_bus* bus = ipmid_get_sd_bus_connection(); + int rc = 0; + char* uuid = nullptr; + char* busname = nullptr; + + do + { + rc = mapper_get_service(bus, objname, &busname); + if (rc < 0) + { + std::cerr << "Failed to get " << objname << " bus name: " + << strerror(-rc) << "\n"; + break; + } + + rc = sd_bus_call_method(bus, busname, objname, interface, "Get", &error, + &reply, "ss", chassisIntf, "uuid"); + if (rc < 0) + { + std::cerr << "Failed to call Get Method:" << strerror(-rc) << "\n"; + break; + } + + rc = sd_bus_message_read(reply, "v", "s", &uuid); + if (rc < 0 || uuid == NULL) + { + std::cerr << "Failed to get a response:" << strerror(-rc) << "\n"; + break; + } + + std::string readUUID(uuid); + auto len = readUUID.length(); + + for (size_t iter = 0, inc = 0; + iter < len && inc < BMC_GUID_LEN; iter += 2, inc++) + { + uint8_t hexVal = std::strtoul(readUUID.substr(iter, 2).c_str(), + NULL, 16); + guid[inc] = hexVal; + } + } + while (0); + + sd_bus_error_free(&error); + reply = sd_bus_message_unref(reply); + free(busname); + + return guid; +} + +} // namespace command diff --git a/command/guid.hpp b/command/guid.hpp new file mode 100644 index 0000000..03c6272 --- /dev/null +++ b/command/guid.hpp @@ -0,0 +1,21 @@ +#pragma once + +#include <cstddef> +#include <vector> + +#include "comm_module.hpp" + +namespace command +{ + +constexpr size_t BMC_GUID_LEN = 16; + +/* + * @brief Get System GUID + * + * @return If UUID is successfully read from the Chassis DBUS object, then the + * GUID is returned, else a canned GUID is returned + */ +std::array<uint8_t, BMC_GUID_LEN> getSystemGUID(); + +} // namespace command |