Added get_default_mac_addr() and set_base_mac_addr()
This commit is contained in:
@@ -1037,15 +1037,19 @@ esp_err_t goe_wifi_tcpip_init(const config &config)
|
|||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
|
|
||||||
#if CONFIG_IDF_TARGET_ESP32
|
#if CONFIG_IDF_TARGET_ESP32
|
||||||
|
if (const auto mac = get_default_mac_addr())
|
||||||
{
|
{
|
||||||
uint8_t mac[8];
|
if (const auto result = set_base_mac_addr(*mac))
|
||||||
if (const auto result = esp_efuse_mac_get_default(mac); result == ESP_OK)
|
|
||||||
{
|
{
|
||||||
if (const auto result = esp_base_mac_addr_set(mac); result != ESP_OK)
|
|
||||||
ESP_LOGE(TAG, "esp_base_mac_addr_set() failed with %s", esp_err_to_name(result));
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
ESP_LOGE(TAG, "esp_efuse_mac_get_default() failed with %s", esp_err_to_name(result));
|
{
|
||||||
|
ESP_LOGE(TAG, "set_base_mac_addr() failed: %.*s", result.error().size(), result.error().data());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ESP_LOGE(TAG, "get_default_mac_addr() failed: %.*s", mac.error().size(), mac.error().data());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -2024,11 +2028,23 @@ tl::expected<wifi_ap_record_t, std::string> get_sta_ap_info()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tl::expected<wifi_stack::mac_t, std::string> get_default_mac_addr()
|
||||||
|
{
|
||||||
|
wifi_stack::mac_t mac{};
|
||||||
|
if (const auto result = esp_efuse_mac_get_default(std::begin(mac)); result == ESP_OK)
|
||||||
|
return mac;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ESP_LOGE(TAG, "esp_efuse_mac_get_default() failed with %s", esp_err_to_name(result));
|
||||||
|
return tl::make_unexpected(std::string{"esp_efuse_mac_get_default() failed with "} + esp_err_to_name(result));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
tl::expected<wifi_stack::mac_t, std::string> get_base_mac_addr()
|
tl::expected<wifi_stack::mac_t, std::string> get_base_mac_addr()
|
||||||
{
|
{
|
||||||
wifi_stack::mac_t chipmac{};
|
wifi_stack::mac_t mac{};
|
||||||
if (const auto result = esp_base_mac_addr_get(std::begin(chipmac)); result == ESP_OK)
|
if (const auto result = esp_base_mac_addr_get(std::begin(mac)); result == ESP_OK)
|
||||||
return chipmac;
|
return mac;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ESP_LOGE(TAG, "esp_base_mac_addr_get() failed with %s", esp_err_to_name(result));
|
ESP_LOGE(TAG, "esp_base_mac_addr_get() failed with %s", esp_err_to_name(result));
|
||||||
@@ -2036,4 +2052,15 @@ tl::expected<wifi_stack::mac_t, std::string> get_base_mac_addr()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tl::expected<void, std::string> set_base_mac_addr(wifi_stack::mac_t mac_addr)
|
||||||
|
{
|
||||||
|
if (const auto result = esp_base_mac_addr_set(std::cbegin(mac_addr)); result == ESP_OK)
|
||||||
|
return {};
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ESP_LOGE(TAG, "esp_base_mac_addr_set() failed with %s", esp_err_to_name(result));
|
||||||
|
return tl::make_unexpected(std::string{"esp_base_mac_addr_set() failed with "} + esp_err_to_name(result));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace wifi_stack
|
} // namespace wifi_stack
|
||||||
|
@@ -56,6 +56,8 @@ void delete_scan_result();
|
|||||||
|
|
||||||
tl::expected<wifi_ap_record_t, std::string> get_sta_ap_info();
|
tl::expected<wifi_ap_record_t, std::string> get_sta_ap_info();
|
||||||
|
|
||||||
|
tl::expected<wifi_stack::mac_t, std::string> get_default_mac_addr();
|
||||||
tl::expected<wifi_stack::mac_t, std::string> get_base_mac_addr();
|
tl::expected<wifi_stack::mac_t, std::string> get_base_mac_addr();
|
||||||
|
tl::expected<void, std::string> set_base_mac_addr(wifi_stack::mac_t mac_addr);
|
||||||
|
|
||||||
} // namespace wifi_stack
|
} // namespace wifi_stack
|
||||||
|
Reference in New Issue
Block a user