diff --git a/src/include/platform/ConfigurationManager.h b/src/include/platform/ConfigurationManager.h index e846e420f5dc79..92c28570cf25e8 100644 --- a/src/include/platform/ConfigurationManager.h +++ b/src/include/platform/ConfigurationManager.h @@ -89,6 +89,7 @@ class ConfigurationManager }; virtual CHIP_ERROR GetPrimaryMACAddress(MutableByteSpan buf) = 0; + virtual CHIP_ERROR GetPrimaryEthernetMACAddress(MutableByteSpan buf) = 0; virtual CHIP_ERROR GetPrimaryWiFiMACAddress(uint8_t * buf) = 0; virtual CHIP_ERROR GetPrimary802154MACAddress(uint8_t * buf) = 0; virtual CHIP_ERROR GetSoftwareVersionString(char * buf, size_t bufSize) = 0; diff --git a/src/include/platform/internal/GenericConfigurationManagerImpl.h b/src/include/platform/internal/GenericConfigurationManagerImpl.h index 21310be54641d9..27b06beda47d90 100644 --- a/src/include/platform/internal/GenericConfigurationManagerImpl.h +++ b/src/include/platform/internal/GenericConfigurationManagerImpl.h @@ -70,6 +70,7 @@ class GenericConfigurationManagerImpl : public ConfigurationManager CHIP_ERROR SetFirmwareBuildChipEpochTime(System::Clock::Seconds32 buildTime) override; CHIP_ERROR StoreSerialNumber(const char * serialNum, size_t serialNumLen) override; CHIP_ERROR GetPrimaryMACAddress(MutableByteSpan buf) override; + CHIP_ERROR GetPrimaryEthernetMACAddress(MutableByteSpan buf) override; CHIP_ERROR GetPrimaryWiFiMACAddress(uint8_t * buf) override; CHIP_ERROR GetPrimary802154MACAddress(uint8_t * buf) override; CHIP_ERROR StoreManufacturingDate(const char * mfgDate, size_t mfgDateLen) override; diff --git a/src/include/platform/internal/GenericConfigurationManagerImpl.ipp b/src/include/platform/internal/GenericConfigurationManagerImpl.ipp index 4f77ae9f975162..4bd35861dca731 100644 --- a/src/include/platform/internal/GenericConfigurationManagerImpl.ipp +++ b/src/include/platform/internal/GenericConfigurationManagerImpl.ipp @@ -366,6 +366,12 @@ CHIP_ERROR GenericConfigurationManagerImpl::GetPrimaryWiFiMACAddres return CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND; } +template +CHIP_ERROR GenericConfigurationManagerImpl::GetPrimaryEthernetMACAddress(MutableByteSpan buf) +{ + return CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND; +} + template CHIP_ERROR GenericConfigurationManagerImpl::GetPrimaryMACAddress(MutableByteSpan buf) { @@ -374,6 +380,14 @@ CHIP_ERROR GenericConfigurationManagerImpl::GetPrimaryMACAddress(Mu memset(buf.data(), 0, buf.size()); +#if CHIP_DEVICE_CONFIG_ENABLE_ETHERNET + if (chip::DeviceLayer::ConfigurationMgr().GetPrimaryEthernetMACAddress(buf) == CHIP_NO_ERROR) + { + ChipLogDetail(DeviceLayer, "Using Ethernet extended MAC for hostname."); + return CHIP_NO_ERROR; + } +#endif + #if CHIP_DEVICE_CONFIG_ENABLE_THREAD if (chip::DeviceLayer::ThreadStackMgr().GetPrimary802154MACAddress(buf.data()) == CHIP_NO_ERROR) { diff --git a/src/platform/ESP32/ConfigurationManagerImpl.cpp b/src/platform/ESP32/ConfigurationManagerImpl.cpp index 188fb75a43e86b..822fb7902688fc 100644 --- a/src/platform/ESP32/ConfigurationManagerImpl.cpp +++ b/src/platform/ESP32/ConfigurationManagerImpl.cpp @@ -31,6 +31,9 @@ #include #include +#if CHIP_DEVICE_CONFIG_ENABLE_ETHERNET +#include "esp_mac.h" +#endif #include "esp_ota_ops.h" #include "esp_phy_init.h" #include "esp_wifi.h" @@ -262,6 +265,20 @@ CHIP_ERROR ConfigurationManagerImpl::StoreCountryCode(const char * code, size_t return GenericConfigurationManagerImpl::StoreCountryCode(code, codeLen); } +CHIP_ERROR ConfigurationManagerImpl::GetPrimaryEthernetMACAddress(MutableByteSpan buf) +{ +#if CHIP_DEVICE_CONFIG_ENABLE_ETHERNET + if (buf.size() < ConfigurationManager::kPrimaryMACAddressLength) + return CHIP_ERROR_BUFFER_TOO_SMALL; + + esp_err_t err = esp_read_mac(buf.data(), ESP_MAC_ETH); + buf.reduce_size(ConfigurationManager::kPrimaryMACAddressLength); + return MapConfigError(err); +#else + return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; +#endif +} + CHIP_ERROR ConfigurationManagerImpl::GetPrimaryWiFiMACAddress(uint8_t * buf) { #if CHIP_DEVICE_CONFIG_ENABLE_WIFI diff --git a/src/platform/ESP32/ConfigurationManagerImpl.h b/src/platform/ESP32/ConfigurationManagerImpl.h index fce74d9307b823..e0ebb0c430a720 100644 --- a/src/platform/ESP32/ConfigurationManagerImpl.h +++ b/src/platform/ESP32/ConfigurationManagerImpl.h @@ -66,6 +66,7 @@ class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImp // ===== Members that implement the ConfigurationManager public interface. CHIP_ERROR Init(void) override; + CHIP_ERROR GetPrimaryEthernetMACAddress(MutableByteSpan buf) override; CHIP_ERROR GetPrimaryWiFiMACAddress(uint8_t * buf) override; bool CanFactoryReset(void) override; void InitiateFactoryReset(void) override; diff --git a/src/platform/fake/ConfigurationManagerImpl.h b/src/platform/fake/ConfigurationManagerImpl.h index 9347d22052c247..d3b7acd4d4c58b 100644 --- a/src/platform/fake/ConfigurationManagerImpl.h +++ b/src/platform/fake/ConfigurationManagerImpl.h @@ -51,6 +51,7 @@ class ConfigurationManagerImpl : public ConfigurationManager CHIP_ERROR StoreSoftwareVersion(uint32_t softwareVer) override { return CHIP_ERROR_NOT_IMPLEMENTED; } CHIP_ERROR StoreSerialNumber(const char * serialNum, size_t serialNumLen) override { return CHIP_ERROR_NOT_IMPLEMENTED; } CHIP_ERROR GetPrimaryMACAddress(MutableByteSpan buf) override { return CHIP_ERROR_NOT_IMPLEMENTED; } + CHIP_ERROR GetPrimaryEthernetMACAddress(MutableByteSpan buf) override { return CHIP_ERROR_NOT_IMPLEMENTED; } CHIP_ERROR GetPrimaryWiFiMACAddress(uint8_t * buf) override { return CHIP_ERROR_NOT_IMPLEMENTED; } CHIP_ERROR GetPrimary802154MACAddress(uint8_t * buf) override { return CHIP_ERROR_NOT_IMPLEMENTED; } CHIP_ERROR StoreManufacturingDate(const char * mfgDate, size_t mfgDateLen) override { return CHIP_ERROR_NOT_IMPLEMENTED; }