diff --git a/platform-mc/terminus_manager.cpp b/platform-mc/terminus_manager.cpp index 2e548f6bf6..3865e20e1a 100644 --- a/platform-mc/terminus_manager.cpp +++ b/platform-mc/terminus_manager.cpp @@ -791,5 +791,28 @@ std::optional> TerminusManager::getMctpInfoForTid( const auto& mctpInfo = it->second; return std::make_pair(std::get<0>(mctpInfo), std::get<1>(mctpInfo)); } + +std::optional TerminusManager::getBmcMctpEid() +{ + const std::string fileName = "/var/run/bmceid0"; + + try { + std::ifstream toDevice; + + toDevice.exceptions(std::ios::failbit | std::ios::badbit); + toDevice.open(fileName); + + uint8_t bmcMctpEid = 0; + toDevice.read(reinterpret_cast(&bmcMctpEid), sizeof(bmcMctpEid)); + + return bmcMctpEid; + } + + catch (const std::ios_base::failure& iose) { + std::cerr << "In file I/O error: " << iose.what() << fileName << std::endl; + } + + return std::nullopt; +} } // namespace platform_mc } // namespace pldm diff --git a/platform-mc/terminus_manager.hpp b/platform-mc/terminus_manager.hpp index 9e3da14bcc..a64d9ca53b 100644 --- a/platform-mc/terminus_manager.hpp +++ b/platform-mc/terminus_manager.hpp @@ -152,7 +152,12 @@ class TerminusManager */ mctp_eid_t getLocalEid() { - return localEid; + auto hostEid = getBmcMctpEid(); + + if (hostEid.has_value()) + return *hostEid; + + return localEid; } /** @brief Helper function to invoke registered handlers for @@ -193,6 +198,17 @@ class TerminusManager */ std::optional> getMctpInfoForTid(pldm_tid_t tid); + /** + * @brief Get the BMC Host EID stored in a file + * + * This function looks up the a file and if the file exists and + * can be read, reads the MCTP EID stored in that file. + * + * @return std::optional Returns a BMC MCTP EID + * stored in the file and in case of any errors, return NULL value. + */ + std::optional getBmcMctpEid(); + private: /** @brief Find the terminus object pointer in termini list. *