diff --git a/src/app/clusters/general_diagnostics_server/general_diagnostics_server.cpp b/src/app/clusters/general_diagnostics_server/general_diagnostics_server.cpp index 2534d0649a0dd2..35495a16f5df82 100644 --- a/src/app/clusters/general_diagnostics_server/general_diagnostics_server.cpp +++ b/src/app/clusters/general_diagnostics_server/general_diagnostics_server.cpp @@ -16,15 +16,19 @@ */ #include +#include #include #include +#include #include +#include #include using namespace chip; using namespace chip::app; using namespace chip::app::Clusters; using namespace chip::app::Clusters::GeneralDiagnostics::Attributes; +using chip::DeviceLayer::ConnectivityMgr; using chip::DeviceLayer::PlatformManager; namespace { @@ -40,6 +44,7 @@ class GeneralDiagosticsAttrAccess : public AttributeAccessInterface private: template CHIP_ERROR ReadIfSupported(CHIP_ERROR (PlatformManager::*getter)(T &), AttributeValueEncoder & aEncoder); + CHIP_ERROR ReadNetworkInterfaces(AttributeValueEncoder & aEncoder); }; template @@ -60,6 +65,32 @@ CHIP_ERROR GeneralDiagosticsAttrAccess::ReadIfSupported(CHIP_ERROR (PlatformMana return aEncoder.Encode(data); } +CHIP_ERROR GeneralDiagosticsAttrAccess::ReadNetworkInterfaces(AttributeValueEncoder & aEncoder) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + DeviceLayer::NetworkInterface * netifs; + + if (ConnectivityMgr().GetNetworkInterfaces(&netifs) == CHIP_NO_ERROR) + { + err = aEncoder.EncodeList([&netifs](const TagBoundEncoder & encoder) -> CHIP_ERROR { + for (DeviceLayer::NetworkInterface * ifp = netifs; ifp != nullptr; ifp = ifp->Next) + { + ReturnErrorOnFailure(encoder.Encode(*ifp)); + } + + return CHIP_NO_ERROR; + }); + + ConnectivityMgr().ReleaseNetworkInterfaces(netifs); + } + else + { + err = aEncoder.Encode(DataModel::List()); + } + + return err; +} + GeneralDiagosticsAttrAccess gAttrAccess; CHIP_ERROR GeneralDiagosticsAttrAccess::Read(const ConcreteAttributePath & aPath, AttributeValueEncoder & aEncoder) @@ -72,6 +103,9 @@ CHIP_ERROR GeneralDiagosticsAttrAccess::Read(const ConcreteAttributePath & aPath switch (aPath.mAttributeId) { + case NetworkInterfaces::Id: { + return ReadNetworkInterfaces(aEncoder); + } case RebootCount::Id: { return ReadIfSupported(&PlatformManager::GetRebootCount, aEncoder); }