From 98062ea2219c7ca6e1a2e44ef08125b0630d9a80 Mon Sep 17 00:00:00 2001 From: daichuan Date: Tue, 20 Jan 2026 15:48:55 +0800 Subject: [PATCH] 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 --- 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 f5326f43ef86e..137e57399151b 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 342e33160ae93..4490722536dda 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 f784ceb6f2602..e4006aebdcb7b 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 2ca04d1f54f1a..4656104b993f2 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 934b8ea23f1af..d0508efef7cd5 100644 --- a/include/sys/boardctl.h +++ b/include/sys/boardctl.h @@ -48,6 +48,11 @@ # include #endif +#ifdef CONFIG_BOARDCTL_MACADDR +# include +# include +#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 ****************************************************************************/