Skip to content

Commit

Permalink
fix get wrong MAC on SoftAP mode (#7777)
Browse files Browse the repository at this point in the history
  • Loading branch information
wqx6 authored and pull[bot] committed Jul 21, 2021
1 parent 7dc1f8a commit a186a5b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/platform/ESP32/ConfigurationManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,28 @@ CHIP_ERROR ConfigurationManagerImpl::_Init()

CHIP_ERROR ConfigurationManagerImpl::_GetPrimaryWiFiMACAddress(uint8_t * buf)
{
return esp_wifi_get_mac(WIFI_IF_STA, buf);
wifi_mode_t mode;
esp_wifi_get_mode(&mode);
if ((mode == WIFI_MODE_AP) || (mode == WIFI_MODE_APSTA))
return MapConfigError(esp_wifi_get_mac(WIFI_IF_AP, buf));
else
return MapConfigError(esp_wifi_get_mac(WIFI_IF_STA, buf));
}

CHIP_ERROR ConfigurationManagerImpl::MapConfigError(esp_err_t error)
{
switch (error)
{
case ESP_OK:
return CHIP_NO_ERROR;
case ESP_ERR_WIFI_NOT_INIT:
return CHIP_ERROR_WELL_UNINITIALIZED;
case ESP_ERR_INVALID_ARG:
case ESP_ERR_WIFI_IF:
return CHIP_ERROR_INVALID_ARGUMENT;
default:
return CHIP_ERROR_INTERNAL;
}
}

bool ConfigurationManagerImpl::_CanFactoryReset()
Expand Down
1 change: 1 addition & 0 deletions src/platform/ESP32/ConfigurationManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class ConfigurationManagerImpl final : public ConfigurationManager,
CHIP_ERROR _GetPrimaryWiFiMACAddress(uint8_t * buf);
bool _CanFactoryReset(void);
void _InitiateFactoryReset(void);
CHIP_ERROR MapConfigError(esp_err_t error);
CHIP_ERROR _ReadPersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t & value);
CHIP_ERROR _WritePersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t value);

Expand Down

0 comments on commit a186a5b

Please sign in to comment.