Skip to content

Commit 46010d1

Browse files
committed
boards/boardctl: Add BOARDIOC_MACADDR command
This commit adds 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 <daichuan@xiaomi.com>
1 parent e143acf commit 46010d1

5 files changed

Lines changed: 66 additions & 1 deletion

File tree

Documentation/reference/user/13_boardctl.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,16 @@ Board information
110110
which to receive the board unique ID.
111111

112112
:dependencies: Board logic must provide the :c:func:`board_uniqueid` interface.
113+
114+
.. c:macro:: BOARDIOC_MACADDR
115+
116+
Get the network driver MAC address.
117+
118+
:Argument: A pointer to an instance of :c:struct:`boardioc_macaddr_s`.
119+
120+
:configuration: CONFIG_BOARDCTL_MACADDR
121+
122+
:dependencies: Board logic must provide the :c:func:`board_macaddr` interface.
113123

114124
Filesystems
115125
-----------

boards/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5322,6 +5322,14 @@ config BOARDCTL_START_CPU
53225322
Architecture specific logic must provide the board_start_cpu()
53235323
interface.
53245324

5325+
config BOARDCTL_MACADDR
5326+
bool "Get network MAC address"
5327+
default n
5328+
---help---
5329+
Enables support for the BOARDIOC_MACADDR boardctl() command.
5330+
Architecture specific logic must provide the board_macaddr()
5331+
interface.
5332+
53255333
config BOARDCTL_IOCTL
53265334
bool "Board-specific boardctl() commands"
53275335
default n

boards/boardctl.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,24 @@ int boardctl(unsigned int cmd, uintptr_t arg)
906906
break;
907907
#endif
908908

909+
#ifdef CONFIG_BOARDCTL_MACADDR
910+
/* CMD: BOARDIOC_MACADDR
911+
* DESCRIPTION: Get the network driver mac address.
912+
* ARG: The mac address.
913+
* CONFIGURATION: CONFIG_BOARDCTL_MACADDR
914+
* DEPENDENCIES: Board logic must provide board_macaddr()
915+
*/
916+
917+
case BOARDIOC_MACADDR:
918+
{
919+
FAR struct boardioc_macaddr_s *req =
920+
(FAR struct boardioc_macaddr_s *)arg;
921+
922+
ret = board_macaddr(req->ifname, req->mac);
923+
}
924+
break;
925+
#endif
926+
909927
default:
910928
{
911929
#ifdef CONFIG_BOARDCTL_IOCTL

include/nuttx/board.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,26 @@ void board_autoled_off(int led);
635635
# define board_autoled_off(led)
636636
#endif
637637

638+
/****************************************************************************
639+
* Name: board_macaddr
640+
*
641+
* Description:
642+
* Get the network driver mac address.
643+
*
644+
* Input Parameters:
645+
* iface - The interface name.
646+
* mac - The mac address.
647+
*
648+
* Returned Value:
649+
* Zero (OK) is returned on success; a negated errno value is returned on
650+
* any failure.
651+
*
652+
****************************************************************************/
653+
654+
#ifdef CONFIG_BOARDCTL_MACADDR
655+
int board_macaddr(FAR const char *iface, FAR uint8_t *mac);
656+
#endif
657+
638658
/****************************************************************************
639659
* Name: board_userled_initialize
640660
*

include/sys/boardctl.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@
216216
#define BOARDIOC_RESET_CAUSE _BOARDIOC(0x0015)
217217
#define BOARDIOC_IRQ_AFFINITY _BOARDIOC(0x0016)
218218
#define BOARDIOC_START_CPU _BOARDIOC(0x0017)
219+
#define BOARDIOC_MACADDR _BOARDIOC(0x0018)
219220

220221
/* If CONFIG_BOARDCTL_IOCTL=y, then board-specific commands will be support.
221222
* In this case, all commands not recognized by boardctl() will be forwarded
@@ -224,7 +225,7 @@
224225
* User defined board commands may begin with this value:
225226
*/
226227

227-
#define BOARDIOC_USER _BOARDIOC(0x0018)
228+
#define BOARDIOC_USER _BOARDIOC(0x0019)
228229

229230
/****************************************************************************
230231
* Public Type Definitions
@@ -478,6 +479,14 @@ struct boardioc_reset_cause_s
478479
};
479480
#endif
480481

482+
#ifdef CONFIG_BOARDCTL_MACADDR
483+
struct boardioc_macaddr_s
484+
{
485+
FAR const char *ifname;
486+
FAR uint8_t *mac;
487+
};
488+
#endif
489+
481490
/****************************************************************************
482491
* Public Data
483492
****************************************************************************/

0 commit comments

Comments
 (0)