Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ESP32] Add an API to get MAC address of ethernet device #29415

Merged
merged 1 commit into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/platform/ESP32/ConfigurationManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
#include <platform/ESP32/ESP32Config.h>
#include <platform/internal/GenericConfigurationManagerImpl.ipp>

#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"
Expand Down Expand Up @@ -262,6 +265,31 @@ CHIP_ERROR ConfigurationManagerImpl::StoreCountryCode(const char * code, size_t
return GenericConfigurationManagerImpl<ESP32Config>::StoreCountryCode(code, codeLen);
}

#if CHIP_DEVICE_CONFIG_ENABLE_ETHERNET

CHIP_ERROR ConfigurationManagerImpl::GetPrimaryMACAddress(MutableByteSpan buf)
{
if (GetPrimaryEthernetMACAddress(buf) == CHIP_NO_ERROR)
{
ChipLogDetail(DeviceLayer, "Using Ethernet MAC for hostname.");
return CHIP_NO_ERROR;
}
return CHIP_ERROR_NOT_FOUND;
}

CHIP_ERROR ConfigurationManagerImpl::GetPrimaryEthernetMACAddress(MutableByteSpan buf)
{
if (buf.size() < ConfigurationManager::kPrimaryMACAddressLength)
return CHIP_ERROR_BUFFER_TOO_SMALL;

memset(buf.data(), 0, buf.size());

esp_err_t err = esp_read_mac(buf.data(), ESP_MAC_ETH);
buf.reduce_size(ConfigurationManager::kPrimaryMACAddressLength);
return MapConfigError(err);
}
#endif

CHIP_ERROR ConfigurationManagerImpl::GetPrimaryWiFiMACAddress(uint8_t * buf)
{
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
Expand Down
4 changes: 4 additions & 0 deletions src/platform/ESP32/ConfigurationManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImp
// ===== Members that implement the ConfigurationManager public interface.

CHIP_ERROR Init(void) override;
#if CHIP_DEVICE_CONFIG_ENABLE_ETHERNET
CHIP_ERROR GetPrimaryMACAddress(MutableByteSpan buf) override;
CHIP_ERROR GetPrimaryEthernetMACAddress(MutableByteSpan buf);
#endif
CHIP_ERROR GetPrimaryWiFiMACAddress(uint8_t * buf) override;
bool CanFactoryReset(void) override;
void InitiateFactoryReset(void) override;
Expand Down
Loading