From 8f88cba705fbba160f86cdbf9a3505ec0b7047ba Mon Sep 17 00:00:00 2001 From: Arto Kinnunen Date: Tue, 24 Nov 2020 10:24:57 +0200 Subject: [PATCH] Update EMAC connect logic with MAC address change Do not fail EMAC interface during connect if MAC address change is not supported in the selected interface. --- features/netsocket/EMACInterface.cpp | 14 ++++++++++++-- features/netsocket/NetworkInterface.h | 5 +++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/features/netsocket/EMACInterface.cpp b/features/netsocket/EMACInterface.cpp index 511e4f8469..2e15cb5b0f 100644 --- a/features/netsocket/EMACInterface.cpp +++ b/features/netsocket/EMACInterface.cpp @@ -15,9 +15,12 @@ */ #include "EMACInterface.h" +#include "mbed_trace.h" using namespace mbed; +#define TRACE_GROUP "EMACi" + /* Interface implementation */ EMACInterface::EMACInterface(EMAC &emac, OnboardNetworkStack &stack) : _emac(emac), @@ -69,10 +72,17 @@ nsapi_error_t EMACInterface::set_dhcp(bool dhcp) nsapi_error_t EMACInterface::connect() { if (!_interface) { - nsapi_error_t err; + nsapi_error_t err = NSAPI_ERROR_UNSUPPORTED; + if (_hw_mac_addr_set) { err = _stack.add_ethernet_interface(_emac, true, &_interface, _hw_mac_addr); - } else { + if (err == NSAPI_ERROR_UNSUPPORTED) { + tr_error("Failed to set user MAC address"); + } + } + + if (err == NSAPI_ERROR_UNSUPPORTED) + { err = _stack.add_ethernet_interface(_emac, true, &_interface); } diff --git a/features/netsocket/NetworkInterface.h b/features/netsocket/NetworkInterface.h index 48f1b9864a..d747ad3299 100644 --- a/features/netsocket/NetworkInterface.h +++ b/features/netsocket/NetworkInterface.h @@ -106,8 +106,9 @@ public: * be unique globally. The address must be set before calling the interface * connect() method. * - * Not all interfaces are supporting MAC address set. A call to connect() - * method will fail if MAC address is provided but not possible to use. + * Not all interfaces are supporting MAC address set and an error is not returned + * for this method call. Verify the changed MAC address by analysing packet + * captures from the used network interface. * * 6-byte EUI-48 MAC addresses are used for Ethernet while Mesh interface is * using 8-byte EUI-64 address.