Skip to content

Commit

Permalink
[Inet] Fix Interface Address Iterator OpenThread (#17648)
Browse files Browse the repository at this point in the history
* Fix Interface Address Iterator OpenThread

* Apply PR comments
  • Loading branch information
jepenven-silabs authored Apr 22, 2022
1 parent 7e9196c commit fa087ea
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 9 deletions.
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 @@ -169,6 +171,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;

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

0 comments on commit fa087ea

Please sign in to comment.