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
6 changes: 6 additions & 0 deletions netutils/netinit/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,12 @@ config NETINIT_SWMAC
With this choice, you can assign a fixed MAC address determined by
a NuttX configuration option.

config NETINIT_WIFIMAC
bool "Device Wi-Fi MAC"
---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
15 changes: 13 additions & 2 deletions netutils/netinit/netinit.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,10 @@ 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_WIFIMAC)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if both wifi and eth are available? Having wifi defined will discard mac definition, correct?

Shouldn't we

#if defined(CONFIG_NETINIT_WIFIMAC)
  char wifi_mac_str[20];
  uint8_t wifi_mac[IFHWADDRLEN];
#endif
#if defined(CONFIG_NETINIT_UIDMAC)
..

char macstr[20];
uint8_t wifi_mac[IFHWADDRLEN];
#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 +299,15 @@ 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_WIFIMAC)
#define BOARDIOC_USER_MAC_WIFI (BOARDIOC_USER + 3)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's define a offical boar ioctl to expose the mac address, @13627105546


boardctl(BOARDIOC_USER_MAC_WIFI, (uintptr_t)macstr);
if (netlib_ethaddrconv(macstr, wifi_mac))
{
netlib_setmacaddr(NET_DEVNAME, wifi_mac);
}
#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
Loading