From 14938782b62f5cd91b13f86c7de5b193e21f149d Mon Sep 17 00:00:00 2001 From: Sid Hsu Date: Thu, 23 Jun 2022 20:42:21 +0800 Subject: [PATCH] [Infineon][TC-DGGEN-2.1] CYW30739 supports responding IPv6Addresses in NetworkInterface. (#19866) Co-authored-by: Justin Wood --- .../CYW30739/DiagnosticDataProviderImpl.cpp | 21 ++++++++++++++++--- .../CYW30739/DiagnosticDataProviderImpl.h | 10 --------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/platform/CYW30739/DiagnosticDataProviderImpl.cpp b/src/platform/CYW30739/DiagnosticDataProviderImpl.cpp index b286b474531867..a205ffb84a23be 100644 --- a/src/platform/CYW30739/DiagnosticDataProviderImpl.cpp +++ b/src/platform/CYW30739/DiagnosticDataProviderImpl.cpp @@ -98,7 +98,7 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetBootReason(BootReasonType & bootReason #if CHIP_DEVICE_CONFIG_ENABLE_THREAD CHIP_ERROR DiagnosticDataProviderImpl::GetNetworkInterfaces(NetworkInterface ** netifpp) { - auto ifp = Platform::New(); + auto ifp = Platform::New(); VerifyOrReturnError(ifp != nullptr, CHIP_ERROR_NO_MEMORY); const char * threadNetworkName = otThreadGetNetworkName(ThreadStackMgrImpl().OTInstance()); @@ -106,10 +106,25 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetNetworkInterfaces(NetworkInterface ** ifp->isOperational = true; ifp->offPremiseServicesReachableIPv4.SetNull(); ifp->offPremiseServicesReachableIPv6.SetNull(); - ifp->hardwareAddress = ByteSpan(ifp->macBuffer); + ifp->hardwareAddress = ByteSpan(ifp->MacAddress); ifp->type = app::Clusters::GeneralDiagnostics::InterfaceType::EMBER_ZCL_INTERFACE_TYPE_THREAD; - ConfigurationMgr().GetPrimary802154MACAddress(ifp->macBuffer); + static_assert(sizeof(ifp->MacAddress) >= ConfigurationManager::kPrimaryMACAddressLength, "Invalid MacAddress buffer size"); + ConfigurationMgr().GetPrimary802154MACAddress(ifp->MacAddress); + + /* Thread only support IPv6 */ + uint8_t ipv6AddressesCount = 0; + for (Inet::InterfaceAddressIterator iterator; iterator.Next() && ipv6AddressesCount < kMaxIPv6AddrCount;) + { + chip::Inet::IPAddress ipv6Address; + if (iterator.GetAddress(ipv6Address) == CHIP_NO_ERROR) + { + memcpy(ifp->Ipv6AddressesBuffer[ipv6AddressesCount], ipv6Address.Addr, kMaxIPv6AddrSize); + ifp->Ipv6AddressSpans[ipv6AddressesCount] = ByteSpan(ifp->Ipv6AddressesBuffer[ipv6AddressesCount]); + ipv6AddressesCount++; + } + } + ifp->IPv6Addresses = app::DataModel::List(ifp->Ipv6AddressSpans, ipv6AddressesCount); *netifpp = ifp; return CHIP_NO_ERROR; diff --git a/src/platform/CYW30739/DiagnosticDataProviderImpl.h b/src/platform/CYW30739/DiagnosticDataProviderImpl.h index 9e6dd337244d02..8776da5f43157b 100644 --- a/src/platform/CYW30739/DiagnosticDataProviderImpl.h +++ b/src/platform/CYW30739/DiagnosticDataProviderImpl.h @@ -48,16 +48,6 @@ class DiagnosticDataProviderImpl : public DiagnosticDataProvider CHIP_ERROR GetNetworkInterfaces(NetworkInterface ** netifpp) override; void ReleaseNetworkInterfaces(NetworkInterface * netifp) override; #endif /* CHIP_DEVICE_CONFIG_ENABLE_THREAD */ - -private: -#if CHIP_DEVICE_CONFIG_ENABLE_THREAD - struct ThreadNetworkInterface : public NetworkInterface - { - ~ThreadNetworkInterface() = delete; - - uint8_t macBuffer[ConfigurationManager::kPrimaryMACAddressLength]; - }; -#endif /* CHIP_DEVICE_CONFIG_ENABLE_THREAD */ }; } // namespace DeviceLayer