Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions netutils/netinit/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,13 @@ config NETINIT_SWMAC
With this choice, you can assign a fixed MAC address determined by
a NuttX configuration option.

config NETINIT_MACADDR
bool "Device MAC address"
depends on BOARDCTL_MACADDR
---help---
With this choice, you can assign a fixed MAC address in the file
device.info (DEVICE_INFO_PATH) defined by user.

endchoice # MAC address selection

config NETINIT_MACADDR_1
Expand Down
13 changes: 11 additions & 2 deletions netutils/netinit/netinit.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,9 @@ static const uint16_t g_ipv6_netmask[8] =
defined(HAVE_MAC)
static void netinit_set_macaddr(void)
{
#if defined(CONFIG_NETINIT_UIDMAC)
#if defined(CONFIG_NETINIT_MACADDR)
struct boardioc_macaddr_s req;
#elif defined(CONFIG_NETINIT_UIDMAC)
uint8_t uid[CONFIG_BOARDCTL_UNIQUEID_SIZE];
#elif defined(CONFIG_NET_ETHERNET)
uint8_t mac[IFHWADDRLEN];
Expand All @@ -296,7 +298,14 @@ static void netinit_set_macaddr(void)

/* Many embedded network interfaces must have a software assigned MAC */

#if defined(CONFIG_NETINIT_UIDMAC)
#if defined(CONFIG_NETINIT_MACADDR)
strlcpy(req.ifname, NET_DEVNAME, IFNAMSIZ);
if (boardctl(BOARDIOC_MACADDR, (uintptr_t)&req) == 0)
{
netlib_setmacaddr(NET_DEVNAME, req.macaddr);
}

#elif defined(CONFIG_NETINIT_UIDMAC)
boardctl(BOARDIOC_UNIQUEID, (uintptr_t)&uid);
uid[0] = (uid[0] & 0b11110000) | 2; /* Locally Administered MAC */
netlib_setmacaddr(NET_DEVNAME, uid);
Expand Down