From 1bb28b602731bf04c31926323783507d9be5ef9a Mon Sep 17 00:00:00 2001 From: Kevin Schoedel <67607049+kpschoedel@users.noreply.github.com> Date: Wed, 8 Dec 2021 09:35:03 -0500 Subject: [PATCH] [Inet] InetIterator::GetHardwareAddress for LwIP (#12687) * [Inet] InetIterator::GetHardwareAddress for LwIP #### Problem 1b2413793424 (#12552) added `InetIterator::GetHardwareAddress()`, with an implementation for Zephyr and stubs for other builds. #### Change overview Implement `GetHardwareAddress()` for LwIP builds. (For sockets builds, there is no cross-platform access to the hardware MAC. Linux could use `SIOCGIFHWADDR`.) #### Testing CI (test from #12552) * fix buffer size check --- src/inet/InetInterface.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/inet/InetInterface.cpp b/src/inet/InetInterface.cpp index a69f7b6281ef37..637ae2ee789e15 100644 --- a/src/inet/InetInterface.cpp +++ b/src/inet/InetInterface.cpp @@ -172,7 +172,12 @@ CHIP_ERROR InterfaceIterator::GetInterfaceType(InterfaceType & type) CHIP_ERROR InterfaceIterator::GetHardwareAddress(uint8_t * addressBuffer, uint8_t & addressSize, uint8_t addressBufferSize) { - return CHIP_ERROR_NOT_IMPLEMENTED; + VerifyOrReturnError(addressBuffer != nullptr, CHIP_ERROR_INVALID_ARGUMENT); + VerifyOrReturnError(HasCurrent(), CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturnError(addressBufferSize >= mCurNetif->hwaddr_len, CHIP_ERROR_BUFFER_TOO_SMALL); + addressSize = mCurNetif->hwaddr_len; + memcpy(addressBuffer, mCurNetif->hwaddr, addressSize); + return CHIP_NO_ERROR; } bool InterfaceAddressIterator::HasCurrent()