From 663ecf4ce3b11d76cb5b946800be4ea9a47a2d8c Mon Sep 17 00:00:00 2001 From: Sid Hsu Date: Wed, 15 Jun 2022 07:16:16 +0800 Subject: [PATCH] [Infineon] Fix CYW30739 GetNetworkInterfaces and MatterPostAttributeChangeCallback methods. (#19568) * Fix returning a dangling pointer for CYW30739 GetNetworkInterfaces method. DiagnosticDataProviderImpl::GetNetworkInterfaces no longer returns a dangling pointer to the stack buffer. * Use the accessor to read IdentifyTime for CYW30739. --- .../lighting-app/cyw30739/src/ZclCallbacks.cpp | 13 ++++++++++--- .../CYW30739/DiagnosticDataProviderImpl.cpp | 17 ++++++++--------- .../CYW30739/DiagnosticDataProviderImpl.h | 12 ++++++++++++ 3 files changed, 30 insertions(+), 12 deletions(-) mode change 100755 => 100644 src/platform/CYW30739/DiagnosticDataProviderImpl.cpp diff --git a/examples/lighting-app/cyw30739/src/ZclCallbacks.cpp b/examples/lighting-app/cyw30739/src/ZclCallbacks.cpp index df3fcf7721d1a4..ba9eb4056d3b72 100644 --- a/examples/lighting-app/cyw30739/src/ZclCallbacks.cpp +++ b/examples/lighting-app/cyw30739/src/ZclCallbacks.cpp @@ -64,9 +64,16 @@ void MatterPostAttributeChangeCallback(const app::ConcreteAttributePath & attrib } break; case Identify::Id: - ChipLogProgress(Zcl, "Identify attribute ID: " ChipLogFormatMEI " Type: %u Value: %u, length %u", - ChipLogValueMEI(attributePath.mClusterId), type, *value, size); - return; + if (attributePath.mAttributeId == Identify::Attributes::IdentifyTime::Id) + { + uint16_t identifyTime; + if (EMBER_ZCL_STATUS_SUCCESS == Identify::Attributes::IdentifyTime::Get(attributePath.mEndpointId, &identifyTime)) + { + ChipLogProgress(Zcl, "IdentifyTime %u", identifyTime); + return; + } + } + break; default: printf("Unhandled cluster ID: 0x%04lx\n", attributePath.mClusterId); return; diff --git a/src/platform/CYW30739/DiagnosticDataProviderImpl.cpp b/src/platform/CYW30739/DiagnosticDataProviderImpl.cpp old mode 100755 new mode 100644 index a6a53bf45b8f93..b286b474531867 --- a/src/platform/CYW30739/DiagnosticDataProviderImpl.cpp +++ b/src/platform/CYW30739/DiagnosticDataProviderImpl.cpp @@ -95,23 +95,21 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetBootReason(BootReasonType & bootReason return err; } +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD CHIP_ERROR DiagnosticDataProviderImpl::GetNetworkInterfaces(NetworkInterface ** netifpp) { - NetworkInterface * ifp = Platform::New(); + auto ifp = Platform::New(); + VerifyOrReturnError(ifp != nullptr, CHIP_ERROR_NO_MEMORY); -#if CHIP_DEVICE_CONFIG_ENABLE_THREAD const char * threadNetworkName = otThreadGetNetworkName(ThreadStackMgrImpl().OTInstance()); ifp->name = Span(threadNetworkName, strlen(threadNetworkName)); ifp->isOperational = true; ifp->offPremiseServicesReachableIPv4.SetNull(); ifp->offPremiseServicesReachableIPv6.SetNull(); - ifp->type = app::Clusters::GeneralDiagnostics::InterfaceType::EMBER_ZCL_INTERFACE_TYPE_THREAD; -#else - /* TODO */ -#endif - uint8_t macBuffer[ConfigurationManager::kPrimaryMACAddressLength]; - ConfigurationMgr().GetPrimary802154MACAddress(macBuffer); - ifp->hardwareAddress = ByteSpan(macBuffer, ConfigurationManager::kPrimaryMACAddressLength); + ifp->hardwareAddress = ByteSpan(ifp->macBuffer); + ifp->type = app::Clusters::GeneralDiagnostics::InterfaceType::EMBER_ZCL_INTERFACE_TYPE_THREAD; + + ConfigurationMgr().GetPrimary802154MACAddress(ifp->macBuffer); *netifpp = ifp; return CHIP_NO_ERROR; @@ -126,6 +124,7 @@ void DiagnosticDataProviderImpl::ReleaseNetworkInterfaces(NetworkInterface * net Platform::Delete(del); } } +#endif /* CHIP_DEVICE_CONFIG_ENABLE_THREAD */ } // namespace DeviceLayer } // namespace chip diff --git a/src/platform/CYW30739/DiagnosticDataProviderImpl.h b/src/platform/CYW30739/DiagnosticDataProviderImpl.h index ff8739a2b05e73..9e6dd337244d02 100644 --- a/src/platform/CYW30739/DiagnosticDataProviderImpl.h +++ b/src/platform/CYW30739/DiagnosticDataProviderImpl.h @@ -44,8 +44,20 @@ class DiagnosticDataProviderImpl : public DiagnosticDataProvider CHIP_ERROR GetCurrentHeapHighWatermark(uint64_t & currentHeapHighWatermark) override; CHIP_ERROR GetRebootCount(uint16_t & rebootCount) override; CHIP_ERROR GetBootReason(BootReasonType & bootReason) override; +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD 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