Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/nxp shim driver fixes #85285

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions drivers/wifi/nxp/Kconfig.nxp
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,8 @@ config NXP_WIFI_SOFTAP_SUPPORT
bool "Wi-Fi SoftAP Support"
select NET_DHCPV4_SERVER
select WIFI_NM_HOSTAPD_AP if WIFI_NM_WPA_SUPPLICANT
imply WIFI_NM_HOSTAPD_WPS if WIFI_NM_HOSTAPD_AP && WIFI_NM_WPA_SUPPLICANT_WPS
imply WIFI_NM_HOSTAPD_CRYPTO_ENTERPRISE if WIFI_NM_HOSTAPD_AP && WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE
default y
help
Option to enable Wi-Fi SoftAP functions in the Wi-Fi driver.
Expand Down Expand Up @@ -720,6 +722,7 @@ config NXP_WIFI_RESET
config NXP_WIFI_ECSA
bool "ECSA"
default y
depends on NXP_WIFI_SOFTAP_SUPPORT
help
This option is used to do channel switch according to spec.

Expand Down
126 changes: 122 additions & 4 deletions drivers/wifi/nxp/nxp_wifi_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ LOG_MODULE_REGISTER(nxp_wifi, CONFIG_WIFI_LOG_LEVEL);
******************************************************************************/
static int s_nxp_wifi_State = NXP_WIFI_NOT_INITIALIZED;
static bool s_nxp_wifi_StaConnected;
#ifdef CONFIG_NXP_WIFI_SOFTAP_SUPPORT
static bool s_nxp_wifi_UapActivated;
#endif
static struct k_event s_nxp_wifi_SyncEvent;

static struct nxp_wifi_dev nxp_wifi0; /* static instance */
Expand All @@ -59,7 +61,7 @@ static struct wlan_network nxp_wlan_network;
static struct wlan_network nxp_wlan_uap_network;
#endif

#ifndef CONFIG_WIFI_NM_HOSTAPD_AP
#if defined(CONFIG_NXP_WIFI_SOFTAP_SUPPORT) && !defined(CONFIG_WIFI_NM_HOSTAPD_AP)
static char uap_ssid[IEEEtypes_SSID_SIZE + 1];
#endif

Expand Down Expand Up @@ -103,9 +105,9 @@ int nxp_wifi_wlan_event_callback(enum wlan_event_reason reason, void *data)
struct in_addr dhcps_addr4;
struct in_addr base_addr;
struct in_addr netmask_addr;
#endif
struct wifi_iface_status status = { 0 };
struct wifi_ap_sta_info ap_sta_info = { 0 };
#endif

LOG_DBG("WLAN: received event %d", reason);

Expand Down Expand Up @@ -151,6 +153,10 @@ int nxp_wifi_wlan_event_callback(enum wlan_event_reason reason, void *data)
net_if_dormant_off(g_mlan.netif);
#endif
LOG_DBG("WLAN: associated to nxp_wlan_network");
#ifdef CONFIG_NET_STATISTICS_WIFI
g_mlan.stats.sta_mgmt.beacons_rx = 0;
g_mlan.stats.sta_mgmt.beacons_miss = 0;
#endif
break;
case WLAN_REASON_SUCCESS:
LOG_DBG("WLAN: connected to nxp_wlan_network");
Expand Down Expand Up @@ -566,6 +572,9 @@ static int nxp_wifi_start_ap(const struct device *dev, struct wifi_connect_req_p
return -ENOENT;
}

nxp_wlan_uap_network.beacon_period = NXP_WIFI_SAP_BEACON_PERIOD_DEFAULT;
nxp_wlan_uap_network.dtim_period = NXP_WIFI_SAP_DTIM_PERIOD_DEFAULT;

