mirror of
https://github.com/Dasharo/zephyr.git
synced 2026-03-06 14:57:20 -08:00
drivers: ethernet: stm32 generate_mac
Ethernet MAC addresses are not unique enough use unique_device_ID full range (96 bits) call crc32_ieee() to generate last 3 bytes of mac address Signed-off-by: Marc Desvaux <marc.desvaux-ext@st.com>
This commit is contained in:
committed by
Carles Cufí
parent
0f23cda744
commit
76ba68cd18
@@ -1098,6 +1098,9 @@ void HAL_ETH_RxCpltCallback(ETH_HandleTypeDef *heth_handle)
|
||||
|
||||
static void generate_mac(uint8_t *mac_addr)
|
||||
{
|
||||
uint8_t unique_device_ID_12_bytes[12];
|
||||
uint32_t result_mac_32_bits;
|
||||
|
||||
#if defined(ETH_STM32_RANDOM_MAC)
|
||||
/* Either CONFIG_ETH_STM32_HAL_RANDOM_MAC or device tree property */
|
||||
/* "zephyr,random-mac-address" is set, generate a random mac address */
|
||||
@@ -1116,7 +1119,10 @@ static void generate_mac(uint8_t *mac_addr)
|
||||
mac_addr[5] = CONFIG_ETH_STM32_HAL_MAC5;
|
||||
#else
|
||||
/* Nothing defined by the user, use device id */
|
||||
hwinfo_get_device_id(&mac_addr[3], 3);
|
||||
hwinfo_get_device_id(unique_device_ID_12_bytes, 12);
|
||||
result_mac_32_bits = crc32_ieee((uint8_t *)unique_device_ID_12_bytes, 12);
|
||||
memcpy(&mac_addr[3], &result_mac_32_bits, 3);
|
||||
|
||||
#endif /* NODE_HAS_VALID_MAC_ADDR(DT_DRV_INST(0))) */
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user