Hi,
I am looking at a method to uniquely identify every ESP32 device .Is the MAC address obtained using the 'esp_wifi_get_mac()' truly unique for every device?
ESP32 MAC address - is it unique?
-
- Posts: 30
- Joined: Thu Dec 10, 2015 5:27 am
Re: ESP32 MAC address - is it unique?
use esp_efuse_mac_get_default instead. this func return base MAC address which is factory-programmed by Espressif in BLK0 of EFUSE.
The original MAC address in efuse is unique, Hower it can be changed by user.
The original MAC address in efuse is unique, Hower it can be changed by user.
Re: ESP32 MAC address - is it unique?
Thanks. Doesn't esp_wifi_get_mac() get the address from EFUSE?
Re: ESP32 MAC address - is it unique?
That is a 50-50 question as the specific MAC is computed in software except the Wifi station mode which is equal to the base MAC from the EFUSE. The EFUSE MAC is ideally unique. I did some digging and the ethernet MAC, wifi soft access point mode MAC and bluetooth MAC(Classic/BLE) are all derived from the base MAC address which is 6 bytes long.
I wrote this down so I will just copy paste from my notes:
You can refer more from the components/esp32/system_api.c file within esp idf. Look for the function esp_read_mac. The number of universal mac addresses can be set within menuconfig.
Also as an addition: The 4 MAC addresses above are computed in software at runtime. The first 24 bits of the address of any of the MACs above identify the OUI (organisationally unique identifier) which when I check on the OUI lookup tool from wireshark https://www.wireshark.org/tools/oui-lookup.html :
24:0A:C4
Which gives:
24:0A:C4 Espressif Espressif Inc.
So my geuss is every Espressif Base MAC's should be mutually spaced by 4 bits from the next for true uniqueness. only an espressif representative I believe can answer this but but since they can only assign (2^24 )/(1 billion device) MACs, my thinking is that each devices base MAC is spaced from the next by 1. They separated the MACs by usage. A devices BT MAC will always be spaced 4 bits from the next and the bluetooth usage niche is different from wifi/ethernet. Where it gets tricky is the ethernet.
In theory one device's Wifi MAC may collide with another device's ethernet MAC, but since not much of espressif's market may use the ethernet peripheral, there may be hardly any collisions in practice.
I wrote this down so I will just copy paste from my notes:
Code: Select all
The following MAC addresses are derived from the BASE MAC in the EFUSE BLK0.
#ESP_MAC_WIFI_STA
#ESP_MAC_WIFI_SOFTAP
#ESP_MAC_BT
#ESP_MAC_ETH
For 2 universal MAC addresses, the BT and Wifi are both enabled. Ethernet is disabled. Here:
#ESP_MAC_WIFI_STA=ESP_MAC_WIFI_SOFTAP=BASE MAC.
#ESP_MAC_BT=BASE MAC+1
For 4 Universal MAC addresses, the BT, Wifi and ethernet are all enabled. Here:
#ESP_MAC_WIFI_STA=BASE MAC.
#ESP_MAC_WIFI_SOFTAP=BASE MAC+1
#ESP_MAC_BT=BASE MAC+2
#ESP_MAC_ETH=BASE MAC+3
Also as an addition: The 4 MAC addresses above are computed in software at runtime. The first 24 bits of the address of any of the MACs above identify the OUI (organisationally unique identifier) which when I check on the OUI lookup tool from wireshark https://www.wireshark.org/tools/oui-lookup.html :
24:0A:C4
Which gives:
24:0A:C4 Espressif Espressif Inc.
So my geuss is every Espressif Base MAC's should be mutually spaced by 4 bits from the next for true uniqueness. only an espressif representative I believe can answer this but but since they can only assign (2^24 )/(1 billion device) MACs, my thinking is that each devices base MAC is spaced from the next by 1. They separated the MACs by usage. A devices BT MAC will always be spaced 4 bits from the next and the bluetooth usage niche is different from wifi/ethernet. Where it gets tricky is the ethernet.
In theory one device's Wifi MAC may collide with another device's ethernet MAC, but since not much of espressif's market may use the ethernet peripheral, there may be hardly any collisions in practice.
Re: ESP32 MAC address - is it unique?
Thanks for the detailed explanation.
Re: ESP32 MAC address - is it unique?
Here is a good explanation on how mac addresses are derived on the ESP32:
https://docs.espressif.com/projects/esp ... dress.html
And here is a good explanation for how many universal (unique) mac addresses are allocated to each ESP32
https://docs.espressif.com/projects/esp ... ystem.html
The answer is either 2 or 4 which is why the api has different ways to derive the BT mac depending on configuration. In the default case, 4 are allocated (but only one fused) so no chance of different interfaces colliding. I am not sure off hand to differentiate which mac configuration was burned in to the chip.
As of the middle of August 2021, ESP32 has 92 blocks of mac addresses (enough for about 400 million ESP32s with 4 per ESP32).
So yes, all 4 interface macs will be unique (though only the WiFi station mac is stored in the EFUSE)
https://docs.espressif.com/projects/esp ... dress.html
And here is a good explanation for how many universal (unique) mac addresses are allocated to each ESP32
https://docs.espressif.com/projects/esp ... ystem.html
The answer is either 2 or 4 which is why the api has different ways to derive the BT mac depending on configuration. In the default case, 4 are allocated (but only one fused) so no chance of different interfaces colliding. I am not sure off hand to differentiate which mac configuration was burned in to the chip.
As of the middle of August 2021, ESP32 has 92 blocks of mac addresses (enough for about 400 million ESP32s with 4 per ESP32).
So yes, all 4 interface macs will be unique (though only the WiFi station mac is stored in the EFUSE)
-
- Posts: 1
- Joined: Tue Jan 24, 2023 8:32 am
Re: ESP32 MAC address - is it unique?
How do you know that there are 92 blocks available to the ESP32?
Is there a source for this?
Is there a source for this?
Who is online
Users browsing this forum: Bing [Bot] and 227 guests