Skip to content

Commit

Permalink
Merge branch 'backport/add_config_to_set_custom_mac_as_base_mac_v5_2'…
Browse files Browse the repository at this point in the history
… into 'release/v5.2'

feat(mac): Add a configuration to set custom MAC as base MAC(Backport V5.2)

See merge request espressif/esp-idf!27738
  • Loading branch information
jack0c committed Dec 7, 2023
2 parents 0a1e584 + 0d4d3c1 commit 97594d2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
7 changes: 7 additions & 0 deletions components/esp_hw_support/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ menu "Hardware Settings"
If you have an invalid MAC CRC (ESP_ERR_INVALID_CRC) problem
and you still want to use this chip, you can enable this option to bypass such an error.
This applies to both MAC_FACTORY and CUSTOM_MAC efuses.

config ESP_MAC_USE_CUSTOM_MAC_AS_BASE_MAC
bool "Enable using custom mac as base mac"
default n
help
When this configuration is enabled, the user can invoke `esp_read_mac` to obtain the desired type of
MAC using a custom MAC as the base MAC.
endmenu

menu "Sleep Config"
Expand Down
26 changes: 17 additions & 9 deletions components/esp_hw_support/mac_addr.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -63,7 +63,7 @@ static mac_t s_mac_table[] = {
#define ITEMS_IN_MAC_TABLE (sizeof(s_mac_table) / sizeof(mac_t))

static esp_err_t generate_mac(uint8_t *mac, uint8_t *base_mac_addr, esp_mac_type_t type);
static esp_err_t get_efuse_mac_get_default(uint8_t *mac);
static esp_err_t get_efuse_factory_mac(uint8_t *mac);
static esp_err_t get_efuse_mac_custom(uint8_t *mac);
#if CONFIG_SOC_IEEE802154_SUPPORTED
static esp_err_t get_efuse_mac_ext(uint8_t *mac);
Expand All @@ -89,11 +89,19 @@ static esp_err_t get_mac_addr_from_mac_table(uint8_t *mac, int idx, bool silent)
esp_mac_type_t type = s_mac_table[idx].type;
if (ESP_MAC_BASE <= type && type <= ESP_MAC_EFUSE_EXT) {
esp_err_t err = ESP_OK;
if (type == ESP_MAC_BASE || type == ESP_MAC_EFUSE_FACTORY) {
err = get_efuse_mac_get_default(s_mac_table[idx].mac);
} else if (type == ESP_MAC_EFUSE_CUSTOM) {
err = get_efuse_mac_custom(s_mac_table[idx].mac);
}
if (type == ESP_MAC_EFUSE_FACTORY
#ifndef CONFIG_ESP_MAC_USE_CUSTOM_MAC_AS_BASE_MAC
|| type == ESP_MAC_BASE
#endif
) {
err = get_efuse_factory_mac(s_mac_table[idx].mac);
} else if (type == ESP_MAC_EFUSE_CUSTOM
#ifdef CONFIG_ESP_MAC_USE_CUSTOM_MAC_AS_BASE_MAC
|| type == ESP_MAC_BASE
#endif
) {
err = get_efuse_mac_custom(s_mac_table[idx].mac);
}
#if CONFIG_SOC_IEEE802154_SUPPORTED
else if (type == ESP_MAC_EFUSE_EXT) {
err = get_efuse_mac_ext(s_mac_table[idx].mac);
Expand Down Expand Up @@ -246,7 +254,7 @@ static esp_err_t get_efuse_mac_custom(uint8_t *mac)

esp_err_t esp_efuse_mac_get_default(uint8_t *mac)
{
esp_err_t err = get_efuse_mac_get_default(mac);
esp_err_t err = get_efuse_factory_mac(mac);
if (err != ESP_OK) {
return err;
}
Expand All @@ -257,7 +265,7 @@ esp_err_t esp_efuse_mac_get_default(uint8_t *mac)
#endif
}

static esp_err_t get_efuse_mac_get_default(uint8_t *mac)
static esp_err_t get_efuse_factory_mac(uint8_t *mac)
{
size_t size_bits = esp_efuse_get_field_size(ESP_EFUSE_MAC_FACTORY);
assert((size_bits % 8) == 0);
Expand Down
1 change: 1 addition & 0 deletions tools/test_apps/system/build_test/sdkconfig.ci.custom_mac
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CONFIG_ESP_MAC_USE_CUSTOM_MAC_AS_BASE_MAC=y

0 comments on commit 97594d2

Please sign in to comment.