Skip to content

Commit c710681

Browse files
liqinhuixm13627105546
authored andcommitted
netutils/netinit: Add Wi-Fi MAC support
Support getting MAC from boardctl for Wi-Fi. Signed-off-by: liqinhui <liqinhui@xiaomi.com>
1 parent b0b90ac commit c710681

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

netutils/netinit/Kconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,12 @@ config NETINIT_SWMAC
488488
With this choice, you can assign a fixed MAC address determined by
489489
a NuttX configuration option.
490490

491+
config NETINIT_WIFIMAC
492+
bool "Device Wi-Fi MAC"
493+
---help---
494+
With this choice, you can assign a fixed MAC address in the file
495+
device.info (DEVICE_INFO_PATH) defined by user.
496+
491497
endchoice # MAC address selection
492498

493499
config NETINIT_MACADDR_1

netutils/netinit/netinit.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,10 @@ static const uint16_t g_ipv6_netmask[8] =
286286
defined(HAVE_MAC)
287287
static void netinit_set_macaddr(void)
288288
{
289+
#if defined(CONFIG_NETINIT_WIFIMAC)
290+
char macstr[20];
291+
uint8_t wifi_mac[IFHWADDRLEN];
292+
#endif
289293
#if defined(CONFIG_NETINIT_UIDMAC)
290294
uint8_t uid[CONFIG_BOARDCTL_UNIQUEID_SIZE];
291295
#elif defined(CONFIG_NET_ETHERNET)
@@ -296,6 +300,14 @@ static void netinit_set_macaddr(void)
296300

297301
/* Many embedded network interfaces must have a software assigned MAC */
298302

303+
#if defined(CONFIG_NETINIT_WIFIMAC)
304+
boardctl(BOARDIOC_NET_GETMAC, (uintptr_t)macstr);
305+
if (netlib_ethaddrconv(macstr, wifi_mac))
306+
{
307+
netlib_setmacaddr(NET_DEVNAME, wifi_mac);
308+
}
309+
#endif
310+
299311
#if defined(CONFIG_NETINIT_UIDMAC)
300312
boardctl(BOARDIOC_UNIQUEID, (uintptr_t)&uid);
301313
uid[0] = (uid[0] & 0b11110000) | 2; /* Locally Administered MAC */

0 commit comments

Comments
 (0)