Skip to content

Commit 8241eb8

Browse files
committed
drivers: wifi: nrf_wifi: Optional MAC configuration from devicetree
Allow setting the MAC address for the nRF Wi-Fi interface with a configuration derived from the devicetree. This allows to use an NVMEM cell as MAC address storage. Signed-off-by: Pieter De Gendt <[email protected]>
1 parent f55dfcd commit 8241eb8

File tree

4 files changed

+31
-86
lines changed

4 files changed

+31
-86
lines changed

drivers/wifi/nrf_wifi/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ zephyr_include_directories(
1313
inc
1414
# for net_sprint_ll_addr
1515
${ZEPHYR_BASE}/subsys/net/ip
16+
# for net_eth_mac_load
17+
${ZEPHYR_BASE}/drivers/ethernet
1618
)
1719

1820
zephyr_include_directories_ifdef(CONFIG_NRF70_OFFLOADED_RAW_TX

drivers/wifi/nrf_wifi/Kconfig.nrfwifi

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -532,37 +532,6 @@ config NRF70_RPU_EXTEND_TWT_SP
532532
mechanism is not used.
533533
endif # NRF_WIFI_LOW_POWER
534534

535-
config WIFI_FIXED_MAC_ADDRESS
536-
string "Wi-Fi Fixed MAC address in format XX:XX:XX:XX:XX:XX"
537-
help
538-
This option overrides the MAC address read from OTP. It is strictly for testing purposes only.
539-
540-
choice
541-
prompt "Wi-Fi MAC address type"
542-
default WIFI_FIXED_MAC_ADDRESS_ENABLED if WIFI_FIXED_MAC_ADDRESS != ""
543-
default WIFI_OTP_MAC_ADDRESS
544-
help
545-
Select the type of MAC address to be used by the Wi-Fi driver
546-
547-
config WIFI_OTP_MAC_ADDRESS
548-
bool "Use MAC address from OTP"
549-
help
550-
This option uses the MAC address stored in the OTP memory of the nRF70.
551-
552-
config WIFI_FIXED_MAC_ADDRESS_ENABLED
553-
bool "fixed MAC address"
554-
help
555-
Enable fixed MAC address
556-
557-
config WIFI_RANDOM_MAC_ADDRESS
558-
bool "Random MAC address generation at runtime"
559-
depends on ENTROPY_GENERATOR
560-
help
561-
This option enables random MAC address generation at runtime.
562-
The random MAC address is generated using the entropy device random generator.
563-
564-
endchoice
565-
566535
config NRF70_RSSI_STALE_TIMEOUT_MS
567536
int "RSSI stale timeout in milliseconds"
568537
default 1000

drivers/wifi/nrf_wifi/src/fmac_main.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -974,16 +974,19 @@ static const struct net_wifi_mgmt_offload wifi_offload_ops = {
974974
.wifi_drv_ops = &wpa_supp_ops,
975975
#endif /* CONFIG_NRF70_STA_MODE */
976976
};
977-
#endif /* CONFIG_NET_L2_ETHERNET */
978-
979977

978+
NET_ETH_MAC_DT_INST_DEFINE(0);
979+
#ifdef CONFIG_NRF70_ENABLE_DUAL_VIF
980+
NET_ETH_MAC_DT_INST_DEFINE(1);
981+
#endif
982+
#endif /* CONFIG_NET_L2_ETHERNET */
980983

981984
#ifdef CONFIG_NET_L2_ETHERNET
982985
ETH_NET_DEVICE_DT_INST_DEFINE(0,
983986
nrf_wifi_drv_main_zep, /* init_fn */
984987
NULL, /* pm_action_cb */
985988
&rpu_drv_priv_zep.rpu_ctx_zep.vif_ctx_zep[0], /* data */
986-
NULL, /* cfg */
989+
NET_ETH_MAC_DT_INST_DEV_CONFIG_GET(0), /* cfg */
987990
CONFIG_WIFI_INIT_PRIORITY, /* prio */
988991
&wifi_offload_ops, /* api */
989992
CONFIG_NRF_WIFI_IFACE_MTU); /*mtu */
@@ -993,7 +996,7 @@ ETH_NET_DEVICE_DT_INST_DEFINE(1,
993996
nrf_wifi_drv_main_zep, /* init_fn */
994997
NULL, /* pm_action_cb */
995998
&rpu_drv_priv_zep.rpu_ctx_zep.vif_ctx_zep[1], /* data */
996-
NULL, /* cfg */
999+
NET_ETH_MAC_DT_INST_DEV_CONFIG_GET(1), /* cfg */
9971000
CONFIG_WIFI_INIT_PRIORITY, /* prio */
9981001
&wifi_offload_ops, /* api */
9991002
CONFIG_NRF_WIFI_IFACE_MTU); /*mtu */

drivers/wifi/nrf_wifi/src/net_if.c

Lines changed: 22 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@
1111

1212
#include <stdlib.h>
1313

14-
#ifdef CONFIG_WIFI_RANDOM_MAC_ADDRESS
15-
#include <zephyr/random/random.h>
16-
#endif
17-
1814
#include <zephyr/logging/log.h>
1915
LOG_MODULE_DECLARE(wifi_nrf, CONFIG_WIFI_NRF70_LOG_LEVEL);
2016

@@ -29,6 +25,7 @@ LOG_MODULE_DECLARE(wifi_nrf, CONFIG_WIFI_NRF70_LOG_LEVEL);
2925
#include "fmac_main.h"
3026
#include "wpa_supp_if.h"
3127
#include "net_if.h"
28+
#include "eth.h"
3229

3330
extern char *net_sprint_ll_addr_buf(const uint8_t *ll, uint8_t ll_len,
3431
char *buf, int buflen);
@@ -553,16 +550,12 @@ static void ip_maddr_event_handler(struct net_if *iface,
553550
}
554551
#endif /* CONFIG_NRF70_STA_MODE */
555552

556-
#ifdef CONFIG_WIFI_FIXED_MAC_ADDRESS_ENABLED
557-
BUILD_ASSERT(sizeof(CONFIG_WIFI_FIXED_MAC_ADDRESS) - 1 == ((WIFI_MAC_ADDR_LEN * 2) + 5),
558-
"Invalid fixed MAC address length");
559-
#endif
560-
561553
enum nrf_wifi_status nrf_wifi_get_mac_addr(struct nrf_wifi_vif_ctx_zep *vif_ctx_zep)
562554
{
563555
enum nrf_wifi_status status = NRF_WIFI_STATUS_FAIL;
564556
struct nrf_wifi_fmac_dev_ctx *fmac_dev_ctx = NULL;
565557
struct nrf_wifi_ctx_zep *rpu_ctx_zep = NULL;
558+
const struct net_eth_mac_config *mac_cfg = NULL;
566559
int ret;
567560

568561
if (!vif_ctx_zep) {
@@ -585,52 +578,30 @@ enum nrf_wifi_status nrf_wifi_get_mac_addr(struct nrf_wifi_vif_ctx_zep *vif_ctx_
585578
}
586579

587580
fmac_dev_ctx = rpu_ctx_zep->rpu_ctx;
581+
mac_cfg = vif_ctx_zep->zep_dev_ctx->config;
588582

589-
#ifdef CONFIG_WIFI_FIXED_MAC_ADDRESS_ENABLED
590-
char fixed_mac_addr[WIFI_MAC_ADDR_LEN];
591-
592-
ret = net_bytes_from_str(fixed_mac_addr,
593-
WIFI_MAC_ADDR_LEN,
594-
CONFIG_WIFI_FIXED_MAC_ADDRESS);
595-
if (ret < 0) {
596-
LOG_ERR("%s: Failed to parse MAC address: %s",
597-
__func__,
598-
CONFIG_WIFI_FIXED_MAC_ADDRESS);
599-
goto unlock;
600-
}
601-
602-
memcpy(vif_ctx_zep->mac_addr.addr,
603-
fixed_mac_addr,
604-
WIFI_MAC_ADDR_LEN);
605-
#elif CONFIG_WIFI_RANDOM_MAC_ADDRESS
606-
char random_mac_addr[WIFI_MAC_ADDR_LEN];
607-
608-
sys_rand_get(random_mac_addr, WIFI_MAC_ADDR_LEN);
609-
random_mac_addr[0] = (random_mac_addr[0] & UNICAST_MASK) | LOCAL_BIT;
610-
611-
memcpy(vif_ctx_zep->mac_addr.addr,
612-
random_mac_addr,
613-
WIFI_MAC_ADDR_LEN);
614-
#elif CONFIG_WIFI_OTP_MAC_ADDRESS
583+
ret = net_eth_mac_load(mac_cfg, vif_ctx_zep->mac_addr.addr);
584+
if (ret == -ENODATA) {
615585
#ifndef CONFIG_NRF71_ON_IPC
616-
status = nrf_wifi_fmac_otp_mac_addr_get(fmac_dev_ctx,
617-
vif_ctx_zep->vif_idx,
618-
vif_ctx_zep->mac_addr.addr);
619-
if (status != NRF_WIFI_STATUS_SUCCESS) {
620-
LOG_ERR("%s: Fetching of MAC address from OTP failed",
621-
__func__);
622-
goto unlock;
623-
}
586+
status = nrf_wifi_fmac_otp_mac_addr_get(fmac_dev_ctx, vif_ctx_zep->vif_idx,
587+
vif_ctx_zep->mac_addr.addr);
588+
if (status != NRF_WIFI_STATUS_SUCCESS) {
589+
LOG_ERR("%s: Fetching of MAC address from OTP failed", __func__);
590+
goto unlock;
591+
}
624592
#else
625-
/* Set dummy MAC address */
626-
vif_ctx_zep->mac_addr.addr[0] = 0x00;
627-
vif_ctx_zep->mac_addr.addr[1] = 0x00;
628-
vif_ctx_zep->mac_addr.addr[2] = 0x5E;
629-
vif_ctx_zep->mac_addr.addr[3] = 0x00;
630-
vif_ctx_zep->mac_addr.addr[4] = 0x10;
631-
vif_ctx_zep->mac_addr.addr[5] = 0x00;
593+
/* Set dummy MAC address */
594+
vif_ctx_zep->mac_addr.addr[0] = 0x00;
595+
vif_ctx_zep->mac_addr.addr[1] = 0x00;
596+
vif_ctx_zep->mac_addr.addr[2] = 0x5E;
597+
vif_ctx_zep->mac_addr.addr[3] = 0x00;
598+
vif_ctx_zep->mac_addr.addr[4] = 0x10;
599+
vif_ctx_zep->mac_addr.addr[5] = 0x00;
632600
#endif /* !CONFIG_NRF71_ON_IPC */
633-
#endif
601+
} else if (ret < 0) {
602+
LOG_ERR("%s: Loading of MAC address from config failed (%d)", __func__, ret);
603+
goto unlock;
604+
}
634605

635606
if (!nrf_wifi_utils_is_mac_addr_valid(vif_ctx_zep->mac_addr.addr)) {
636607
LOG_ERR("%s: Invalid MAC address: %s",

0 commit comments

Comments
 (0)