diff --git a/common/types.hpp b/common/types.hpp index 2c5dcdbb3..83dbcbf6c 100644 --- a/common/types.hpp +++ b/common/types.hpp @@ -21,9 +21,11 @@ using Request = std::vector; using Response = std::vector; using Command = uint8_t; +using Association = std::tuple; +using InventoryPath = std::string; using MctpMedium = std::string; using NetworkId = uint32_t; -using MctpInfo = std::tuple; +using MctpInfo = std::tuple; using MctpInfos = std::vector; using tid_t = uint8_t; @@ -36,9 +38,9 @@ using Interface = std::string; using Interfaces = std::vector; using Property = std::string; using PropertyType = std::string; -using Value = - std::variant>; +using Value = std::variant, std::vector>; using PropertyMap = std::map; using InterfaceMap = std::map; diff --git a/platform-mc/test/event_manager_test.cpp b/platform-mc/test/event_manager_test.cpp index a3bc20446..c923d9e3f 100644 --- a/platform-mc/test/event_manager_test.cpp +++ b/platform-mc/test/event_manager_test.cpp @@ -205,7 +205,7 @@ TEST_F(EventManagerTest, getSensorThresholdMessageIdTest) TEST_F(EventManagerTest, SetEventReceiverTest) { // Add terminus - auto mappedTid = terminusManager.mapTid(pldm::MctpInfo(1, "", "", 1)); + auto mappedTid = terminusManager.mapTid(pldm::MctpInfo(1, "", "", 1, "")); auto tid = mappedTid.value(); termini[tid] = std::make_shared(tid, 1 << PLDM_BASE | 1 << PLDM_PLATFORM); @@ -349,7 +349,7 @@ TEST_F(EventManagerTest, SetEventReceiverTest) TEST_F(EventManagerTest, pollForPlatformEventTaskMultipartTransferTest) { // Add terminus - auto mappedTid = terminusManager.mapTid(pldm::MctpInfo(1, "", "", 1)); + auto mappedTid = terminusManager.mapTid(pldm::MctpInfo(1, "", "", 1, "")); auto tid = mappedTid.value(); termini[tid] = std::make_shared(tid, 1 << PLDM_BASE | 1 << PLDM_PLATFORM); diff --git a/platform-mc/test/platform_manager_test.cpp b/platform-mc/test/platform_manager_test.cpp index eed03a2e8..eb4d0003e 100644 --- a/platform-mc/test/platform_manager_test.cpp +++ b/platform-mc/test/platform_manager_test.cpp @@ -35,7 +35,8 @@ class PlatformManagerTest : public testing::Test TEST_F(PlatformManagerTest, initTerminusTest) { // Add terminus - auto mappedTid = mockTerminusManager.mapTid(pldm::MctpInfo(1, "", "", 1)); + auto mappedTid = + mockTerminusManager.mapTid(pldm::MctpInfo(1, "", "", 1, "")); auto tid = mappedTid.value(); termini[tid] = std::make_shared(tid, 1 << PLDM_BASE | 1 << PLDM_PLATFORM); @@ -164,7 +165,8 @@ TEST_F(PlatformManagerTest, initTerminusTest) TEST_F(PlatformManagerTest, negativeInitTerminusTest1) { // terminus doesn't Type2 support - auto mappedTid = mockTerminusManager.mapTid(pldm::MctpInfo(1, "", "", 1)); + auto mappedTid = + mockTerminusManager.mapTid(pldm::MctpInfo(1, "", "", 1, "")); auto tid = mappedTid.value(); termini[tid] = std::make_shared(tid, 1 << PLDM_BASE); auto terminus = termini[tid]; @@ -178,7 +180,8 @@ TEST_F(PlatformManagerTest, negativeInitTerminusTest1) TEST_F(PlatformManagerTest, negativeInitTerminusTest2) { // terminus responses error - auto mappedTid = mockTerminusManager.mapTid(pldm::MctpInfo(1, "", "", 1)); + auto mappedTid = + mockTerminusManager.mapTid(pldm::MctpInfo(1, "", "", 1, "")); auto tid = mappedTid.value(); termini[tid] = std::make_shared(tid, 1 << PLDM_BASE | 1 << PLDM_PLATFORM); diff --git a/platform-mc/test/terminus_manager_test.cpp b/platform-mc/test/terminus_manager_test.cpp index 2fb3f1e50..f09b24a17 100644 --- a/platform-mc/test/terminus_manager_test.cpp +++ b/platform-mc/test/terminus_manager_test.cpp @@ -47,7 +47,7 @@ class TerminusManagerTest : public testing::Test TEST_F(TerminusManagerTest, mapTidTest) { - pldm::MctpInfo mctpInfo1(1, "", "", 0); + pldm::MctpInfo mctpInfo1(1, "", "", 0, ""); auto mappedTid1 = terminusManager.mapTid(mctpInfo1); EXPECT_NE(mappedTid1, std::nullopt); @@ -68,38 +68,38 @@ TEST_F(TerminusManagerTest, mapTidTest) TEST_F(TerminusManagerTest, negativeMapTidTest) { // map null EID(0) to TID - pldm::MctpInfo m0(0, "", "", 0); + pldm::MctpInfo m0(0, "", "", 0, ""); auto mappedTid = terminusManager.mapTid(m0); EXPECT_EQ(mappedTid, std::nullopt); // map broadcast EID(0xff) to TID - pldm::MctpInfo m1(0xff, "", "", 0); + pldm::MctpInfo m1(0xff, "", "", 0, ""); mappedTid = terminusManager.mapTid(m1); EXPECT_EQ(mappedTid, std::nullopt); // map EID to tid which has been assigned - pldm::MctpInfo m2(2, "", "", 1); - pldm::MctpInfo m3(3, "", "", 1); + pldm::MctpInfo m2(2, "", "", 1, ""); + pldm::MctpInfo m3(3, "", "", 1, ""); auto mappedTid2 = terminusManager.mapTid(m2); auto mappedTid3 = terminusManager.mapTid(m3, mappedTid2.value()); EXPECT_NE(mappedTid2, std::nullopt); EXPECT_EQ(mappedTid3, std::nullopt); // map two mctpInfo with same EID but different network Id - pldm::MctpInfo m4(12, "", "", 1); - pldm::MctpInfo m5(12, "", "", 2); + pldm::MctpInfo m4(12, "", "", 1, ""); + pldm::MctpInfo m5(12, "", "", 2, ""); auto mappedTid4 = terminusManager.mapTid(m4); auto mappedTid5 = terminusManager.mapTid(m5); EXPECT_NE(mappedTid4.value(), mappedTid5.value()); // map same mctpInfo twice - pldm::MctpInfo m6(12, "", "", 3); + pldm::MctpInfo m6(12, "", "", 3, ""); auto mappedTid6 = terminusManager.mapTid(m6); auto mappedTid6_1 = terminusManager.mapTid(m6); EXPECT_EQ(mappedTid6.value(), mappedTid6_1.value()); // look up an unmapped MctpInfo to TID - pldm::MctpInfo m7(1, "", "", 0); + pldm::MctpInfo m7(1, "", "", 0, ""); auto mappedTid7 = terminusManager.toTid(m7); EXPECT_EQ(mappedTid7, std::nullopt); @@ -153,7 +153,7 @@ TEST_F(TerminusManagerTest, discoverMctpTerminusTest) EXPECT_EQ(rc, PLDM_SUCCESS); pldm::MctpInfos mctpInfos{}; - mctpInfos.emplace_back(pldm::MctpInfo(12, "", "", 1)); + mctpInfos.emplace_back(pldm::MctpInfo(12, "", "", 1, "")); mockTerminusManager.discoverMctpTerminus(mctpInfos); EXPECT_EQ(1, termini.size()); @@ -198,7 +198,7 @@ TEST_F(TerminusManagerTest, negativeDiscoverMctpTerminusTest) EXPECT_EQ(rc, PLDM_SUCCESS); pldm::MctpInfos mctpInfos{}; - mctpInfos.emplace_back(pldm::MctpInfo(12, "", "", 1)); + mctpInfos.emplace_back(pldm::MctpInfo(12, "", "", 1, "")); mockTerminusManager.discoverMctpTerminus(mctpInfos); EXPECT_EQ(0, termini.size()); diff --git a/requester/mctp_endpoint_discovery.cpp b/requester/mctp_endpoint_discovery.cpp index 1004e50b8..94c198ac0 100644 --- a/requester/mctp_endpoint_discovery.cpp +++ b/requester/mctp_endpoint_discovery.cpp @@ -26,6 +26,8 @@ constexpr auto PROPERTY_INTERFACE = "org.freedesktop.DBus.Properties"; constexpr auto MCTP_INTERFACE = "xyz.openbmc_project.MCTP.Endpoint"; constexpr auto MCTP_OBJECT_PATH = "/xyz/openbmc_project/mctp"; +constexpr auto ASSOCIATION_INTERFACE = + "xyz.openbmc_project.Association.Definitions"; MctpDiscovery::MctpDiscovery( sdbusplus::bus::bus& bus, @@ -74,6 +76,9 @@ void MctpDiscovery::getMctpInfos(MctpInfos& mctpInfos) for (const auto& serviceIter : services) { const std::string& service = serviceIter.first; + MctpInfo mctpInfo; + using Property = std::string; + using PropertyMap = std::map; try { @@ -82,8 +87,6 @@ void MctpDiscovery::getMctpInfos(MctpInfos& mctpInfos) method.append(MCTP_INTERFACE); auto response = bus.call(method, dbusTimeout); - using Property = std::string; - using PropertyMap = std::map; PropertyMap properties; response.read(properties); @@ -102,7 +105,11 @@ void MctpDiscovery::getMctpInfos(MctpInfos& mctpInfos) std::cerr << "Adding Endpoint networkId " << networkId << " EID " << unsigned(eid) << "\n"; mctpInfos.emplace_back( - MctpInfo(eid, emptyUUID, "", networkId)); + MctpInfo(eid, emptyUUID, "", networkId, "")); + } + else + { + continue; } } } @@ -113,6 +120,39 @@ void MctpDiscovery::getMctpInfos(MctpInfos& mctpInfos) << " PATH: " << path << std::endl; return; } + + const auto interfaces = serviceIter.second; + if (std::find(interfaces.begin(), interfaces.end(), + ASSOCIATION_INTERFACE) != interfaces.end()) + { + try + { + auto method = + bus.new_method_call(service.c_str(), path.c_str(), + PROPERTY_INTERFACE, "GetAll"); + method.append(ASSOCIATION_INTERFACE); + + auto response = bus.call(method, dbusTimeout); + PropertyMap properties; + response.read(properties); + + if (properties.contains("Associations")) + { + auto associations = std::get>( + properties.at("Associations")); + std::get<4>(mctpInfos.back()) = + std::get<2>(associations.front()); + } + } + catch (const sdbusplus::exception_t& e) + { + std::cerr + << "Error reading MCTP Endpoint association, error: " + << e.what() << " SERVICE: " << service + << " PATH: " << path << std::endl; + return; + } + } } } } @@ -138,6 +178,7 @@ void MctpDiscovery::getAddedMctpInfos(sdbusplus::message_t& msg, return; } + MctpInfo mctpInfo; for (const auto& [intfName, properties] : interfaces) { if (intfName == MCTP_INTERFACE) @@ -156,11 +197,28 @@ void MctpDiscovery::getAddedMctpInfos(sdbusplus::message_t& msg, { std::cerr << "Adding Endpoint networkId " << networkId << " EID " << unsigned(eid) << "\n"; - mctpInfos.emplace_back( - MctpInfo(eid, emptyUUID, "", networkId)); + std::get<0>(mctpInfo) = eid; + std::get<1>(mctpInfo) = emptyUUID; + std::get<2>(mctpInfo) = ""; + std::get<3>(mctpInfo) = networkId; } } } + + if (intfName == ASSOCIATION_INTERFACE) + { + if (properties.contains("Associations")) + { + auto associations = std::get>( + properties.at("Associations")); + std::get<4>(mctpInfo) = std::get<2>(associations.front()); + } + } + } + // Make sure we got the eid + if (std::get<0>(mctpInfo)) + { + mctpInfos.emplace_back(mctpInfo); } } @@ -238,9 +296,10 @@ void MctpDiscovery::loadStaticEndpoints(MctpInfos& mctpInfos) auto networkId = endpoint.value("NetworkId", 0xFF); auto eid = endpoint.value("EID", 0xFF); auto types = endpoint.value("SupportedMessageTypes", emptyUnit8Array); + auto inventoryPath = endpoint.value("InventoryPath", ""); if (std::find(types.begin(), types.end(), mctpTypePLDM) != types.end()) { - MctpInfo mctpInfo(eid, emptyUUID, "", networkId); + MctpInfo mctpInfo(eid, emptyUUID, "", networkId, inventoryPath); if (std::find(mctpInfos.begin(), mctpInfos.end(), mctpInfo) == mctpInfos.end()) {