Skip to content

Commit

Permalink
Addressed review comments - empty implementations and unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kkasperczyk-no committed Dec 6, 2021
1 parent 4ad880f commit eeaaa34
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 33 deletions.
37 changes: 31 additions & 6 deletions src/inet/InetInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,16 @@ bool InterfaceIterator::HasBroadcastAddress()
return HasCurrent() && (mCurNetif->flags & NETIF_FLAG_BROADCAST) != 0;
}

CHIP_ERROR InterfaceIterator::GetInterfaceType(InterfaceType & type) const
{
return CHIP_ERROR_NOT_IMPLEMENTED;
}

CHIP_ERROR InterfaceIterator::GetHardwareAddress(uint8_t * addressBuffer, uint8_t & addressSize, uint8_t addressBufferSize) const
{
return CHIP_ERROR_NOT_IMPLEMENTED;
}

bool InterfaceAddressIterator::HasCurrent()
{
return mIntfIter.HasCurrent() && ((mCurAddrIndex != kBeforeStartIndex) || Next());
Expand Down Expand Up @@ -619,6 +629,16 @@ short InterfaceIterator::GetFlags()
return mIntfFlags;
}

CHIP_ERROR InterfaceIterator::GetInterfaceType(InterfaceType & type) const
{
return CHIP_ERROR_NOT_IMPLEMENTED;
}

CHIP_ERROR InterfaceIterator::GetHardwareAddress(uint8_t * addressBuffer, uint8_t & addressSize, uint8_t addressBufferSize) const
{
return CHIP_ERROR_NOT_IMPLEMENTED;
}

InterfaceAddressIterator::InterfaceAddressIterator()
{
mAddrsList = nullptr;
Expand Down Expand Up @@ -850,36 +870,41 @@ bool InterfaceIterator::HasBroadcastAddress()
return HasCurrent() && INET_CONFIG_ENABLE_IPV4;
}

InterfaceType InterfaceIterator::GetInterfaceType() const
CHIP_ERROR InterfaceIterator::GetInterfaceType(InterfaceType & type) const
{
const net_linkaddr * linkAddr = net_if_get_link_addr(mCurrentInterface);
if (!linkAddr)
return InterfaceType::Unknown;
return CHIP_ERROR_INCORRECT_STATE;

// Do not consider other than WiFi and Thread for now.
if (linkAddr->type == NET_LINK_IEEE802154)
{
return InterfaceType::Thread;
type = InterfaceType::Thread;
}
// Zephyr doesn't define WiFi address type, so it shares the same type as Ethernet.
else if (linkAddr->type == NET_LINK_ETHERNET)
{
return InterfaceType::WiFi;
type = InterfaceType::WiFi;
}
else
{
return InterfaceType::Unknown;
type = InterfaceType::Unknown;
}

return CHIP_NO_ERROR;
}

CHIP_ERROR InterfaceIterator::GetHardwareAddress(uint8_t * addressBuffer, uint8_t & addressSize, uint8_t addressBufferSize) const
{
if (!addressBuffer)
return CHIP_ERROR_INVALID_ARGUMENT;

const net_linkaddr * linkAddr = net_if_get_link_addr(mCurrentInterface);
if (!linkAddr)
return CHIP_ERROR_INCORRECT_STATE;

if (linkAddr->len > addressBufferSize)
return CHIP_ERROR_INVALID_ARGUMENT;
return CHIP_ERROR_BUFFER_TOO_SMALL;

addressSize = linkAddr->len;
memcpy(addressBuffer, linkAddr->addr, linkAddr->len);
Expand Down
14 changes: 7 additions & 7 deletions src/inet/InetInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,21 +311,21 @@ class InterfaceIterator
*/
bool HasBroadcastAddress();

#if CHIP_SYSTEM_CONFIG_USE_ZEPHYR_NET_IF
/**
* Returns interface type of the current network interface.
* Get the interface type of the current network interface.
*
* @param[out] type Object to save the interface type.
*/
InterfaceType GetInterfaceType() const;
CHIP_ERROR GetInterfaceType(InterfaceType & type) const;

/**
* Get the hardware address of the current network interface
*
* @param[in] addressBuffer Region of memory to write the hardware address.
* @param[in] addressSize Size of the address saved to a buffer.
* @param[in] addressBufferSize Maximum size of a buffer to save data.
* @param[out] addressBuffer Region of memory to write the hardware address.
* @param[out] addressSize Size of the address saved to a buffer.
* @param[in] addressBufferSize Maximum size of a buffer to save data.
*/
CHIP_ERROR GetHardwareAddress(uint8_t * addressBuffer, uint8_t & addressSize, uint8_t addressBufferSize) const;
#endif

protected:
#if CHIP_SYSTEM_CONFIG_USE_LWIP
Expand Down
21 changes: 21 additions & 0 deletions src/inet/tests/TestInetEndPoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ static void TestInetInterface(nlTestSuite * inSuite, void * inContext)
InterfaceId intId;
IPAddress addr;
IPPrefix addrWithPrefix;
InterfaceType intType;
// 64 bit IEEE MAC address
const uint8_t kMaxHardwareAddressSize = 8;
uint8_t intHwAddress[kMaxHardwareAddressSize];
uint8_t intHwAddressSize;

CHIP_ERROR err;

#ifndef __MBED__
Expand Down Expand Up @@ -172,6 +178,21 @@ static void TestInetInterface(nlTestSuite * inSuite, void * inContext)
NL_TEST_ASSERT(inSuite, !intIterator.SupportsMulticast());
NL_TEST_ASSERT(inSuite, !intIterator.HasBroadcastAddress());

// Not all platforms support getting interface type and hardware address
err = intIterator.GetInterfaceType(intType);
NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR || err == CHIP_ERROR_NOT_IMPLEMENTED);

