]> granicus.if.org Git - esp-idf/commitdiff
mac address: add user set mac address
authorXiaXiaotian <xiaxiaotian@espressif.com>
Wed, 1 Mar 2017 12:42:46 +0000 (20:42 +0800)
committerXiaXiaotian <xiaxiaotian@espressif.com>
Wed, 1 Mar 2017 12:42:46 +0000 (20:42 +0800)
add menuconfig for user to set mac address of wifi, bt and ethernet.

components/bt/Kconfig
components/esp32/Kconfig
components/esp32/include/esp_system.h
components/esp32/lib
components/esp32/system_api.c
components/ethernet/Kconfig
components/ethernet/emac_main.c

index 63dce8d1f93166ddd491beb3c2d1e5f41596bea6..e4a72654fa67cd881dc56315f4fdaf33468416e5 100644 (file)
@@ -3,6 +3,15 @@ menuconfig BT_ENABLED
     help
         Select this option to enable Bluetooth stack and show the submenu with Bluetooth configuration choices.
 
+config ESP_MAC_OFFSET_BT_
+    int "MAC address offset value of WiFi station"
+    depends on BT_ENABLED
+    range 0 255
+    default 2
+    help
+       The offset value of bluetooth MAC address from the MAC address which is read from efuse.
+       This offset value must be different from that of WiFi softap, WiFi station and ethernet.
+
 config BTC_TASK_STACK_SIZE
        int "Bluetooth event (callback to application) task stack size"
     depends on BT_ENABLED
index 8aa0ed3b5fbbe07cd172add24aa6c48b9e0cd3c1..361ddccd52bd17de96599e1e2dab5099280f4507 100644 (file)
@@ -481,6 +481,24 @@ menuconfig WIFI_ENABLED
     help
        Select this option to enable WiFi stack and show the submenu with WiFi configuration choices.
 
+config ESP_MAC_OFFSET_WIFI_STA
+    int "MAC address offset value of WiFi station"
+    depends on WIFI_ENABLED
+    range 0 255
+    default 0
+    help
+       The offset value of WiFi station MAC address from the MAC address which is read from efuse.
+       This offset value must be different from that of WiFi softap, bluetooth and ethernet.
+
+config ESP_MAC_OFFSET_WIFI_SOFTAP
+    int "MAC address offset value of WiFi softap"
+    depends on WIFI_ENABLED
+    range 0 255
+    default 1
+    help
+       The offset value of WiFi softap MAC address from the MAC address which is read from efuse.
+       This offset value must be different from that of WiFi station, bluetooth and ethernet.
+
 config SW_COEXIST_ENABLE
     bool "Software controls WiFi/Bluetooth coexistence"
     depends on WIFI_ENABLED && BT_ENABLED
