diff --git a/netutils/netinit/Kconfig b/netutils/netinit/Kconfig index 6af444e6a..2031c7bae 100644 --- a/netutils/netinit/Kconfig +++ b/netutils/netinit/Kconfig @@ -474,6 +474,14 @@ choice address to the hardware before it brings the network up. This choice allows you select the source of that MAC address. +config NETINIT_UIDMAC + bool "Board Unique ID" + depends on BOARDCTL_UNIQUEID + ---help--- + Assign a MAC address based on the board unique ID. + CONFIG_BOARDCTL_UNIQUEID_SIZE must be at least 6 bytes for + Ethernet, 8 bytes for 6LOWPAN. + config NETINIT_SWMAC bool "Fixed address" ---help--- diff --git a/netutils/netinit/netinit.c b/netutils/netinit/netinit.c index 8e9f14792..2f4d0a78d 100644 --- a/netutils/netinit/netinit.c +++ b/netutils/netinit/netinit.c @@ -48,6 +48,7 @@ #include #include +#include #include "netutils/netlib.h" #if defined(CONFIG_NETUTILS_DHCPC) || defined(CONFIG_NETINIT_DNS) @@ -289,7 +290,9 @@ static const uint16_t g_ipv6_netmask[8] = defined(HAVE_MAC) static void netinit_set_macaddr(void) { -#if defined(CONFIG_NET_ETHERNET) +#if defined(CONFIG_NETINIT_UIDMAC) + uint8_t uid[CONFIG_BOARDCTL_UNIQUEID_SIZE]; +#elif defined(CONFIG_NET_ETHERNET) uint8_t mac[IFHWADDRLEN]; #elif defined(HAVE_EADDR) uint8_t eaddr[8]; @@ -297,7 +300,12 @@ static void netinit_set_macaddr(void) /* Many embedded network interfaces must have a software assigned MAC */ -#if defined(CONFIG_NET_ETHERNET) +#if defined(CONFIG_NETINIT_UIDMAC) + boardctl(BOARDIOC_UNIQUEID, (uintptr_t)&uid); + uid[0] = (uid[0] & 0b11110000) | 2; /* Locally Administered MAC */ + netlib_setmacaddr(NET_DEVNAME, uid); + +#elif defined(CONFIG_NET_ETHERNET) /* Use the configured, fixed MAC address */ mac[0] = (CONFIG_NETINIT_MACADDR_2 >> (8 * 1)) & 0xff;