err = intIterator.GetHardwareAddress(intHwAddress, intHwAddressSize, sizeof(intHwAddress));
NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR || err == CHIP_ERROR_NOT_IMPLEMENTED);
if (err == CHIP_NO_ERROR)
{
NL_TEST_ASSERT(inSuite, intHwAddressSize == 6 || intHwAddressSize == 8);
NL_TEST_ASSERT(inSuite,
intIterator.GetHardwareAddress(nullptr, intHwAddressSize, sizeof(intHwAddress)) ==
CHIP_ERROR_INVALID_ARGUMENT);
NL_TEST_ASSERT(inSuite, intIterator.GetHardwareAddress(intHwAddress, intHwAddressSize, 4) == CHIP_ERROR_BUFFER_TOO_SMALL);
}

printf(" Addresses:\n");
for (; addrIterator.HasCurrent(); addrIterator.Next())
{
Expand Down
46 changes: 26 additions & 20 deletions src/platform/Zephyr/DiagnosticDataProviderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,27 +139,33 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetNetworkInterfaces(NetworkInterface **
NetworkInterface * ifp = new NetworkInterface();

interfaceIterator.GetInterfaceName(ifp->Name, Inet::InterfaceId::kMaxIfNameLength);
ifp->name = CharSpan(ifp->Name, strlen(ifp->Name));
ifp->fabricConnected = true;
Inet::InterfaceType interfaceType = interfaceIterator.GetInterfaceType();

switch (interfaceType)
ifp->name = CharSpan(ifp->Name, strlen(ifp->Name));
ifp->fabricConnected = true;
Inet::InterfaceType interfaceType;
if (interfaceIterator.GetInterfaceType(interfaceType) == CHIP_NO_ERROR)
{
switch (interfaceType)
{
case Inet::InterfaceType::Unknown:
ifp->type = EMBER_ZCL_INTERFACE_TYPE_UNSPECIFIED;
break;
case Inet::InterfaceType::WiFi:
ifp->type = EMBER_ZCL_INTERFACE_TYPE_WI_FI;
break;
case Inet::InterfaceType::Ethernet:
ifp->type = EMBER_ZCL_INTERFACE_TYPE_ETHERNET;
break;
case Inet::InterfaceType::Thread:
ifp->type = EMBER_ZCL_INTERFACE_TYPE_THREAD;
break;
case Inet::InterfaceType::Cellular:
ifp->type = EMBER_ZCL_INTERFACE_TYPE_CELLULAR;
break;
}
}
else
{
case Inet::InterfaceType::Unknown:
ifp->type = EMBER_ZCL_INTERFACE_TYPE_UNSPECIFIED;
break;
case Inet::InterfaceType::WiFi:
ifp->type = EMBER_ZCL_INTERFACE_TYPE_WI_FI;
break;
case Inet::InterfaceType::Ethernet:
ifp->type = EMBER_ZCL_INTERFACE_TYPE_ETHERNET;
break;
case Inet::InterfaceType::Thread:
ifp->type = EMBER_ZCL_INTERFACE_TYPE_THREAD;
break;
case Inet::InterfaceType::Cellular:
ifp->type = EMBER_ZCL_INTERFACE_TYPE_CELLULAR;
break;
ChipLogError(DeviceLayer, "Failed to get interface type");
}

ifp->offPremiseServicesReachableIPv4 = false;
Expand Down

0 comments on commit eeaaa34

Please sign in to comment.