ret = wlan_add_network(&nxp_wlan_uap_network);
if (ret != WM_SUCCESS) {
status = NXP_WIFI_RET_FAIL;
Expand Down Expand Up @@ -1062,6 +1071,10 @@ static int nxp_wifi_uap_status(const struct device *dev, struct wifi_iface_statu

status->dtim_period = nxp_wlan_uap_network.dtim_period;

#ifdef CONFIG_NXP_WIFI_11AX_TWT
status->twt_capable = true;
#endif

if (if_handle->state.interface == WLAN_BSS_TYPE_STA) {
status->iface_mode = WIFI_MODE_INFRA;
} else if (if_handle->state.interface == WLAN_BSS_TYPE_UAP) {
Expand Down Expand Up @@ -1177,9 +1190,33 @@ static int nxp_wifi_status(const struct device *dev, struct wifi_iface_status *s
}

#if defined(CONFIG_NET_STATISTICS_WIFI)
#ifdef CONFIG_NXP_WIFI_GET_LOG
static int nxp_wifi_get_detail_stats(int bss_type, wlan_pkt_stats_t *stats)
{
int ret;

if (bss_type == WLAN_BSS_TYPE_STA) {
ret = wlan_get_log(stats);
}
#ifdef CONFIG_NXP_WIFI_SOFTAP_SUPPORT
else if (bss_type == WLAN_BSS_TYPE_UAP) {
ret = wlan_uap_get_log(stats);
}
#endif
else {
ret = -ENODEV;
}
return ret;
}
#endif

static int nxp_wifi_stats(const struct device *dev, struct net_stats_wifi *stats)
{
struct interface *if_handle = (struct interface *)dev->data;
#ifdef CONFIG_NXP_WIFI_GET_LOG
int ret;
wlan_pkt_stats_t *wifi_stats;
#endif

stats->bytes.received = if_handle->stats.bytes.received;
stats->bytes.sent = if_handle->stats.bytes.sent;
Expand All @@ -1191,8 +1228,79 @@ static int nxp_wifi_stats(const struct device *dev, struct net_stats_wifi *stats
stats->broadcast.tx = if_handle->stats.broadcast.tx;
stats->multicast.rx = if_handle->stats.multicast.rx;
stats->multicast.tx = if_handle->stats.multicast.tx;
stats->sta_mgmt.beacons_rx = if_handle->stats.sta_mgmt.beacons_rx;
stats->sta_mgmt.beacons_miss = if_handle->stats.sta_mgmt.beacons_miss;
stats->unicast.rx = if_handle->stats.unicast.rx;
stats->unicast.tx = if_handle->stats.unicast.tx;
stats->overrun_count = if_handle->stats.errors.rx + if_handle->stats.errors.tx;

#ifdef CONFIG_NXP_WIFI_GET_LOG
wifi_stats = k_malloc(sizeof(wlan_pkt_stats_t));
if (!wifi_stats) {
LOG_WRN("No mem for detailed statistics");
return 0;
}

memset(wifi_stats, 0, sizeof(wlan_pkt_stats_t));
ret = nxp_wifi_get_detail_stats(if_handle->state.interface, wifi_stats);
if (ret != 0) {
LOG_ERR("Get detailed statistics from Wi-Fi failed ret %d", ret);
k_free(wifi_stats);
return ret;
}

if (wifi_stats->bcn_rcv_cnt >= if_handle->stats.sta_mgmt.beacons_rx) {
stats->sta_mgmt.beacons_rx = wifi_stats->bcn_rcv_cnt -
if_handle->stats.sta_mgmt.beacons_rx;
} else {
/** we might have a new connection since last stats reset,
* so stored stats is invalid
*/
stats->sta_mgmt.beacons_rx = wifi_stats->bcn_rcv_cnt;
}

if (wifi_stats->bcn_miss_cnt >= if_handle->stats.sta_mgmt.beacons_miss) {
stats->sta_mgmt.beacons_miss = wifi_stats->bcn_miss_cnt -
if_handle->stats.sta_mgmt.beacons_miss;
} else {
stats->sta_mgmt.beacons_miss = wifi_stats->bcn_miss_cnt;
}

k_free(wifi_stats);
#endif
return 0;
}

int nxp_wifi_reset_stats(const struct device *dev)
{
struct interface *if_handle = (struct interface *)dev->data;
#ifdef CONFIG_NXP_WIFI_GET_LOG
int ret;
wlan_pkt_stats_t *wifi_stats;
#endif

/* clear local statistics */
memset(&if_handle->stats, 0, sizeof(if_handle->stats));

#ifdef CONFIG_NXP_WIFI_GET_LOG
/* store firmware statistics */
wifi_stats = k_malloc(sizeof(wlan_pkt_stats_t));
if (!wifi_stats) {
LOG_WRN("No mem to reset detailed statistics");
return 0;
}

memset(wifi_stats, 0, sizeof(wlan_pkt_stats_t));
ret = nxp_wifi_get_detail_stats(if_handle->state.interface, wifi_stats);
if (ret != 0) {
LOG_ERR("Reset detailed statistics from Wi-Fi failed ret %d", ret);
k_free(wifi_stats);
return ret;
}

if_handle->stats.sta_mgmt.beacons_rx = wifi_stats->bcn_rcv_cnt;
if_handle->stats.sta_mgmt.beacons_miss = wifi_stats->bcn_miss_cnt;

k_free(wifi_stats);
#endif

return 0;
}
Expand Down Expand Up @@ -1577,6 +1685,7 @@ static int nxp_wifi_set_twt(const struct device *dev, struct wifi_twt_params *pa
return ret;
}

#ifdef CONFIG_NXP_WIFI_SOFTAP_SUPPORT
static int nxp_wifi_set_btwt(const struct device *dev, struct wifi_twt_params *params)
{
wlan_btwt_config_t btwt_config;
Expand All @@ -1593,6 +1702,7 @@ static int nxp_wifi_set_btwt(const struct device *dev, struct wifi_twt_params *p
return wlan_set_btwt_cfg(&btwt_config);
}
#endif
#endif

static int nxp_wifi_set_rts_threshold(const struct device *dev, unsigned int rts_threshold)
{
Expand All @@ -1609,6 +1719,7 @@ static int nxp_wifi_set_rts_threshold(const struct device *dev, unsigned int rts
return ret;
}

#ifdef CONFIG_NXP_WIFI_SOFTAP_SUPPORT
static int nxp_wifi_ap_set_rts_threshold(const struct device *dev, unsigned int rts_threshold)
{
int ret = -1;
Expand All @@ -1623,6 +1734,7 @@ static int nxp_wifi_ap_set_rts_threshold(const struct device *dev, unsigned int

return ret;
}
#endif

static void nxp_wifi_sta_init(struct net_if *iface)
{
Expand Down Expand Up @@ -1723,6 +1835,8 @@ static NXP_WIFI_SET_FUNC_ATTR int nxp_wifi_send(const struct device *dev, struct
if_handle->stats.multicast.tx++;
} else if (net_eth_is_addr_broadcast(&hdr->dst)) {
if_handle->stats.broadcast.tx++;
} else {
if_handle->stats.unicast.tx++;
}
#endif

Expand Down Expand Up @@ -1752,6 +1866,8 @@ static NXP_WIFI_SET_FUNC_ATTR int nxp_wifi_recv(struct net_if *iface, struct net
if_handle->stats.broadcast.rx++;
} else if (net_eth_is_addr_multicast(&hdr->dst)) {
if_handle->stats.multicast.rx++;
} else {
if_handle->stats.unicast.rx++;
}

if_handle->stats.bytes.received += pkt_len;
Expand Down Expand Up @@ -1917,6 +2033,7 @@ static const struct wifi_mgmt_ops nxp_wifi_sta_mgmt = {
.iface_status = nxp_wifi_status,
#if defined(CONFIG_NET_STATISTICS_WIFI)
.get_stats = nxp_wifi_stats,
.reset_stats = nxp_wifi_reset_stats,
#endif
#ifdef CONFIG_NXP_WIFI_11K
.cfg_11k = nxp_wifi_11k_cfg,
Expand Down Expand Up @@ -1999,6 +2116,7 @@ static const struct wifi_mgmt_ops nxp_wifi_uap_mgmt = {
.iface_status = nxp_wifi_uap_status,
#if defined(CONFIG_NET_STATISTICS_WIFI)
.get_stats = nxp_wifi_stats,
.reset_stats = nxp_wifi_reset_stats,
#endif
.set_power_save = nxp_wifi_power_save,
.get_power_save_config = nxp_wifi_get_power_save,
Expand Down
3 changes: 3 additions & 0 deletions drivers/wifi/nxp/nxp_wifi_drv.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
#define NXP_WIFI_SYNC_PS_GROUP \
NXP_WIFI_EVENT_BIT(WLAN_REASON_PS_ENTER) | NXP_WIFI_EVENT_BIT(WLAN_REASON_PS_EXIT)

#define NXP_WIFI_SAP_BEACON_PERIOD_DEFAULT 100
#define NXP_WIFI_SAP_DTIM_PERIOD_DEFAULT 1

enum nxp_wifi_ret {
NXP_WIFI_RET_SUCCESS,
NXP_WIFI_RET_FAIL,
Expand Down
2 changes: 0 additions & 2 deletions samples/net/wifi/shell/boards/frdm_rw612.conf
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ CONFIG_SHELL_CMD_BUFF_SIZE=512

# net
CONFIG_NET_L2_ETHERNET=y
CONFIG_NET_DHCPV4_SERVER_ADDR_COUNT=32
CONFIG_NET_IPV4=y
CONFIG_NET_IPV6=y
CONFIG_ETH_MCUX=n
Expand Down Expand Up @@ -63,7 +62,6 @@ CONFIG_NET_IPV6_FRAGMENT_MAX_COUNT=3
CONFIG_NET_IPV6_FRAGMENT_MAX_PKT=8
CONFIG_NET_IPV6_FRAGMENT_TIMEOUT=3
CONFIG_NET_MAX_CONN=10
CONFIG_NET_DHCPV4_SERVER_ICMP_PROBE_TIMEOUT=100
CONFIG_ETH_DRIVER=n

# net threads priority
Expand Down
3 changes: 0 additions & 3 deletions samples/net/wifi/shell/boards/overlay_hostap_rw612.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_MBEDTLS_PSA=y
CONFIG_WIFI_NM_WPA_SUPPLICANT_INF_MON=n
CONFIG_WIFI_NM_MAX_MANAGED_INTERFACES=2
CONFIG_SAE_PWE_EARLY_EXIT=y
CONFIG_WIFI_NM_HOSTAPD_AP=y
CONFIG_WIFI_NM_WPA_SUPPLICANT_WPS=y
CONFIG_WIFI_NM_HOSTAPD_WPS=y
CONFIG_WIFI_NM_HOSTAPD_CRYPTO_ENTERPRISE=y

# Enable mbedtls
CONFIG_MBEDTLS=y
Expand Down
2 changes: 0 additions & 2 deletions samples/net/wifi/shell/boards/rd_rw612_bga.conf
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ CONFIG_SHELL_CMD_BUFF_SIZE=512

# net
CONFIG_NET_L2_ETHERNET=y
CONFIG_NET_DHCPV4_SERVER_ADDR_COUNT=32
CONFIG_NET_IPV4=y
CONFIG_NET_IPV6=y
CONFIG_ETH_MCUX=n
Expand Down Expand Up @@ -63,7 +62,6 @@ CONFIG_NET_IPV6_FRAGMENT_MAX_COUNT=3
CONFIG_NET_IPV6_FRAGMENT_MAX_PKT=8
CONFIG_NET_IPV6_FRAGMENT_TIMEOUT=3
CONFIG_NET_MAX_CONN=10
CONFIG_NET_DHCPV4_SERVER_ICMP_PROBE_TIMEOUT=100

# net threads priority
CONFIG_NET_TC_THREAD_PRIO_CUSTOM=y
Expand Down
4 changes: 4 additions & 0 deletions soc/nxp/rw/Kconfig.defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,8 @@ config NXP_FW_LOADER
config NXP_RF_IMU
default y if (BT || WIFI || IEEE802154)

if WIFI
orsource "Kconfig.defconfig.wifi"
endif # WIFI

endif # SOC_SERIES_RW6XX
17 changes: 17 additions & 0 deletions soc/nxp/rw/Kconfig.defconfig.wifi
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2022-2025 NXP
# SPDX-License-Identifier: Apache-2.0

if NETWORKING
if NET_DHCPV4_SERVER
config NET_DHCPV4_SERVER_ADDR_COUNT
default 32

config NET_DHCPV4_SERVER_ICMP_PROBE_TIMEOUT
default 100
endif # NET_DHCPV4_SERVER

if NET_L2_WIFI_MGMT
config WIFI_MGMT_AP_MAX_NUM_STA
default 8 if NXP_WIFI_SOFTAP_SUPPORT
endif # NET_L2_WIFI_MGMT
endif # NETWORKING
Loading