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.git
The following commit(s) were added to refs/heads/master by this push:
new 763caabf6d0 boards/boardctl: Add BOARDIOC_MACADDR command
763caabf6d0 is described below
commit 763caabf6d02cc159849290edd52ac62c16e0e6e
Author: daichuan <[email protected]>
AuthorDate: Tue Jan 20 15:48:55 2026 +0800
boards/boardctl: Add BOARDIOC_MACADDR command
Add a new boardctl command BOARDIOC_MACADDR to retrieve the MAC address of
the network interface.
The board_macaddr function needs to be implemented by the board logic.
Signed-off-by: daichuan <[email protected]>
---
Documentation/reference/user/13_boardctl.rst | 10 ++++++++++
boards/Kconfig | 8 ++++++++
boards/boardctl.c | 19 +++++++++++++++++++
include/nuttx/board.h | 20 ++++++++++++++++++++
include/sys/boardctl.h | 16 +++++++++++++++-
5 files changed, 72 insertions(+), 1 deletion(-)
diff --git a/Documentation/reference/user/13_boardctl.rst
b/Documentation/reference/user/13_boardctl.rst
index f5326f43ef8..137e5739915 100644
--- a/Documentation/reference/user/13_boardctl.rst
+++ b/Documentation/reference/user/13_boardctl.rst
@@ -110,6 +110,16 @@ Board information
which to receive the board unique ID.
:dependencies: Board logic must provide the :c:func:`board_uniqueid`
interface.
+
+.. c:macro:: BOARDIOC_MACADDR
+
+ Get the network driver MAC address.
+
+ :Argument: A pointer to an instance of :c:struct:`boardioc_macaddr_s`.
+
+ :configuration: CONFIG_BOARDCTL_MACADDR
+
+ :dependencies: Board logic must provide the :c:func:`board_macaddr`
interface.
Filesystems
-----------
diff --git a/boards/Kconfig b/boards/Kconfig
index de6b20a8196..cc91f727186 100644
--- a/boards/Kconfig
+++ b/boards/Kconfig
@@ -5322,6 +5322,14 @@ config BOARDCTL_START_CPU
Architecture specific logic must provide the board_start_cpu()
interface.
+config BOARDCTL_MACADDR
+ bool "Get network MAC address"
+ default n
+ ---help---
+ Enables support for the BOARDIOC_MACADDR boardctl() command.
+ Architecture specific logic must provide the board_macaddr()
+ interface.
+
config BOARDCTL_IOCTL
bool "Board-specific boardctl() commands"
default n
diff --git a/boards/boardctl.c b/boards/boardctl.c
index f784ceb6f26..e4006aebdcb 100644
--- a/boards/boardctl.c
+++ b/boards/boardctl.c
@@ -906,6 +906,25 @@ int boardctl(unsigned int cmd, uintptr_t arg)
break;
#endif
+#ifdef CONFIG_BOARDCTL_MACADDR
+ /* CMD: BOARDIOC_MACADDR
+ * DESCRIPTION: Get the network driver mac address.
+ * ARG: A pointer to an instance of struct
+ * boardioc_macaddr_s.
+ * CONFIGURATION: CONFIG_BOARDCTL_MACADDR
+ * DEPENDENCIES: Board logic must provide board_macaddr()
+ */
+
+ case BOARDIOC_MACADDR:
+ {
+ FAR struct boardioc_macaddr_s *req =
+ (FAR struct boardioc_macaddr_s *)arg;
+
+ ret = board_macaddr(req->ifname, req->macaddr);
+ }
+ break;
+#endif
+
default:
{
#ifdef CONFIG_BOARDCTL_IOCTL
diff --git a/include/nuttx/board.h b/include/nuttx/board.h
index 2ca04d1f54f..4656104b993 100644
--- a/include/nuttx/board.h
+++ b/include/nuttx/board.h
@@ -635,6 +635,26 @@ void board_autoled_off(int led);
# define board_autoled_off(led)
#endif
+/****************************************************************************
+ * Name: board_macaddr
+ *
+ * Description:
+ * Get the network driver mac address.
+ *
+ * Input Parameters:
+ * ifname - The interface name.
+ * macaddr - The mac address.
+ *
+ * Returned Value:
+ * Zero (OK) is returned on success; a negated errno value is returned on
+ * any failure.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_BOARDCTL_MACADDR
+int board_macaddr(FAR const char *ifname, FAR uint8_t *macaddr);
+#endif
+
/****************************************************************************
* Name: board_userled_initialize
*
diff --git a/include/sys/boardctl.h b/include/sys/boardctl.h
index 934b8ea23f1..d0508efef7c 100644
--- a/include/sys/boardctl.h
+++ b/include/sys/boardctl.h
@@ -48,6 +48,11 @@
# include <nuttx/spinlock.h>
#endif
+#ifdef CONFIG_BOARDCTL_MACADDR
+# include <net/if.h>
+# include <nuttx/net/netdev.h>
+#endif
+
#ifdef CONFIG_BOARDCTL
/****************************************************************************
@@ -216,6 +221,7 @@
#define BOARDIOC_RESET_CAUSE _BOARDIOC(0x0015)
#define BOARDIOC_IRQ_AFFINITY _BOARDIOC(0x0016)
#define BOARDIOC_START_CPU _BOARDIOC(0x0017)
+#define BOARDIOC_MACADDR _BOARDIOC(0x0018)
/* If CONFIG_BOARDCTL_IOCTL=y, then board-specific commands will be support.
* In this case, all commands not recognized by boardctl() will be forwarded
@@ -224,7 +230,7 @@
* User defined board commands may begin with this value:
*/
-#define BOARDIOC_USER _BOARDIOC(0x0018)
+#define BOARDIOC_USER _BOARDIOC(0x0019)
/****************************************************************************
* Public Type Definitions
@@ -478,6 +484,14 @@ struct boardioc_reset_cause_s
};
#endif
+#ifdef CONFIG_BOARDCTL_MACADDR
+struct boardioc_macaddr_s
+{
+ char ifname[IFNAMSIZ];
+ uint8_t macaddr[RADIO_MAX_ADDRLEN];
+};
+#endif
+
/****************************************************************************
* Public Data
****************************************************************************/