Add two MAC addresses support for Mihawk's 2 NICs
In somes systms, there are 2 MAC addresses for 2 NICs like mihawk. In
order to support system like Mihawk, check the object path of
NetworkInterface to find the corresponding object of NIC.
Tested: Get the 2 MAC addresses of eth0 and eth1 from inventory
Signed-off-by: Alvin Wang <alvinwang@msn.com>
Change-Id: I2ee08c020010bccd7e46b94d69f5fd80a639aef7
diff --git a/util.cpp b/util.cpp
index f1fd4cd..afbc229 100644
--- a/util.cpp
+++ b/util.cpp
@@ -519,7 +519,8 @@
"xyz.openbmc_project.Inventory.Item.NetworkInterface";
constexpr auto invRoot = "/xyz/openbmc_project/inventory";
-ether_addr getfromInventory(sdbusplus::bus::bus& bus)
+ether_addr getfromInventory(sdbusplus::bus::bus& bus,
+ const std::string& intfName)
{
std::vector<DbusInterface> interfaces;
interfaces.emplace_back(invNetworkIntf);
@@ -548,10 +549,37 @@
elog<InternalFailure>();
}
- // It is expected that only one object has implemented this interface.
+ DbusObjectPath objPath;
+ DbusService service;
- auto objPath = objectTree.begin()->first;
- auto service = objectTree.begin()->second.begin()->first;
+ if (1 == objectTree.size())
+ {
+ objPath = objectTree.begin()->first;
+ service = objectTree.begin()->second.begin()->first;
+ }
+ else
+ {
+ // If there are more than 2 objects, object path must contain the
+ // interface name
+ for (auto const& object : objectTree)
+ {
+ log<level::INFO>("interface", entry("INT=%s", intfName.c_str()));
+ log<level::INFO>("object", entry("OBJ=%s", object.first.c_str()));
+ if (std::string::npos != object.first.find(intfName))
+ {
+ objPath = object.first;
+ service = object.second.begin()->first;
+ break;
+ }
+ }
+
+ if (objPath.empty())
+ {
+ log<level::ERR>("Can't find the object for the interface",
+ entry("intfName=%s", intfName.c_str()));
+ elog<InternalFailure>();
+ }
+ }
auto method = bus.new_method_call(service.c_str(), objPath.c_str(),
propIntf, methodGet);