Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Inet] Fix Interface Address Iterator OpenThread #17648

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions src/inet/InetInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@
#include <net/net_if.h>
#endif // CHIP_SYSTEM_CONFIG_USE_ZEPHYR_NET_IF

#if CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT
#include <inet/UDPEndPointImplOpenThread.h>
#endif

#include <stdio.h>
#include <string.h>

Expand Down Expand Up @@ -105,15 +109,31 @@ bool InterfaceIterator::Next()
// TODO : Cleanup #17346
return false;
}

InterfaceAddressIterator::InterfaceAddressIterator()
{
mNetifAddrList = nullptr;
mCurAddr = nullptr;
}

bool InterfaceAddressIterator::HasCurrent()
{
return mIntfIter.HasCurrent();
return (mNetifAddrList != nullptr) ? (mCurAddr != nullptr) : Next();
}

bool InterfaceAddressIterator::Next()
{
// TODO : Cleanup #17346
return false;
if (mNetifAddrList == nullptr)
{
mNetifAddrList = otIp6GetUnicastAddresses(Inet::globalOtInstance);
mCurAddr = mNetifAddrList;
}
else if (mCurAddr != nullptr)
{
mCurAddr = mCurAddr->mNext;
}

return (mCurAddr != nullptr);
}
CHIP_ERROR InterfaceAddressIterator::GetAddress(IPAddress & outIPAddress)
{
Expand All @@ -122,7 +142,7 @@ CHIP_ERROR InterfaceAddressIterator::GetAddress(IPAddress & outIPAddress)
return CHIP_ERROR_SENTINEL;
}

outIPAddress = IPAddress((*(mAddrInfoList[mCurAddrIndex].mAddress)));
outIPAddress = IPAddress(mCurAddr->mAddress);
return CHIP_NO_ERROR;
}

Expand Down
6 changes: 2 additions & 4 deletions src/inet/InetInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -540,15 +540,13 @@ class DLL_EXPORT InterfaceAddressIterator
int mCurAddrIndex = -1;
#endif // CHIP_SYSTEM_CONFIG_USE_ZEPHYR_NET_IF
#if CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT
otIp6AddressInfo * mAddrInfoList;
int mCurAddrIndex;
InterfaceIterator mIntfIter;
const otNetifAddress * mNetifAddrList;
const otNetifAddress * mCurAddr;
#endif // #if CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT
};

#if CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT
inline InterfaceIterator::InterfaceIterator(void) {}
inline InterfaceAddressIterator::InterfaceAddressIterator(void) {}
inline InterfaceIterator::~InterfaceIterator() = default;
inline InterfaceAddressIterator::~InterfaceAddressIterator() = default;
inline bool InterfaceIterator::HasCurrent(void)
Expand Down
8 changes: 8 additions & 0 deletions src/inet/UDPEndPointImplOpenThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
namespace chip {
namespace Inet {

otInstance * globalOtInstance;

void UDPEndPointImplOT::handleUdpReceive(void * aContext, otMessage * aMessage, const otMessageInfo * aMessageInfo)
{
UDPEndPointImplOT * ep = static_cast<UDPEndPointImplOT *>(aContext);
Expand Down Expand Up @@ -170,6 +172,12 @@ void UDPEndPointImplOT::HandleDataReceived(System::PacketBufferHandle && msg)
}
}

void UDPEndPointImplOT::SetNativeParams(void * params)
{
mOTInstance = static_cast<otInstance *>(params);
globalOtInstance = mOTInstance;
}

CHIP_ERROR UDPEndPointImplOT::SetMulticastLoopback(IPVersion aIPVersion, bool aLoopback)
{
(void) aIPVersion;
Expand Down
4 changes: 3 additions & 1 deletion src/inet/UDPEndPointImplOpenThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
namespace chip {
namespace Inet {

extern otInstance * globalOtInstance;
jepenven-silabs marked this conversation as resolved.
Show resolved Hide resolved

class UDPEndPointImplOT : public UDPEndPoint, public EndPointStateOpenThread
{
public:
Expand All @@ -44,7 +46,7 @@ class UDPEndPointImplOT : public UDPEndPoint, public EndPointStateOpenThread
uint16_t GetBoundPort() const override;
void Free() override;
void HandleDataReceived(System::PacketBufferHandle && msg);
inline void SetNativeParams(void * params) { mOTInstance = static_cast<otInstance *>(params); }
void SetNativeParams(void * params);
CHIP_ERROR SetMulticastLoopback(IPVersion aIPVersion, bool aLoopback) override;
CHIP_ERROR BindInterfaceImpl(IPAddressType addressType, InterfaceId interfaceId) override;

Expand Down