Skip to content

Commit

Permalink
[Infineon] Fix CYW30739 GetNetworkInterfaces and MatterPostAttributeC…
Browse files Browse the repository at this point in the history
…hangeCallback 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.
  • Loading branch information
hsusid authored Jun 14, 2022
1 parent 1a2c719 commit 663ecf4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
13 changes: 10 additions & 3 deletions examples/lighting-app/cyw30739/src/ZclCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 8 additions & 9 deletions src/platform/CYW30739/DiagnosticDataProviderImpl.cpp
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -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<NetworkInterface>();
auto ifp = Platform::New<ThreadNetworkInterface>();
VerifyOrReturnError(ifp != nullptr, CHIP_ERROR_NO_MEMORY);

#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
const char * threadNetworkName = otThreadGetNetworkName(ThreadStackMgrImpl().OTInstance());
ifp->name = Span<const char>(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;
Expand All @@ -126,6 +124,7 @@ void DiagnosticDataProviderImpl::ReleaseNetworkInterfaces(NetworkInterface * net
Platform::Delete(del);
}
}
#endif /* CHIP_DEVICE_CONFIG_ENABLE_THREAD */

} // namespace DeviceLayer
} // namespace chip
12 changes: 12 additions & 0 deletions src/platform/CYW30739/DiagnosticDataProviderImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 663ecf4

Please sign in to comment.