index 30701761ad293a02e142cdfa2c5ca564343dddad..b127d56feafacb3055f5728e826a916bd576bc63 100644 (file)
 extern "C" {
 #endif
 
+enum {
+    ESP_MAC_WIFI_STA,
+    ESP_MAC_WIFI_SOFTAP,
+    ESP_MAC_BT,
+    ESP_MAC_ETH,
+};
+
 /**
   * @attention  application don't need to call this function anymore. It do nothing and will
   *             be removed in future version.
@@ -115,6 +122,19 @@ esp_err_t esp_efuse_read_mac(uint8_t* mac);
   */
 esp_err_t system_efuse_read_mac(uint8_t mac[6]) __attribute__ ((deprecated));
 
+/**
+  * @brief  Read hardware MAC address and set MAC address of the interface.
+  *
+  * This function first reads hardware MAC address from efuse. Then set the MAC address of the interface
+  * including wifi station, wifi softap, bluetooth and ethernet according to the offset value in menuconfig.
+  *
+  * @param  mac  MAC address of the interface, length: 6 bytes.
+  * @param  interface  interface, 0:wifi station, 1:wifi softap, 2:bluetooth, 3:ethernet.
+  *
+  * @return ESP_OK on success
+  */
+esp_err_t esp_read_mac(uint8_t* mac, int interface);
+
 /**
  * Get SDK version
  *
index 7b06303c0fa416aea7f86b7596e84db367189066..e22ec1a5140dca2bb44f9bfb3147911fa4ebb8fe 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 7b06303c0fa416aea7f86b7596e84db367189066
+Subproject commit e22ec1a5140dca2bb44f9bfb3147911fa4ebb8fe
index d984af78a7084b6ea06e3e07def8f00e857391d0..36b8b6b58851b2e07a227f17d672658203f008be 100644 (file)
@@ -12,6 +12,8 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+#include <string.h>
+
 #include "esp_system.h"
 #include "esp_attr.h"
 #include "esp_wifi.h"
@@ -72,6 +74,47 @@ esp_err_t esp_efuse_read_mac(uint8_t* mac)
 
 esp_err_t system_efuse_read_mac(uint8_t mac[6]) __attribute__((alias("esp_efuse_read_mac")));
 
+esp_err_t esp_read_mac(uint8_t* mac, int interface)
+{
+    uint8_t efuse_mac[6];
+
+    if (mac == NULL) {
+        ESP_LOGE(TAG, "mac address param is NULL");
+        abort();
+    }
+
+    esp_efuse_read_mac(efuse_mac);
+
+    switch (interface) {
+#if CONFIG_WIFI_ENABLED
+    case ESP_MAC_WIFI_STA:
+        memcpy(mac, efuse_mac, 6);
+        mac[5] += CONFIG_ESP_MAC_OFFSET_WIFI_STA;
+        break;
+    case ESP_MAC_WIFI_SOFTAP:
+        memcpy(mac, efuse_mac, 6);
+        mac[5] += CONFIG_ESP_MAC_OFFSET_WIFI_SOFTAP;
+        break;
+#endif
+#if CONFIG_BT_ENABLED
+    case ESP_MAC_WIFI_BT:
+        memcpy(mac, efuse_mac, 6);
+        mac[5] += CONFIG_ESP_MAC_OFFSET_BT;
+        break;
+#endif
+#if CONFIG_ETHERNET
+    case ESP_MAC_WIFI_ETH:
+        memcpy(mac, efuse_mac, 6);
+        mac[5] += CONFIG_ESP_MAC_OFFSET_ETH;
+        break;
+#endif
+    default:
+        ESP_LOGW(TAG, "wrong mac type"); 
+        break;
+    }
+  
+    return ESP_OK;
+}
 
 void esp_restart_noos() __attribute__ ((noreturn));
 
index 46e86cc60ec7b6dbce78f3f210b7a5351db53d3e..230e53cdc743742fbe3594951567ef1b778427d3 100644 (file)
@@ -4,6 +4,15 @@ menuconfig ETHERNET
     help
         Select this option to enable ethernet driver and show the submenu with ethernet features.
 
+config ESP_MAC_OFFSET_ETH
+    int "MAC address offset value of ethernet"
+    depends on ETHERNET
+    range 0 255
+    default 3
+    help
+       The offset value of ethernet MAC address from the MAC address which is read from efuse.
+       This offset value must be different from that of WiFi softap, bluetooth and WiFi station.
+
 config DMA_RX_BUF_NUM
     int "Number of DMA RX buffers"
     range 3 20
index 5479ec399e0c8efa6ac7c1d45e8b435de731e63b..8c93a1830e476fff5acae0c17ce86618a8e4b435 100644 (file)
@@ -75,8 +75,7 @@ esp_err_t emac_post(emac_sig_t sig, emac_par_t par);
 
 static void emac_macaddr_init(void)
 {
-    esp_efuse_read_mac(&(emac_config.macaddr[0]));
-    emac_config.macaddr[5] = emac_config.macaddr[5] + 3;
+    esp_read_mac(&(emac_config.macaddr[0]), ESP_MAC_ETH);
 }
 
 void esp_eth_get_mac(uint8_t mac[6])