You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by "pkarashchenko (via GitHub)" <gi...@apache.org> on 2023/04/11 07:04:49 UTC

[GitHub] [nuttx] pkarashchenko commented on a diff in pull request #8993: xtensa/esp32: Add support for universal mac addresses

pkarashchenko commented on code in PR #8993:
URL: https://github.com/apache/nuttx/pull/8993#discussion_r1162381782


##########
arch/xtensa/src/esp32/esp32_wireless.c:
##########
@@ -36,6 +36,16 @@
 #include "esp_phy_init.h"
 #include "phy_init_data.h"
 
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#ifdef CONFIG_ESP32_UNIVERSAL_MAC_ADDRESSES_FOUR
+#define MAC_ADDR_UNIVERSE_BT_OFFSET 2
+#else
+#define MAC_ADDR_UNIVERSE_BT_OFFSET 1

Review Comment:
   ```suggestion
   #  define MAC_ADDR_UNIVERSE_BT_OFFSET 1
   ```



##########
arch/xtensa/src/esp32/Kconfig:
##########
@@ -2167,6 +2167,44 @@ config ESP32_BLE_MAX_CONN
 
 endmenu # BLE Configuration
 
+choice ESP32_UNIVERSAL_MAC_ADDRESSES
+	bool "Number of universally administered (by IEEE) MAC addresses"
+	default ESP32_UNIVERSAL_MAC_ADDRESSES_FOUR
+	depends on ESP32_WIFI || ESP32_BLE
+	---help---
+		Configure the number of universally administered (by IEEE) MAC addresses.
+		During initialization, MAC addresses for each network interface are generated or derived from a
+		single base MAC address.
+		If the number of universal MAC addresses is four, all four interfaces (WiFi station, WiFi softap,
+		Bluetooth and Ethernet) receive a universally administered MAC address. These are generated
+		sequentially by adding 0, 1, 2 and 3 (respectively) to the final octet of the base MAC address.
+		If the number of universal MAC addresses is two, only two interfaces (WiFi station and Bluetooth)
+		receive a universally administered MAC address. These are generated sequentially by adding 0
+		and 1 (respectively) to the base MAC address. The remaining two interfaces (WiFi softap and Ethernet)
+		receive local MAC addresses. These are derived from the universal WiFi station and Bluetooth MAC
+		addresses, respectively.
+		When using the default (Espressif-assigned) base MAC address, either setting can be used. When using
+		a custom universal MAC address range, the correct setting will depend on the allocation of MAC
+		addresses in this range (either 2 or 4 per device.)
+
+	config ESP32_UNIVERSAL_MAC_ADDRESSES_TWO
+		bool "Two"
+		select ESP_MAC_ADDR_UNIVERSE_WIFI_STA
+		select ESP_MAC_ADDR_UNIVERSE_BT
+
+	config ESP32_UNIVERSAL_MAC_ADDRESSES_FOUR
+		bool "Four"
+		select ESP_MAC_ADDR_UNIVERSE_WIFI_STA
+		select ESP_MAC_ADDR_UNIVERSE_WIFI_AP
+		select ESP_MAC_ADDR_UNIVERSE_BT
+		select ESP_MAC_ADDR_UNIVERSE_ETH

Review Comment:
   ```suggestion
   config ESP32_UNIVERSAL_MAC_ADDRESSES_TWO
   	bool "Two"
   	select ESP_MAC_ADDR_UNIVERSE_WIFI_STA
   	select ESP_MAC_ADDR_UNIVERSE_BT
   
   config ESP32_UNIVERSAL_MAC_ADDRESSES_FOUR
   	bool "Four"
   	select ESP_MAC_ADDR_UNIVERSE_WIFI_STA
   	select ESP_MAC_ADDR_UNIVERSE_WIFI_AP
   	select ESP_MAC_ADDR_UNIVERSE_BT
   	select ESP_MAC_ADDR_UNIVERSE_ETH
   ```



##########
arch/xtensa/src/esp32/esp32_wireless.c:
##########
@@ -36,6 +36,16 @@
 #include "esp_phy_init.h"
 #include "phy_init_data.h"
 
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#ifdef CONFIG_ESP32_UNIVERSAL_MAC_ADDRESSES_FOUR
+#define MAC_ADDR_UNIVERSE_BT_OFFSET 2

Review Comment:
   ```suggestion
   #  define MAC_ADDR_UNIVERSE_BT_OFFSET 2
   ```



##########
arch/xtensa/src/esp32/esp32_emac.c:
##########
@@ -470,6 +470,29 @@ static int emac_read_mac(uint8_t *mac)
       return -EINVAL;
     }
 
+#ifdef CONFIG_ESP_MAC_ADDR_UNIVERSE_ETH
+  mac[5] += 3;
+#else
+  mac[5] += 1;
+  uint8_t tmp = mac[0];
+  for (i = 0; i < 64; i++)
+    {
+      mac[0] = tmp | 0x02;
+      mac[0] ^= i << 2;
+
+      if (mac[0] != tmp)
+        {
+          break;
+        }
+    }
+
+  if (i >= 64)
+    {
+      wlerr("Failed to generate ethernet MAC\n");
+      return -1;
+    }
+
+#endif

Review Comment:
   ```suggestion
   #endif
   
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org