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

Pass the arg of GetPrimaryOrFallbackMACAddress by reference. #37609

Merged
merged 2 commits into from
Feb 18, 2025
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
2 changes: 1 addition & 1 deletion src/app/server/Dnssd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ void DnssdServer::AddICDKeyToAdvertisement(AdvertisingParams & advParams)
}
#endif

void DnssdServer::GetPrimaryOrFallbackMACAddress(chip::MutableByteSpan mac)
void DnssdServer::GetPrimaryOrFallbackMACAddress(MutableByteSpan & mac)
{
if (ConfigurationMgr().GetPrimaryMACAddress(mac) != CHIP_NO_ERROR)
{
Expand Down
2 changes: 1 addition & 1 deletion src/app/server/Dnssd.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class DLL_EXPORT DnssdServer : public ICDStateObserver
// Our randomly-generated fallback "MAC address", in case we don't have a real one.
uint8_t mFallbackMAC[chip::DeviceLayer::ConfigurationManager::kPrimaryMACAddressLength] = { 0 };

void GetPrimaryOrFallbackMACAddress(chip::MutableByteSpan mac);
void GetPrimaryOrFallbackMACAddress(MutableByteSpan & mac);

//
// Check if we have any valid operational credentials present in the fabric table and return true
Expand Down
2 changes: 1 addition & 1 deletion src/include/platform/ConfigurationManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class ConfigurationManager
// Copies the primary MAC into a mutable span, which must be of size kPrimaryMACAddressLength.
// Upon success, the span will be reduced to the size of the MAC address being returned, which
// can be less than kPrimaryMACAddressLength on a device that supports Thread.
virtual CHIP_ERROR GetPrimaryMACAddress(MutableByteSpan buf) = 0;
virtual CHIP_ERROR GetPrimaryMACAddress(MutableByteSpan & buf) = 0;

// Copies the primary WiFi MAC into a buffer of size kEthernetMACAddressLength
virtual CHIP_ERROR GetPrimaryWiFiMACAddress(uint8_t * buf) = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class GenericConfigurationManagerImpl : public ConfigurationManager
CHIP_ERROR GetFirmwareBuildChipEpochTime(System::Clock::Seconds32 & buildTime) override;
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 GetPrimaryMACAddress(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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::GetPrimaryWiFiMACAddres
}

template <class ConfigClass>
CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::GetPrimaryMACAddress(MutableByteSpan buf)
CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::GetPrimaryMACAddress(MutableByteSpan & buf)
{
if (buf.size() != ConfigurationManager::kPrimaryMACAddressLength)
return CHIP_ERROR_INVALID_ARGUMENT;
Expand Down
4 changes: 2 additions & 2 deletions src/platform/ESP32/ConfigurationManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ CHIP_ERROR ConfigurationManagerImpl::StoreCountryCode(const char * code, size_t

#if CHIP_DEVICE_CONFIG_ENABLE_ETHERNET

CHIP_ERROR ConfigurationManagerImpl::GetPrimaryMACAddress(MutableByteSpan buf)
CHIP_ERROR ConfigurationManagerImpl::GetPrimaryMACAddress(MutableByteSpan & buf)
{
if (GetPrimaryEthernetMACAddress(buf) == CHIP_NO_ERROR)
{
Expand All @@ -322,7 +322,7 @@ CHIP_ERROR ConfigurationManagerImpl::GetPrimaryMACAddress(MutableByteSpan buf)
return CHIP_ERROR_NOT_FOUND;
}

CHIP_ERROR ConfigurationManagerImpl::GetPrimaryEthernetMACAddress(MutableByteSpan buf)
CHIP_ERROR ConfigurationManagerImpl::GetPrimaryEthernetMACAddress(MutableByteSpan & buf)
{
if (buf.size() < ConfigurationManager::kPrimaryMACAddressLength)
return CHIP_ERROR_BUFFER_TOO_SMALL;
Expand Down
4 changes: 2 additions & 2 deletions src/platform/ESP32/ConfigurationManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImp

CHIP_ERROR Init(void) override;
#if CHIP_DEVICE_CONFIG_ENABLE_ETHERNET
CHIP_ERROR GetPrimaryMACAddress(MutableByteSpan buf) override;
CHIP_ERROR GetPrimaryEthernetMACAddress(MutableByteSpan buf);
CHIP_ERROR GetPrimaryMACAddress(MutableByteSpan & buf) override;
CHIP_ERROR GetPrimaryEthernetMACAddress(MutableByteSpan & buf);
#endif
CHIP_ERROR GetPrimaryWiFiMACAddress(uint8_t * buf) override;
bool CanFactoryReset(void) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ CHIP_ERROR ConfigurationManagerImpl::GetPrimaryWiFiMACAddress(uint8_t * buf)
#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI

#if CHIP_DEVICE_CONFIG_ENABLE_ETHERNET
CHIP_ERROR ConfigurationManagerImpl::GetPrimaryMACAddress(MutableByteSpan buf)
CHIP_ERROR ConfigurationManagerImpl::GetPrimaryMACAddress(MutableByteSpan & buf)
{
if (buf.size() != ConfigurationManager::kPrimaryMACAddressLength)
return CHIP_ERROR_INVALID_ARGUMENT;
Expand Down
2 changes: 1 addition & 1 deletion src/platform/bouffalolab/common/ConfigurationManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImp
#endif

#if CHIP_DEVICE_CONFIG_ENABLE_ETHERNET
CHIP_ERROR GetPrimaryMACAddress(MutableByteSpan buf) override;
CHIP_ERROR GetPrimaryMACAddress(MutableByteSpan & buf) override;
#endif

static void DoFactoryReset(intptr_t arg);
Expand Down
2 changes: 1 addition & 1 deletion src/platform/fake/ConfigurationManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class ConfigurationManagerImpl : public ConfigurationManager
CHIP_ERROR GetSoftwareVersion(uint32_t & softwareVer) override { return CHIP_ERROR_NOT_IMPLEMENTED; }
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 GetPrimaryMACAddress(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; }
Expand Down
9 changes: 8 additions & 1 deletion src/platform/tests/TestConfigurationMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,10 +389,17 @@ TEST_F(TestConfigurationMgr, GetPrimaryMACAddress)
MutableByteSpan mac6Bytes(macBuffer6Bytes);

err = ConfigurationMgr().GetPrimaryMACAddress(mac8Bytes);
if (mac8Bytes.size() != ConfigurationManager::kPrimaryMACAddressLength)
if (sizeof(macBuffer8Bytes) != ConfigurationManager::kPrimaryMACAddressLength)
{
// Should have failed input validation
EXPECT_EQ(err, CHIP_ERROR_INVALID_ARGUMENT);
}
else if (mac8Bytes.size() != ConfigurationManager::kPrimaryMACAddressLength)
{
// This can happen if the primary address is Thread but then there is no
// Thread address to be had and we fell back to Wi-Fi.
EXPECT_EQ(mac8Bytes.size(), ConfigurationManager::kEthernetMACAddressLength);
}

err = ConfigurationMgr().GetPrimaryMACAddress(mac6Bytes);
if (mac6Bytes.size() != ConfigurationManager::kPrimaryMACAddressLength)
Expand Down
Loading