main memory map. Enable this if you have this hardware and want to use it in the same
way as on-chip RAM.
-config CUSTOMER_MAC_ADDRESS
- bool "Customer MAC address"
- default n
- help
- Customers can define their own mac address in efuse.
- Set to 'y' if you decide to use the mac address that you defined in efuse.
+choice BASE_MAC_ADDRESS_STORAGE
+ prompt "Storage of the base MAC address"
+ default BASE_MAC_STORED_DEFAULT_EFUSE
+ help
+ Select storage of the base MAC address which is used for all network interfaces when networking is initialized.
+ If "Default place in EFUSE" is selected, esp32 will use the base MAC address which is written into default
+ place in EFUSE when the chip is manufactured.
+ If "Customer-defined place in EFUSE" is selected, ESP32 will use customer-defined base MAC address which
+ is written into EFUSE Block 3 words 0, 1.
+ If "Other customer-defined place" is selected, esp32 will use customer-defined base MAC address from other
+ place(flash, EEPROM, etc). User code must call esp_base_mac_addr_set_external to set the base MAC address
+ before network features are initialised.
+
+config BASE_MAC_STORED_DEFAULT_EFUSE
+ bool "Default place in EFUSE"
+config BASE_MAC_STORED_CUSTOMER_DEFINED_EFUSE
+ bool "Customer-defined place in EFUSE"
+config BASE_MAC_STORED_OTHER_CUSTOMER_DEFINED_PLACE
+ bool "Other customer-defined place"
+endchoice
choice NUMBER_OF_MAC_ADDRESS_GENERATED_FROM_EFUSE
bool "Number of MAC address generated from the hardware MAC address in efuse"
default FOUR_MAC_ADDRESS_FROM_EFUSE
help
- Config the number of MAC address which is generated from the hardware MAC address in efuse.
+ Config the number of MAC address which is generated from the base MAC address in efuse.
If the number is two, the MAC addresses of WiFi station and bluetooth are generated from
- the hardware MAC address in efuse. The MAC addresses of WiFi softap and ethernet are derived
+ the base MAC address in efuse. The MAC addresses of WiFi softap and ethernet are derived
from that of WiFi station and bluetooth respectively.
If the number is four, the MAC addresses of WiFi station, WiFi softap, bluetooth and ethernet
- are all generated from the hardware MAC address in efuse.
+ are all generated from the base MAC address in efuse.
config TWO_MAC_ADDRESS_FROM_EFUSE
bool "Two"
uint32_t esp_random(void);
/**
- * @brief Read hardware MAC address.
+ * @brief Set base MAC address from external storage e.g. flash and EEPROM.
+ *
+ * Base MAC address is used to generate the MAC addresses used by the networking interfaces.
+ * If using base MAC address stored in external storage, call this API to set base MAC
+ * address from external storage before initializing WiFi/BT/Ethernet.
+ *
+ * @param mac base MAC address, length: 6 bytes.
+ *
+ * @return ESP_OK on success
+ */
+esp_err_t esp_base_mac_addr_set_external(uint8_t *mac);
+
+/**
+ * @brief Return base MAC address set using esp_mac_addr_set_external.
+ *
+ * @param mac base MAC address, length: 6 bytes.
+ *
+ * Base MAC address is used to generate the MAC addresses used by the networking interfaces.
+ * If using base MAC address stored in external storage, call this API to set base MAC
+ * address from external storage before initializing WiFi/BT/Ethernet.
+ *
+ * @return ESP_OK on success
+ */
+esp_err_t esp_base_mac_addr_get_external(uint8_t *mac);
+
+/**
+ * @brief Read hardware MAC address from efuse.
*
* In WiFi MAC, only ESP32 station MAC is the hardware MAC, ESP32 softAP MAC is a software MAC
* calculated from ESP32 station MAC.
static const char* TAG = "system_api";
+static uint8_t ext_base_mac_addr[6] = {0};
+
void system_init()
{
}
+esp_err_t esp_base_mac_addr_set_external(uint8_t *mac)
+{
+ if (mac == NULL) {
+ ESP_LOGE(TAG, "External base MAC address is NULL");
+ abort();
+ }
+
+ memcpy(ext_base_mac_addr, mac, 6);
+
+ return ESP_OK;
+}
+
+esp_err_t esp_base_mac_addr_get_external(uint8_t *mac)
+{
+ uint8_t null_mac[6] = {0};
+
+ if (memcmp(ext_base_mac_addr, null_mac, 6) == 0) {
+ ESP_LOGE(TAG, "External MAC address is not set");
+ abort();
+ }
+
+ memcpy(mac, ext_base_mac_addr, 6);
+
+ return ESP_OK;
+}
+
esp_err_t esp_efuse_read_mac(uint8_t* mac)
{
uint32_t mac_low;
uint8_t efuse_crc;
uint8_t calc_crc;
-#ifndef CONFIG_CUSTOMER_MAC_ADDRESS
+#ifdef CONFIG_BASE_MAC_STORED_DEFAULT_EFUSE
mac_low = REG_READ(EFUSE_BLK0_RDATA1_REG);
mac_high = REG_READ(EFUSE_BLK0_RDATA2_REG);
mac[5] = mac_low >> 16;
efuse_crc = mac_high;
-#endif //CONFIG_CUSTOMER_DEFINED_MAC_ADDR
+#endif //CONFIG_BASE_MAC_STORED_DEFAULT_EFUSE
calc_crc = esp_crc8(mac, 6);
|| NUM_MAC_ADDRESS_FROM_EFUSE == TWO_MAC_ADDRESS_FROM_EFUSE, \
"incorrect NUM_MAC_ADDRESS_FROM_EFUSE value");
+#if defined(CONFIG_BASE_MAC_STORED_DEFAULT_EFUSE) || defined(CONFIG_BASE_MAC_STORED_CUSTOMER_DEFINED_EFUSE)
esp_efuse_read_mac(efuse_mac);
+#endif
+
+#if defined(CONFIG_BASE_MAC_STORED_OTHER_CUSTOMER_DEFINED_PLACE)
+ esp_base_mac_addr_get_external(efuse_mac);
+#endif
switch (type) {
case ESP_MAC_WIFI_STA: