summaryrefslogtreecommitdiffstats
path: root/command
diff options
context:
space:
mode:
Diffstat (limited to 'command')
-rw-r--r--command/guid.cpp50
-rw-r--r--command/guid.hpp18
-rw-r--r--command/rakp12.cpp7
-rw-r--r--command/rakp34.cpp3
4 files changed, 58 insertions, 20 deletions
diff --git a/command/guid.cpp b/command/guid.cpp
index 556484d..0943846 100644
--- a/command/guid.cpp
+++ b/command/guid.cpp
@@ -7,21 +7,28 @@
#include <host-ipmid/ipmid-api.h>
#include <mapper.h>
+namespace cache
+{
+
+command::Guid guid;
+
+} // namespace cache
+
namespace command
{
-std::array<uint8_t, BMC_GUID_LEN> getSystemGUID()
+std::unique_ptr<sdbusplus::bus::match_t> matchPtr(nullptr);
+
+static constexpr auto guidObjPath = "/org/openbmc/control/chassis0";
+static constexpr auto propInterface = "org.freedesktop.DBus.Properties";
+
+Guid 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";
+ Guid guid = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
+ 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10 };
+
constexpr auto chassisIntf = "org.openbmc.control.Chassis";
sd_bus_message* reply = nullptr;
@@ -33,16 +40,16 @@ std::array<uint8_t, BMC_GUID_LEN> getSystemGUID()
do
{
- rc = mapper_get_service(bus, objname, &busname);
+ rc = mapper_get_service(bus, guidObjPath, &busname);
if (rc < 0)
{
- std::cerr << "Failed to get " << objname << " bus name: "
+ std::cerr << "Failed to get " << guidObjPath << " bus name: "
<< strerror(-rc) << "\n";
break;
}
- rc = sd_bus_call_method(bus, busname, objname, interface, "Get", &error,
- &reply, "ss", chassisIntf, "uuid");
+ rc = sd_bus_call_method(bus, busname, guidObjPath, propInterface, "Get",
+ &error, &reply, "ss", chassisIntf, "uuid");
if (rc < 0)
{
std::cerr << "Failed to call Get Method:" << strerror(-rc) << "\n";
@@ -76,4 +83,21 @@ std::array<uint8_t, BMC_GUID_LEN> getSystemGUID()
return guid;
}
+void registerGUIDChangeCallback()
+{
+ if(matchPtr == nullptr)
+ {
+ using namespace sdbusplus::bus::match::rules;
+ sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
+
+ matchPtr = std::make_unique<sdbusplus::bus::match_t>(
+ bus,
+ path_namespace(guidObjPath) +
+ type::signal() +
+ member("PropertiesChanged") +
+ interface(propInterface),
+ [](sdbusplus::message::message&){cache::guid = getSystemGUID();});
+ }
+}
+
} // namespace command
diff --git a/command/guid.hpp b/command/guid.hpp
index 622b330..5941ef8 100644
--- a/command/guid.hpp
+++ b/command/guid.hpp
@@ -2,7 +2,7 @@
#include <cstddef>
#include <vector>
-
+#include <sdbusplus/bus/match.hpp>
#include "comm_module.hpp"
namespace command
@@ -10,12 +10,26 @@ namespace command
constexpr size_t BMC_GUID_LEN = 16;
+using Guid = std::array<uint8_t, BMC_GUID_LEN>;
+
/**
* @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();
+Guid getSystemGUID();
+
+/**
+ * @brief Register the callback to update the cache when the GUID changes
+ */
+void registerGUIDChangeCallback();
} // namespace command
+
+namespace cache
+{
+
+extern command::Guid guid;
+
+} //namespace cache
diff --git a/command/rakp12.cpp b/command/rakp12.cpp
index 19dc160..e5ea3a7 100644
--- a/command/rakp12.cpp
+++ b/command/rakp12.cpp
@@ -113,8 +113,7 @@ std::vector<uint8_t> RAKP12(const std::vector<uint8_t>& inPayload,
std::advance(iter, cipher::rakp_auth::BMC_RANDOM_NUMBER_LEN);
// Managed System GUID
- auto guid = getSystemGUID();
- std::copy_n(guid.data(), guid.size(), iter);
+ std::copy_n(cache::guid.data(), cache::guid.size(), iter);
std::advance(iter, BMC_GUID_LEN);
// Requested Privilege Level
@@ -144,7 +143,9 @@ std::vector<uint8_t> RAKP12(const std::vector<uint8_t>& inPayload,
response->managed_system_random_number);
// Copy System GUID to the Response
- std::copy_n(guid.data(), guid.size(), response->managed_system_guid);
+ std::copy_n(cache::guid.data(),
+ cache::guid.size(),
+ response->managed_system_guid);
// Insert the HMAC output into the payload
outPayload.insert(outPayload.end(), output.begin(), output.end());
diff --git a/command/rakp34.cpp b/command/rakp34.cpp
index 95b8af7..8c95e95 100644
--- a/command/rakp34.cpp
+++ b/command/rakp34.cpp
@@ -233,8 +233,7 @@ std::vector<uint8_t> RAKP34(const std::vector<uint8_t>& inPayload,
std::advance(iter, sizeof(bmcSessionID));
// Managed System GUID
- auto guid = getSystemGUID();
- std::copy_n(guid.data(), guid.size(), iter);
+ std::copy_n(cache::guid.data(), cache::guid.size(), iter);
// Integrity Check Value
auto icv = authAlgo->generateICV(input);
OpenPOWER on IntegriCloud