This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
The following commit(s) were added to refs/heads/master by this push:
new b80d67c62 netutils/netinit: Support the NETINIT_MACADDR
b80d67c62 is described below
commit b80d67c6281356efde5bd72d2d1466d8bd1593fb
Author: liqinhui <[email protected]>
AuthorDate: Fri Jun 6 10:07:25 2025 +0800
netutils/netinit: Support the NETINIT_MACADDR
Support getting MAC address from boardctl(BOARDIOC_MACADDR) via
NETINIT_MACADDR.
Signed-off-by: liqinhui <[email protected]>
---
include/netutils/netinit.h | 4 ----
netutils/netinit/Kconfig | 7 +++++++
netutils/netinit/netinit.c | 13 +++++++++++--
3 files changed, 18 insertions(+), 6 deletions(-)
diff --git a/include/netutils/netinit.h b/include/netutils/netinit.h
index 3c3c85d50..320fa1498 100644
--- a/include/netutils/netinit.h
+++ b/include/netutils/netinit.h
@@ -57,10 +57,6 @@
# define CONFIG_NETINIT_DNSIPADDR CONFIG_NETINIT_DRIPADDR
#endif
-#ifndef CONFIG_NETINIT_MACADDR
-# define CONFIG_NETINIT_MACADDR 0x00e0deadbeef
-#endif
-
#if !defined(CONFIG_NETINIT_THREAD) || !defined(CONFIG_ARCH_PHY_INTERRUPT) || \
!defined(CONFIG_NETDEV_PHY_IOCTL) || !defined(CONFIG_NET_UDP)
# undef CONFIG_NETINIT_MONITOR
diff --git a/netutils/netinit/Kconfig b/netutils/netinit/Kconfig
index 2031c7bae..8d91b0b50 100644
--- a/netutils/netinit/Kconfig
+++ b/netutils/netinit/Kconfig
@@ -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
diff --git a/netutils/netinit/netinit.c b/netutils/netinit/netinit.c
index 4433eb4a5..c0a459725 100644
--- a/netutils/netinit/netinit.c
+++ b/netutils/netinit/netinit.c
@@ -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];
@@ -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);