Skip to content

Commit

Permalink
fix get wrong MAC on SoftAP mode
Browse files Browse the repository at this point in the history
  • Loading branch information
wqx6 committed Jun 22, 2021
1 parent 82e6290 commit eba85a8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/platform/ESP32/ConfigurationManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +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_NOT_IMPLEMENTED;
}
}

bool ConfigurationManagerImpl::_CanFactoryReset()
{
// TODO: query the application to determine if factory reset is allowed.
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 eba85a8

Please sign in to comment.