From fd271144c9d29dffc0373757294777f126c7c39d Mon Sep 17 00:00:00 2001 From: Maochen Wang Date: Mon, 2 Sep 2024 12:27:52 +0800 Subject: [PATCH 001/299] [nrf fromtree] hostap: only add STA interface when hostapd enabled For add_interface(), only add STA interface when hostapd enabled, and the Soft-AP interface will be added in zephyr_hostapd_init(). Signed-off-by: Maochen Wang (cherry picked from commit e2f671ee004e6d89699ce45e2f7891b04b1aa73f) --- modules/hostap/src/supp_main.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/hostap/src/supp_main.c b/modules/hostap/src/supp_main.c index 8a7382c7b39..bff147df40e 100644 --- a/modules/hostap/src/supp_main.c +++ b/modules/hostap/src/supp_main.c @@ -508,6 +508,12 @@ static void iface_cb(struct net_if *iface, void *user_data) return; } +#ifdef CONFIG_WIFI_NM_HOSTAPD_AP + if (wifi_nm_iface_is_sap(iface)) { + return; + } +#endif + if (!net_if_is_admin_up(iface)) { return; } From 641848dfe6cb087060ee711400f52225e584cdf3 Mon Sep 17 00:00:00 2001 From: Gaofeng Zhang Date: Mon, 23 Sep 2024 11:35:11 +0800 Subject: [PATCH 002/299] [nrf fromtree] zephyr: hostap: fix eap secure mode print UNKNOWN wpas_key_mgmt_to_zephyr doesn't support eap secure mode, add code to support eap secure mode. Signed-off-by: Gaofeng Zhang (cherry picked from commit 94386e103ee230bd01965e4171ff6de2ddff4933) --- modules/hostap/src/supp_api.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/hostap/src/supp_api.c b/modules/hostap/src/supp_api.c index 049223b6956..703ca789f42 100644 --- a/modules/hostap/src/supp_api.c +++ b/modules/hostap/src/supp_api.c @@ -348,6 +348,10 @@ static inline int chan_to_freq(int chan) static inline enum wifi_frequency_bands wpas_band_to_zephyr(enum wpa_radio_work_band band) { switch (band) { + case WPA_KEY_MGMT_IEEE8021X: + case WPA_KEY_MGMT_IEEE8021X_SUITE_B: + case WPA_KEY_MGMT_IEEE8021X_SUITE_B_192: + return WIFI_SECURITY_TYPE_EAP_TLS; case BAND_2_4_GHZ: return WIFI_FREQ_BAND_2_4_GHZ; case BAND_5_GHZ: From 87618b47f985c2312ac4eeab26aadc966de99155 Mon Sep 17 00:00:00 2001 From: Gang Li Date: Fri, 20 Sep 2024 19:05:53 +0900 Subject: [PATCH 003/299] [nrf fromtree] hostap: add AP configuration cmd support Implement AP configuration parameter operations. Signed-off-by: Gang Li (cherry picked from commit 4bfdb643867bc23968166506d172736eed98ae68) --- modules/hostap/src/supp_api.c | 51 ++++++++++++++++++++++++++++++++++ modules/hostap/src/supp_api.h | 9 ++++++ modules/hostap/src/supp_main.c | 1 + 3 files changed, 61 insertions(+) diff --git a/modules/hostap/src/supp_api.c b/modules/hostap/src/supp_api.c index 703ca789f42..d7c3c60749a 100644 --- a/modules/hostap/src/supp_api.c +++ b/modules/hostap/src/supp_api.c @@ -1410,6 +1410,57 @@ int hapd_config_network(struct hostapd_iface *iface, out: return ret; } + +int supplicant_ap_config_params(const struct device *dev, struct wifi_ap_config_params *params) +{ + struct hostapd_iface *iface; + const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_mgmt_api(dev); + int ret = 0; + + if (params->type & WIFI_AP_CONFIG_PARAM_MAX_INACTIVITY) { + if (!wifi_mgmt_api || !wifi_mgmt_api->ap_config_params) { + wpa_printf(MSG_ERROR, "ap_config_params not supported"); + return -ENOTSUP; + } + + ret = wifi_mgmt_api->ap_config_params(dev, params); + if (ret) { + wpa_printf(MSG_ERROR, + "Failed to set maximum inactivity duration for stations"); + } else { + wpa_printf(MSG_INFO, "Set maximum inactivity duration for stations: %d (s)", + params->max_inactivity); + } + } + if (params->type & WIFI_AP_CONFIG_PARAM_MAX_NUM_STA) { + k_mutex_lock(&wpa_supplicant_mutex, K_FOREVER); + + iface = get_hostapd_handle(dev); + if (!iface) { + ret = -ENOENT; + wpa_printf(MSG_ERROR, "Interface %s not found", dev->name); + goto out; + } + + if (iface->state > HAPD_IFACE_DISABLED) { + ret = -EBUSY; + wpa_printf(MSG_ERROR, "Interface %s is not in disable state", dev->name); + goto out; + } + + if (!hostapd_cli_cmd_v("set max_num_sta %d", params->max_num_sta)) { + ret = -EINVAL; + wpa_printf(MSG_ERROR, "Failed to set maximum number of stations"); + goto out; + } + wpa_printf(MSG_INFO, "Set maximum number of stations: %d", params->max_num_sta); + +out: + k_mutex_unlock(&wpa_supplicant_mutex); + } + + return ret; +} #endif int supplicant_ap_enable(const struct device *dev, diff --git a/modules/hostap/src/supp_api.h b/modules/hostap/src/supp_api.h index dbef7b77796..9dc37cbd88a 100644 --- a/modules/hostap/src/supp_api.h +++ b/modules/hostap/src/supp_api.h @@ -225,6 +225,15 @@ int supplicant_get_wifi_conn_params(const struct device *dev, * @return 0 for OK; -1 for ERROR */ int hapd_state(const struct device *dev, int *state); + +/** + * @brief Wi-Fi AP configuration parameter. + * + * @param dev Wi-Fi device + * @param params AP parameters + * @return 0 for OK; -1 for ERROR + */ +int supplicant_ap_config_params(const struct device *dev, struct wifi_ap_config_params *params); #else static inline int hapd_state(const struct device *dev, int *state) { diff --git a/modules/hostap/src/supp_main.c b/modules/hostap/src/supp_main.c index bff147df40e..b696c7bc02a 100644 --- a/modules/hostap/src/supp_main.c +++ b/modules/hostap/src/supp_main.c @@ -101,6 +101,7 @@ static const struct wifi_mgmt_ops mgmt_ap_ops = { #ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP .dpp_dispatch = hapd_dpp_dispatch, #endif /* CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP */ + .ap_config_params = supplicant_ap_config_params, }; DEFINE_WIFI_NM_INSTANCE(hostapd, &mgmt_ap_ops); From d7fbdf9a07303f0b51fecd4aed50e5b9401cbdc1 Mon Sep 17 00:00:00 2001 From: Jukka Rissanen Date: Fri, 27 Sep 2024 21:32:47 +0300 Subject: [PATCH 004/299] [nrf fromtree] hostap: The security keys were checked in wrong function The security check case statements were in frequency band setting checks. This is totally wrong and will cause compiler warnings. Moving the checks to correct function. Signed-off-by: Jukka Rissanen (cherry picked from commit 2f47de60a0a7038eed1bfe11ced16ae51444434e) --- modules/hostap/src/supp_api.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/hostap/src/supp_api.c b/modules/hostap/src/supp_api.c index d7c3c60749a..58e2a3127aa 100644 --- a/modules/hostap/src/supp_api.c +++ b/modules/hostap/src/supp_api.c @@ -348,10 +348,6 @@ static inline int chan_to_freq(int chan) static inline enum wifi_frequency_bands wpas_band_to_zephyr(enum wpa_radio_work_band band) { switch (band) { - case WPA_KEY_MGMT_IEEE8021X: - case WPA_KEY_MGMT_IEEE8021X_SUITE_B: - case WPA_KEY_MGMT_IEEE8021X_SUITE_B_192: - return WIFI_SECURITY_TYPE_EAP_TLS; case BAND_2_4_GHZ: return WIFI_FREQ_BAND_2_4_GHZ; case BAND_5_GHZ: @@ -364,6 +360,10 @@ static inline enum wifi_frequency_bands wpas_band_to_zephyr(enum wpa_radio_work_ static inline enum wifi_security_type wpas_key_mgmt_to_zephyr(int key_mgmt, int proto) { switch (key_mgmt) { + case WPA_KEY_MGMT_IEEE8021X: + case WPA_KEY_MGMT_IEEE8021X_SUITE_B: + case WPA_KEY_MGMT_IEEE8021X_SUITE_B_192: + return WIFI_SECURITY_TYPE_EAP_TLS; case WPA_KEY_MGMT_NONE: return WIFI_SECURITY_TYPE_NONE; case WPA_KEY_MGMT_PSK: From 563c136986ede47eddb2506001a5149233e14b8a Mon Sep 17 00:00:00 2001 From: Rex Chen Date: Sun, 29 Sep 2024 18:30:00 +0900 Subject: [PATCH 005/299] [nrf fromtree] net: wifi: shell: add reg domain support Supp api add reg domain support. Signed-off-by: Rex Chen (cherry picked from commit 5a195001e393fcfbb48111f8376e45b2bb63b233) --- modules/hostap/src/supp_api.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/modules/hostap/src/supp_api.c b/modules/hostap/src/supp_api.c index 58e2a3127aa..542ba57b235 100644 --- a/modules/hostap/src/supp_api.c +++ b/modules/hostap/src/supp_api.c @@ -1141,13 +1141,44 @@ int supplicant_reg_domain(const struct device *dev, struct wifi_reg_domain *reg_domain) { const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_mgmt_api(dev); + struct wpa_supplicant *wpa_s; + int ret = -1; if (!wifi_mgmt_api || !wifi_mgmt_api->reg_domain) { wpa_printf(MSG_ERROR, "Regulatory domain not supported"); return -ENOTSUP; } - return wifi_mgmt_api->reg_domain(dev, reg_domain); + if (reg_domain->oper == WIFI_MGMT_GET) { + return wifi_mgmt_api->reg_domain(dev, reg_domain); + } + + if (reg_domain->oper == WIFI_MGMT_SET) { + k_mutex_lock(&wpa_supplicant_mutex, K_FOREVER); + + wpa_s = get_wpa_s_handle(dev); + if (!wpa_s) { + wpa_printf(MSG_ERROR, "Interface %s not found", dev->name); + goto out; + } + + if (!wpa_cli_cmd_v("set country %s", reg_domain->country_code)) { + goto out; + } + +#ifdef CONFIG_WIFI_NM_HOSTAPD_AP + if (!hostapd_cli_cmd_v("set country_code %s", reg_domain->country_code)) { + goto out; + } +#endif + + ret = 0; + +out: + k_mutex_unlock(&wpa_supplicant_mutex); + } + + return ret; } int supplicant_mode(const struct device *dev, struct wifi_mode_info *mode) From 883a02fbb19bf296fbf2fe25c8ec2f278cc81f83 Mon Sep 17 00:00:00 2001 From: Jukka Rissanen Date: Wed, 25 Sep 2024 14:18:47 +0300 Subject: [PATCH 006/299] [nrf fromtree] hostap: Use proper value when generating supplicant event The previous NET_EVENT_SUPPLICANT_CMD_INT_EVENT is from "enum net_event_supplicant_cmd" but the supplicant_send_wifi_mgmt_event() has the event parameter as an "enum net_event_wifi_cmd" and those event number spaces are different. This meant that the wrong event value NET_EVENT_SUPPLICANT_CMD_INT_EVENT maps to NET_EVENT_WIFI_CMD_TWT (from "enum net_event_wifi_cmd") which fortunately did not cause issue in this case because the supplicant_send_wifi_mgmt_event() has no handling for this TWT event value. It is important we fix this as this can cause great confusion in the future. Signed-off-by: Jukka Rissanen (cherry picked from commit 4b83b2346fe1d3845a10cd47e449dd3418b82952) --- include/zephyr/net/wifi_mgmt.h | 2 ++ modules/hostap/src/supp_events.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/include/zephyr/net/wifi_mgmt.h b/include/zephyr/net/wifi_mgmt.h index 899cb2f095b..68650dd9319 100644 --- a/include/zephyr/net/wifi_mgmt.h +++ b/include/zephyr/net/wifi_mgmt.h @@ -282,6 +282,8 @@ enum net_event_wifi_cmd { NET_EVENT_WIFI_CMD_AP_STA_CONNECTED, /** STA disconnected from AP */ NET_EVENT_WIFI_CMD_AP_STA_DISCONNECTED, + /** Supplicant specific event */ + NET_EVENT_WIFI_CMD_SUPPLICANT, }; /** Event emitted for Wi-Fi scan result */ diff --git a/modules/hostap/src/supp_events.c b/modules/hostap/src/supp_events.c index 617779b4d44..9ac472b6bdb 100644 --- a/modules/hostap/src/supp_events.c +++ b/modules/hostap/src/supp_events.c @@ -386,7 +386,7 @@ int supplicant_send_wifi_mgmt_event(const char *ifname, enum net_event_wifi_cmd (struct wifi_ap_sta_info *)supplicant_status); break; #endif /* CONFIG_AP */ - case NET_EVENT_SUPPLICANT_CMD_INT_EVENT: + case NET_EVENT_WIFI_CMD_SUPPLICANT: event_data.data = &data; if (supplicant_process_status(&event_data, (char *)supplicant_status) > 0) { net_mgmt_event_notify_with_info(NET_EVENT_SUPPLICANT_INT_EVENT, From ddddfdd85d13afcce81137c1fdaa270ad08c6b0d Mon Sep 17 00:00:00 2001 From: Fengming Ye Date: Fri, 27 Sep 2024 12:07:12 +0900 Subject: [PATCH 007/299] [nrf fromtree] hostap: add crypto module test kconfig option Add crypto module test kconfig option CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_TEST, which is default n and hidden. It is only available by developer for crypto module test. Signed-off-by: Fengming Ye (cherry picked from commit e40eef2d58d4355b0b9978228240d712de6d956c) --- modules/hostap/CMakeLists.txt | 7 +++++++ modules/hostap/Kconfig | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/modules/hostap/CMakeLists.txt b/modules/hostap/CMakeLists.txt index 6d6d61cfef4..931e368e6e6 100644 --- a/modules/hostap/CMakeLists.txt +++ b/modules/hostap/CMakeLists.txt @@ -504,6 +504,13 @@ zephyr_library_sources_ifdef(CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE ${HOSTAP_SRC_BASE}/crypto/fips_prf_internal.c ${HOSTAP_SRC_BASE}/crypto/milenage.c ) + +zephyr_library_sources_ifdef(CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_TEST + ${HOSTAP_SRC_BASE}/crypto/crypto_module_tests.c + ${HOSTAP_SRC_BASE}/crypto/fips_prf_internal.c + ${HOSTAP_SRC_BASE}/crypto/sha1-internal.c + ${HOSTAP_SRC_BASE}/crypto/sha1-tlsprf.c +) endif() zephyr_library_link_libraries_ifndef(CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_NONE diff --git a/modules/hostap/Kconfig b/modules/hostap/Kconfig index b329cd2e4f0..d49dc6a29a0 100644 --- a/modules/hostap/Kconfig +++ b/modules/hostap/Kconfig @@ -533,4 +533,8 @@ config SAE_PWE_EARLY_EXIT this can be intensive, so, add an option to exit early. Note that this is highly insecure and shouldn't be used in production +config WIFI_NM_WPA_SUPPLICANT_CRYPTO_TEST + bool + depends on WIFI_NM_WPA_SUPPLICANT_CRYPTO_MBEDTLS_PSA + endif # WIFI_NM_WPA_SUPPLICANT From d00ea9274c38e238b4bf2714d7fa4883746165de Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Mon, 7 Oct 2024 01:22:04 +0530 Subject: [PATCH 008/299] [nrf fromtree] modules: hostap: Use OS primitive even in native code This was we can modify it in a single place that works both for native and OS specific code. Signed-off-by: Chaitanya Tata (cherry picked from commit bcef9ac6eab222526644fa9257420e4ee7fb8f59) --- modules/hostap/src/supp_api.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/hostap/src/supp_api.c b/modules/hostap/src/supp_api.c index 542ba57b235..875d2d72949 100644 --- a/modules/hostap/src/supp_api.c +++ b/modules/hostap/src/supp_api.c @@ -269,7 +269,7 @@ static int wpa_supp_supported_channels(struct wpa_supplicant *wpa_s, uint8_t ban } size = ((mode->num_channels) * CHAN_NUM_LEN) + 1; - _chan_list = k_malloc(size); + _chan_list = os_malloc(size); if (!_chan_list) { wpa_printf(MSG_ERROR, "Mem alloc failed for channel list"); return -ENOMEM; @@ -500,11 +500,11 @@ static int wpas_add_and_config_network(struct wpa_supplicant *wpa_s, if (chan_list) { if (!wpa_cli_cmd_v("set_network %d scan_freq%s", resp.network_id, chan_list)) { - k_free(chan_list); + os_free(chan_list); goto out; } - k_free(chan_list); + os_free(chan_list); } } From 4f541cf957db93675cfd14969b1defbb8d51096e Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Mon, 7 Oct 2024 01:37:49 +0530 Subject: [PATCH 009/299] [nrf fromtree] modules: hostap: Fix heap pool allocation Now that hostap is used k_heap, it needs to reserve the kernel heap not libc heap. Fixes #79477. Signed-off-by: Chaitanya Tata (cherry picked from commit 3ade4bed2749d2096bba293b8869c057adaf55a6) --- modules/hostap/Kconfig | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/hostap/Kconfig b/modules/hostap/Kconfig index d49dc6a29a0..60770bed61d 100644 --- a/modules/hostap/Kconfig +++ b/modules/hostap/Kconfig @@ -23,13 +23,13 @@ config WIFI_NM_WPA_SUPPLICANT if WIFI_NM_WPA_SUPPLICANT -config COMMON_LIBC_MALLOC_ARENA_SIZE - default 85000 if WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE && !MBEDTLS_ENABLE_HEAP - default 40000 if WIFI_NM_WPA_SUPPLICANT_AP +config HEAP_MEM_POOL_ADD_SIZE_HOSTAP + def_int 85000 if WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE && !MBEDTLS_ENABLE_HEAP + def_int 40000 if WIFI_NM_WPA_SUPPLICANT_AP # 8192 for MbedTLS heap - default 21808 if MBEDTLS_ENABLE_HEAP + def_int 21808 if MBEDTLS_ENABLE_HEAP # 30K is mandatory, but might need more for long duration use cases - default 30000 + def_int 30000 config WIFI_NM_WPA_SUPPLICANT_THREAD_STACK_SIZE int "Stack size for wpa_supplicant thread" From 4ad5c6f61adbc78b33b13848d52a5ef429ace545 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Mon, 7 Oct 2024 01:57:24 +0530 Subject: [PATCH 010/299] [nrf fromtree] modules: hostap: Add missing default for max STAs in AP mode The default should honor the build time flag. Signed-off-by: Chaitanya Tata (cherry picked from commit b2c6f6c53b1bf1df66434b8ae0a37502b093ba5b) --- modules/hostap/src/supp_api.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/hostap/src/supp_api.c b/modules/hostap/src/supp_api.c index 875d2d72949..a19747575fb 100644 --- a/modules/hostap/src/supp_api.c +++ b/modules/hostap/src/supp_api.c @@ -1575,6 +1575,8 @@ int supplicant_ap_enable(const struct device *dev, /* No need to check for existing network to join for SoftAP*/ wpa_s->conf->ap_scan = 2; + /* Set BSS parameter max_num_sta to default configured value */ + wpa_s->conf->max_num_sta = CONFIG_WIFI_MGMT_AP_MAX_NUM_STA; ret = wpas_add_and_config_network(wpa_s, params, true); if (ret) { From 0823505894675507c3a18ec1140aaa42de6a9ce2 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Mon, 7 Oct 2024 01:58:10 +0530 Subject: [PATCH 011/299] [nrf fromtree] modules: hostap: Use the build time flag Instead of hard-coded value, use the build time flag. Signed-off-by: Chaitanya Tata (cherry picked from commit 970428419cfdf7a1c836528a44fe006121080064) --- modules/hostap/src/supp_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/hostap/src/supp_main.c b/modules/hostap/src/supp_main.c index b696c7bc02a..b111f43a4e8 100644 --- a/modules/hostap/src/supp_main.c +++ b/modules/hostap/src/supp_main.c @@ -873,7 +873,7 @@ struct hostapd_config *hostapd_config_read2(const char *fname) bss = conf->last_bss; bss->start_disabled = 1; - bss->max_num_sta = 8; + bss->max_num_sta = CONFIG_WIFI_MGMT_AP_MAX_NUM_STA; bss->dtim_period = 1; os_strlcpy(conf->bss[0]->iface, ifname, sizeof(conf->bss[0]->iface)); bss->logger_stdout_level = HOSTAPD_LEVEL_INFO; From 025a9c20f245acefbd76b3f4285c110e922e02bd Mon Sep 17 00:00:00 2001 From: Maochen Wang Date: Tue, 8 Oct 2024 17:19:56 +0800 Subject: [PATCH 012/299] [nrf fromtree] hostap: fix other STA failed to connect to SAP The format of wpa_passphrase and sae_password is wrong when start the SAP, which leads the invaild MIC check error when other STA try to connect in security mode. Change the wrong format can fix this issue. Signed-off-by: Maochen Wang (cherry picked from commit 838ff13fe2d6e0ec7e289efd7908d429e6e57d23) --- modules/hostap/src/supp_api.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/hostap/src/supp_api.c b/modules/hostap/src/supp_api.c index a19747575fb..3d79fab1eb1 100644 --- a/modules/hostap/src/supp_api.c +++ b/modules/hostap/src/supp_api.c @@ -1357,7 +1357,7 @@ int hapd_config_network(struct hostapd_iface *iface, if (!hostapd_cli_cmd_v("set wpa_key_mgmt WPA-PSK")) { goto out; } - if (!hostapd_cli_cmd_v("set wpa_passphrase \"%s\"", params->psk)) { + if (!hostapd_cli_cmd_v("set wpa_passphrase %s", params->psk)) { goto out; } if (!hostapd_cli_cmd_v("set wpa_pairwise CCMP")) { @@ -1370,7 +1370,7 @@ int hapd_config_network(struct hostapd_iface *iface, if (!hostapd_cli_cmd_v("set wpa_key_mgmt WPA-PSK")) { goto out; } - if (!hostapd_cli_cmd_v("set wpa_passphrase \"%s\"", params->psk)) { + if (!hostapd_cli_cmd_v("set wpa_passphrase %s", params->psk)) { goto out; } if (!hostapd_cli_cmd_v("set rsn_pairwise CCMP")) { @@ -1383,7 +1383,7 @@ int hapd_config_network(struct hostapd_iface *iface, if (!hostapd_cli_cmd_v("set wpa_key_mgmt WPA-PSK-SHA256")) { goto out; } - if (!hostapd_cli_cmd_v("set wpa_passphrase \"%s\"", params->psk)) { + if (!hostapd_cli_cmd_v("set wpa_passphrase %s", params->psk)) { goto out; } if (!hostapd_cli_cmd_v("set rsn_pairwise CCMP")) { @@ -1396,7 +1396,7 @@ int hapd_config_network(struct hostapd_iface *iface, if (!hostapd_cli_cmd_v("set wpa_key_mgmt SAE")) { goto out; } - if (!hostapd_cli_cmd_v("set sae_password \"%s\"", + if (!hostapd_cli_cmd_v("set sae_password %s", params->sae_password ? params->sae_password : params->psk)) { goto out; From 51c09bbcd9e0dae8823eb7888c7410bef0a51eb2 Mon Sep 17 00:00:00 2001 From: Gang Li Date: Fri, 20 Sep 2024 15:54:45 +0900 Subject: [PATCH 013/299] [nrf fromtree] hostap: add WPA-Auto-Personal(WPA2/WPA3 mixed) support Add WPA-Auto-Personal support for AP and STA. This mode uses WPA2/WPA3 SAE mixed security with PSK. Signed-off-by: Gang Li (cherry picked from commit 79222c9c11f69c879de295477db6a811de6c2497) --- modules/hostap/src/supp_api.c | 53 ++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/modules/hostap/src/supp_api.c b/modules/hostap/src/supp_api.c index 3d79fab1eb1..e3efd8c9bf8 100644 --- a/modules/hostap/src/supp_api.c +++ b/modules/hostap/src/supp_api.c @@ -603,6 +603,32 @@ static int wpas_add_and_config_network(struct wpa_supplicant *wpa_s, goto out; } } + } else if (params->security == WIFI_SECURITY_TYPE_WPA_AUTO_PERSONAL) { + if (!wpa_cli_cmd_v("set_network %d psk \"%s\"", resp.network_id, + psk_null_terminated)) { + goto out; + } + + if (params->sae_password) { + if (!wpa_cli_cmd_v("set_network %d sae_password \"%s\"", + resp.network_id, sae_null_terminated)) { + goto out; + } + } else { + if (!wpa_cli_cmd_v("set_network %d sae_password \"%s\"", + resp.network_id, psk_null_terminated)) { + goto out; + } + } + + if (!wpa_cli_cmd_v("set sae_pwe 2")) { + goto out; + } + + if (!wpa_cli_cmd_v("set_network %d key_mgmt WPA-PSK SAE", + resp.network_id)) { + goto out; + } #ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE } else if (params->security == WIFI_SECURITY_TYPE_EAP_TLS) { if (!wpa_cli_cmd_v("set_network %d key_mgmt WPA-EAP", @@ -1407,7 +1433,32 @@ int hapd_config_network(struct hostapd_iface *iface, if (!hostapd_cli_cmd_v("set sae_pwe 2")) { goto out; } - iface->bss[0]->conf->sae_pwe = 2; + } else if (params->security == WIFI_SECURITY_TYPE_WPA_AUTO_PERSONAL) { + if (!hostapd_cli_cmd_v("set wpa 2")) { + goto out; + } + + if (!hostapd_cli_cmd_v("set wpa_key_mgmt WPA-PSK SAE")) { + goto out; + } + + if (!hostapd_cli_cmd_v("set wpa_passphrase \"%s\"", params->psk)) { + goto out; + } + + if (!hostapd_cli_cmd_v("set sae_password \"%s\"", + params->sae_password ? params->sae_password + : params->psk)) { + goto out; + } + + if (!hostapd_cli_cmd_v("set rsn_pairwise CCMP")) { + goto out; + } + + if (!hostapd_cli_cmd_v("set sae_pwe 2")) { + goto out; + } } else if (params->security == WIFI_SECURITY_TYPE_DPP) { if (!hostapd_cli_cmd_v("set wpa 2")) { goto out; From c8c1eed9ff46877b1234cbea87010b1b0576ad77 Mon Sep 17 00:00:00 2001 From: Ravi Dondaputi Date: Thu, 10 Oct 2024 13:15:32 +0530 Subject: [PATCH 014/299] [nrf fromtree] modules: hostap: Add config options for EAP types Enabling all EAP types for enterprise mode increases memory usage in both ROM and RAM. Provide config options for each type to let solutions choose the methods based on their requirements. Signed-off-by: Ravi Dondaputi (cherry picked from commit 609520bf3fbf5fa20a4941eb253b1eb6903e60ad) --- modules/hostap/CMakeLists.txt | 133 +++++++++++++++++++++++++++------ modules/hostap/Kconfig | 50 +++++++++++++ modules/hostap/src/supp_main.h | 30 ++++++++ 3 files changed, 191 insertions(+), 22 deletions(-) diff --git a/modules/hostap/CMakeLists.txt b/modules/hostap/CMakeLists.txt index 931e368e6e6..095c7c6dd23 100644 --- a/modules/hostap/CMakeLists.txt +++ b/modules/hostap/CMakeLists.txt @@ -323,68 +323,157 @@ zephyr_library_compile_definitions_ifdef(CONFIG_WIFI_NM_WPA_SUPPLICANT_WPS ) zephyr_library_sources_ifdef(CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE + ${HOSTAP_SRC_BASE}/eap_common/eap_common.c +) + +zephyr_library_compile_definitions_ifdef(CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE + IEEE8021X_EAPOL + EAP_IKEv2 +) + +zephyr_library_sources_ifdef(CONFIG_EAP_TLS ${HOSTAP_SRC_BASE}/eap_peer/eap_tls.c ${HOSTAP_SRC_BASE}/eap_peer/eap_tls_common.c - ${HOSTAP_SRC_BASE}/eap_common/eap_common.c +) + +zephyr_library_compile_definitions_ifdef(CONFIG_EAP_TLS + EAP_TLS +) + +zephyr_library_sources_ifdef(CONFIG_EAP_TTLS + ${HOSTAP_SRC_BASE}/eap_peer/eap_ttls.c +) + +zephyr_library_compile_definitions_ifdef(CONFIG_EAP_TTLS + EAP_TTLS +) +zephyr_library_sources_ifdef(CONFIG_EAP_PEAP ${HOSTAP_SRC_BASE}/eap_peer/eap_peap.c ${HOSTAP_SRC_BASE}/eap_common/eap_peap_common.c - ${HOSTAP_SRC_BASE}/eap_peer/eap_ttls.c +) + +zephyr_library_compile_definitions_ifdef(CONFIG_EAP_PEAP + EAP_PEAP +) + +zephyr_library_sources_ifdef(CONFIG_EAP_MD5 ${HOSTAP_SRC_BASE}/eap_peer/eap_md5.c +) + +zephyr_library_compile_definitions_ifdef(CONFIG_EAP_MD5 + EAP_MD5 +) + +zephyr_library_sources_ifdef(CONFIG_EAP_MSCHAPV2 ${HOSTAP_SRC_BASE}/eap_peer/eap_mschapv2.c - ${HOSTAP_SRC_BASE}/eap_common/chap.c ${HOSTAP_SRC_BASE}/eap_peer/mschapv2.c + ${HOSTAP_SRC_BASE}/eap_common/chap.c +) + +zephyr_library_compile_definitions_ifdef(CONFIG_EAP_MSCHAPV2 + EAP_MSCHAPv2 +) + +zephyr_library_sources_ifdef(CONFIG_EAP_LEAP ${HOSTAP_SRC_BASE}/eap_peer/eap_leap.c +) +zephyr_library_compile_definitions_ifdef(CONFIG_EAP_LEAP + EAP_LEAP +) + +zephyr_library_sources_ifdef(CONFIG_EAP_PSK ${HOSTAP_SRC_BASE}/eap_peer/eap_psk.c ${HOSTAP_SRC_BASE}/eap_common/eap_psk_common.c +) - ${HOSTAP_SRC_BASE}/eap_peer/eap_fast.c - ${HOSTAP_SRC_BASE}/eap_peer/eap_fast_pac.c - ${HOSTAP_SRC_BASE}/eap_common/eap_fast_common.c +zephyr_library_compile_definitions_ifdef(CONFIG_EAP_PSK + EAP_PSK +) +zephyr_library_sources_ifdef(CONFIG_EAP_PAX ${HOSTAP_SRC_BASE}/eap_peer/eap_pax.c ${HOSTAP_SRC_BASE}/eap_common/eap_pax_common.c +) +zephyr_library_compile_definitions_ifdef(CONFIG_EAP_PAX + EAP_PAX +) + +zephyr_library_sources_ifdef(CONFIG_EAP_SAKE ${HOSTAP_SRC_BASE}/eap_peer/eap_sake.c ${HOSTAP_SRC_BASE}/eap_common/eap_sake_common.c +) +zephyr_library_compile_definitions_ifdef(CONFIG_EAP_SAKE + EAP_SAKE +) + +zephyr_library_sources_ifdef(CONFIG_EAP_GPSK ${HOSTAP_SRC_BASE}/eap_peer/eap_gpsk.c ${HOSTAP_SRC_BASE}/eap_common/eap_gpsk_common.c +) + +zephyr_library_compile_definitions_ifdef(CONFIG_EAP_GPSK + EAP_GPSK +) +zephyr_library_sources_ifdef(CONFIG_EAP_PWD ${HOSTAP_SRC_BASE}/eap_peer/eap_pwd.c ${HOSTAP_SRC_BASE}/eap_common/eap_pwd_common.c +) + +zephyr_library_compile_definitions_ifdef(CONFIG_EAP_PWD + EAP_PWD +) +zephyr_library_sources_ifdef(CONFIG_EAP_EKE ${HOSTAP_SRC_BASE}/eap_peer/eap_eke.c ${HOSTAP_SRC_BASE}/eap_common/eap_eke_common.c +) +zephyr_library_compile_definitions_ifdef(CONFIG_EAP_EKE + EAP_EKE +) + +zephyr_library_sources_ifdef(CONFIG_EAP_IKEV2 ${HOSTAP_SRC_BASE}/eap_peer/eap_ikev2.c ${HOSTAP_SRC_BASE}/eap_peer/ikev2.c ${HOSTAP_SRC_BASE}/eap_common/eap_ikev2_common.c ${HOSTAP_SRC_BASE}/eap_common/ikev2_common.c +) + +zephyr_library_compile_definitions_ifdef(CONFIG_EAP_IKEV2 + EAP_IKEV2 +) +zephyr_library_sources_ifdef(CONFIG_EAP_SIM ${HOSTAP_SRC_BASE}/eap_peer/eap_sim.c ${HOSTAP_SRC_BASE}/eap_common/eap_sim_common.c +) + +zephyr_library_compile_definitions_ifdef(CONFIG_EAP_SIM + EAP_SIM +) +zephyr_library_sources_ifdef(CONFIG_EAP_AKA ${HOSTAP_SRC_BASE}/eap_peer/eap_aka.c ) -zephyr_library_compile_definitions_ifdef(CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE - EAP_TLS - IEEE8021X_EAPOL - EAP_PEAP - EAP_TTLS - EAP_MD5 - EAP_MSCHAPv2 - EAP_LEAP - EAP_PSK - EAP_FAST - EAP_PAX - EAP_SAKE - EAP_GPSK - EAP_PWD - EAP_EKE - EAP_IKEv2 +zephyr_library_compile_definitions_ifdef(CONFIG_EAP_AKA + EAP_AKA +) + +# Needs TLS1.3 and SESSION_TICKETS +zephyr_library_sources_ifdef(CONFIG_EAP_FAST + ${HOSTAP_SRC_BASE}/eap_peer/eap_fast.c + ${HOSTAP_SRC_BASE}/eap_peer/eap_fast_pac.c + ${HOSTAP_SRC_BASE}/eap_common/eap_fast_common.c +) + +zephyr_library_compile_definitions_ifdef(CONFIG_EAP_FAST + EAP_FAST ) zephyr_library_compile_definitions_ifndef(CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE diff --git a/modules/hostap/Kconfig b/modules/hostap/Kconfig index 60770bed61d..3886df79c48 100644 --- a/modules/hostap/Kconfig +++ b/modules/hostap/Kconfig @@ -226,6 +226,56 @@ config WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE select MBEDTLS_PEM_CERTIFICATE_FORMAT depends on !WIFI_NM_WPA_SUPPLICANT_CRYPTO_NONE +config EAP_TLS + bool "EAP-TLS support" + +config EAP_TTLS + bool "EAP-TTLS support" + +config EAP_PEAP + bool "EAP-PEAP support" + +config EAP_MD5 + bool "EAP-MD5 support" + +config EAP_MSCHAPV2 + bool "EAP-MSCHAPv2 support" + +config EAP_LEAP + bool "EAP-LEAP support" + +config EAP_PSK + bool "EAP-PSK support" + +config EAP_PAX + bool "EAP-PAX support" + +config EAP_SAKE + bool "EAP-SAKE support" + +config EAP_GPSK + bool "EAP-GPSK support" + +config EAP_PWD + bool "EAP-PWD support" + +config EAP_EKE + bool "EAP-EKE support" + +config EAP_IKEV2 + bool "EAP-IKEv2 support" + +config EAP_SIM + bool "EAP-SIM support" + +config EAP_AKA + bool "EAP-AKA support" + +config EAP_ALL + bool "All EAP methods support" + select EAP_TLS + default y if WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE + config WIFI_NM_WPA_SUPPLICANT_WPA3 bool "WPA3 support" depends on !WIFI_NM_WPA_SUPPLICANT_CRYPTO_NONE diff --git a/modules/hostap/src/supp_main.h b/modules/hostap/src/supp_main.h index 03f7461555e..7137d281929 100644 --- a/modules/hostap/src/supp_main.h +++ b/modules/hostap/src/supp_main.h @@ -6,6 +6,36 @@ #ifndef __SUPP_MAIN_H_ #define __SUPP_MAIN_H_ +#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE +/* At least one of the EAP methods need to be enabled in enterprise mode */ +#if !defined(CONFIG_EAP_TLS) && !defined(CONFIG_EAP_TTLS) && \ + !defined(CONFIG_EAP_PEAP) && !defined(CONFIG_EAP_FAST) && \ + !defined(CONFIG_EAP_SIM) && !defined(CONFIG_EAP_AKA) && \ + !defined(CONFIG_EAP_MD5) && !defined(CONFIG_EAP_MSCHAPV2) && \ + !defined(CONFIG_EAP_PSK) && !defined(CONFIG_EAP_PAX) && \ + !defined(CONFIG_EAP_SAKE) && !defined(CONFIG_EAP_GPSK) && \ + !defined(CONFIG_EAP_PWD) && !defined(CONFIG_EAP_EKE) && \ + !defined(CONFIG_EAP_IKEV2) +#error "At least one of the following EAP methods need to be defined \ + CONFIG_EAP_TLS \ + CONFIG_EAP_TTLS \ + CONFIG_EAP_PEAP \ + CONFIG_EAP_MD5 \ + CONFIG_EAP_MSCHAPV2 \ + CONFIG_EAP_LEAP \ + CONFIG_EAP_PSK \ + CONFIG_EAP_PAX \ + CONFIG_EAP_SAKE \ + CONFIG_EAP_GPSK \ + CONFIG_EAP_PWD \ + CONFIG_EAP_EKE \ + CONFIG_EAP_IKEV2 \ + CONFIG_EAP_SIM \ + CONFIG_EAP_AKA \ + CONFIG_EAP_ALL " +#endif /* EAP METHODS */ +#endif /* CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE */ + #if !defined(CONFIG_NET_DHCPV4) static inline void net_dhcpv4_start(struct net_if *iface) { From 4206c05b44adaa87d16e2de4f1238f264dc648f2 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Thu, 19 Sep 2024 17:13:35 +0530 Subject: [PATCH 015/299] [nrf fromtree] modules: hostap: Add separate config for EAP-FAST EAP-FAST has extra requirements (TLS 1.3, session tickets etc) and is seldom used, so, remove it from Enterprise list and add a separate Kconfig option. This solves the build error when Enterprise mode is enabled. Signed-off-by: Chaitanya Tata (cherry picked from commit 39b904d9cc6cb40013a8a5ff75cd8053eeed8889) --- modules/hostap/CMakeLists.txt | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/modules/hostap/CMakeLists.txt b/modules/hostap/CMakeLists.txt index 095c7c6dd23..bdbb845dc4b 100644 --- a/modules/hostap/CMakeLists.txt +++ b/modules/hostap/CMakeLists.txt @@ -476,6 +476,17 @@ zephyr_library_compile_definitions_ifdef(CONFIG_EAP_FAST EAP_FAST ) +# Needs TLS1.3 and SESSION_TICKETS +zephyr_library_sources_ifdef(CONFIG_EAP_FAST + ${HOSTAP_SRC_BASE}/eap_peer/eap_fast.c + ${HOSTAP_SRC_BASE}/eap_peer/eap_fast_pac.c + ${HOSTAP_SRC_BASE}/eap_common/eap_fast_common.c +) + +zephyr_library_compile_definitions_ifdef(CONFIG_EAP_FAST + EAP_FAST +) + zephyr_library_compile_definitions_ifndef(CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE CONFIG_NO_CONFIG_BLOBS ) From 9ee4f0a2d98fd072487704ba6202e0d08b2f70ac Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Fri, 20 Sep 2024 00:16:50 +0530 Subject: [PATCH 016/299] [nrf fromtree] modules: hostap: Fix checks for Enterprise security Enterprise security doesn't have either SAE or PSK, so, using a blanker else throws a false warning. Fix the checks to proper handler enterprise mode. Signed-off-by: Chaitanya Tata (cherry picked from commit 48916d66e7d35022525e7e05e7b0b7d99a104809) --- modules/hostap/src/supp_api.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/modules/hostap/src/supp_api.c b/modules/hostap/src/supp_api.c index e3efd8c9bf8..46de2917acf 100644 --- a/modules/hostap/src/supp_api.c +++ b/modules/hostap/src/supp_api.c @@ -509,17 +509,7 @@ static int wpas_add_and_config_network(struct wpa_supplicant *wpa_s, } if (params->security != WIFI_SECURITY_TYPE_NONE) { - if (params->sae_password) { - if ((params->sae_password_length < WIFI_PSK_MIN_LEN) || - (params->sae_password_length > WIFI_SAE_PSWD_MAX_LEN)) { - wpa_printf(MSG_ERROR, - "Passphrase should be in range (%d-%d) characters", - WIFI_PSK_MIN_LEN, WIFI_SAE_PSWD_MAX_LEN); - goto out; - } - strncpy(sae_null_terminated, params->sae_password, WIFI_SAE_PSWD_MAX_LEN); - sae_null_terminated[params->sae_password_length] = '\0'; - } else { + if (params->psk) { if ((params->psk_length < WIFI_PSK_MIN_LEN) || (params->psk_length > WIFI_PSK_MAX_LEN)) { wpa_printf(MSG_ERROR, @@ -551,6 +541,16 @@ static int wpas_add_and_config_network(struct wpa_supplicant *wpa_s, params->security == WIFI_SECURITY_TYPE_SAE_H2E || params->security == WIFI_SECURITY_TYPE_SAE_AUTO) { if (params->sae_password) { + if ((params->sae_password_length < WIFI_PSK_MIN_LEN) || + (params->sae_password_length > WIFI_SAE_PSWD_MAX_LEN)) { + wpa_printf(MSG_ERROR, + "Passphrase should be in range (%d-%d) characters", + WIFI_PSK_MIN_LEN, WIFI_SAE_PSWD_MAX_LEN); + goto out; + } + strncpy(sae_null_terminated, params->sae_password, + WIFI_SAE_PSWD_MAX_LEN); + sae_null_terminated[params->sae_password_length] = '\0'; if (!wpa_cli_cmd_v("set_network %d sae_password \"%s\"", resp.network_id, sae_null_terminated)) { goto out; From b0c28c01602e24220c244786cb9093df80f4a4a7 Mon Sep 17 00:00:00 2001 From: Maochen Wang Date: Tue, 15 Oct 2024 16:02:20 +0800 Subject: [PATCH 017/299] [nrf fromtree] hostap: fix DUT hang when start SAP on wrong channel When try to start SAP on channel 12 with region code US, the channel check will fail and calls supplicant_send_wifi_mgmt_ap_status() with iface->owner is NULL, which causes DUT hang. Set iface->owner when enable the SAP can fix this issue. Signed-off-by: Maochen Wang (cherry picked from commit a2599007202c3c5682aeebb742177ccf8b0b6ee1) --- modules/hostap/src/supp_api.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/hostap/src/supp_api.c b/modules/hostap/src/supp_api.c index 46de2917acf..e39e358393a 100644 --- a/modules/hostap/src/supp_api.c +++ b/modules/hostap/src/supp_api.c @@ -1574,6 +1574,8 @@ int supplicant_ap_enable(const struct device *dev, goto out; } + iface->owner = iface; + if (iface->state == HAPD_IFACE_ENABLED) { ret = -EBUSY; wpa_printf(MSG_ERROR, "Interface %s is not in disable state", dev->name); From 0e8c6cf6e3ce1ea7212c359a205b1f150024551a Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Tue, 8 Oct 2024 21:42:26 +0530 Subject: [PATCH 018/299] [nrf fromtree] drivers: nrfwifi: Fix random MAC address setting Random MAC address setting can never be configured as the two defaults cover all cases. Fix the defaults, now the order is * Fixed * OTP (default, in case of no config) * Random Signed-off-by: Chaitanya Tata (cherry picked from commit 80db01f3bfeb5302b51d78375be17a1889cdca01) --- drivers/wifi/nrfwifi/Kconfig.nrfwifi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/wifi/nrfwifi/Kconfig.nrfwifi b/drivers/wifi/nrfwifi/Kconfig.nrfwifi index bccb48b8576..5f2e645e575 100644 --- a/drivers/wifi/nrfwifi/Kconfig.nrfwifi +++ b/drivers/wifi/nrfwifi/Kconfig.nrfwifi @@ -511,8 +511,8 @@ config WIFI_FIXED_MAC_ADDRESS choice prompt "Wi-Fi MAC address type" - default WIFI_OTP_MAC_ADDRESS if WIFI_FIXED_MAC_ADDRESS = "" default WIFI_FIXED_MAC_ADDRESS_ENABLED if WIFI_FIXED_MAC_ADDRESS != "" + default WIFI_OTP_MAC_ADDRESS help Select the type of MAC address to be used by the Wi-Fi driver From 5e13de09c75b7b5a3d1c56173181f1b0c1213ce2 Mon Sep 17 00:00:00 2001 From: Jukka Rissanen Date: Wed, 25 Sep 2024 14:46:37 +0300 Subject: [PATCH 019/299] [nrf fromtree] west.yml: update hostap revision Update hostap revision to get supplicant event numbers correctly. Signed-off-by: Jukka Rissanen (cherry picked from commit d59bb2f9f50c542fb10b0d8095903dea6109c3cc) --- west.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/west.yml b/west.yml index 1265f9cca33..dc77e581c4a 100644 --- a/west.yml +++ b/west.yml @@ -259,7 +259,7 @@ manifest: - hal - name: hostap path: modules/lib/hostap - revision: 9896a2ea803ec62e0998c0e569f12af88537d647 + revision: f6792cb45d848df5d562dd9255dfc6acf62be164 - name: libmetal revision: a6851ba6dba8c9e87d00c42f171a822f7a29639b path: modules/hal/libmetal From 3ea1f832c470fb28e7b7c42ce78c0e1cef184275 Mon Sep 17 00:00:00 2001 From: Fengming Ye Date: Fri, 27 Sep 2024 12:10:04 +0900 Subject: [PATCH 020/299] [nrf fromtree] west.yml: update hostap revision Update hostap revision to get crypto module test. Signed-off-by: Fengming Ye (cherry picked from commit 20e81f7c85bb6e298735325cc74e160db8f95baa) --- west.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/west.yml b/west.yml index dc77e581c4a..40707c2c58b 100644 --- a/west.yml +++ b/west.yml @@ -259,7 +259,7 @@ manifest: - hal - name: hostap path: modules/lib/hostap - revision: f6792cb45d848df5d562dd9255dfc6acf62be164 + revision: d84b1ea174407f9a501976fb294e39c40c348645 - name: libmetal revision: a6851ba6dba8c9e87d00c42f171a822f7a29639b path: modules/hal/libmetal From e35cf5b783aeb22b39062e26de7a79c5e0092cd5 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Mon, 7 Oct 2024 02:20:11 +0530 Subject: [PATCH 021/299] [nrf fromtree] manifest: hostap: Pull fixes from NCS Pull fixes that are in NCS but missed in upstream. Signed-off-by: Chaitanya Tata (cherry picked from commit 5c9c95b593a2f0725c1115195d7568456e84a795) --- west.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/west.yml b/west.yml index 40707c2c58b..2f749eba0f3 100644 --- a/west.yml +++ b/west.yml @@ -259,7 +259,7 @@ manifest: - hal - name: hostap path: modules/lib/hostap - revision: d84b1ea174407f9a501976fb294e39c40c348645 + revision: cdc0782c6ec76d75456e637bff78004c2c6eae87 - name: libmetal revision: a6851ba6dba8c9e87d00c42f171a822f7a29639b path: modules/hal/libmetal From 924bf9c9cdac1a8b60c8c2d411c9af995381a757 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Wed, 9 Oct 2024 23:11:53 +0530 Subject: [PATCH 022/299] [nrf fromtree] manifest: hostap: Pull fix for duplicate AP enable event The event is sent from both WPA supplicant and hostapd, but hostapd should only be sent when using hostapd to create the AP. Signed-off-by: Chaitanya Tata (cherry picked from commit edb47444b933b61d15ea87f3b5e6aa2db8e81716) --- west.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/west.yml b/west.yml index 2f749eba0f3..d7fd027b924 100644 --- a/west.yml +++ b/west.yml @@ -259,7 +259,7 @@ manifest: - hal - name: hostap path: modules/lib/hostap - revision: cdc0782c6ec76d75456e637bff78004c2c6eae87 + revision: 0fd0276b5b65de4d2f7cd0552789a74d3a129441 - name: libmetal revision: a6851ba6dba8c9e87d00c42f171a822f7a29639b path: modules/hal/libmetal From 8fbe6cbb06aab019eff32183ddeee5689c9d0120 Mon Sep 17 00:00:00 2001 From: Rafal Dyla Date: Tue, 1 Oct 2024 09:18:42 +0200 Subject: [PATCH 023/299] [nrf fromtree] modules: hal_nordic: Add global domain power request service Service for powering peripherals that use GPIO pins in the global power domains: - Active Fast - Active Slow - Main Slow Signed-off-by: Rafal Dyla (cherry picked from commit ec77fc399cb15a7bc2b49c9713ad9e0c1048d697) --- modules/hal_nordic/nrfs/CMakeLists.txt | 1 + modules/hal_nordic/nrfs/Kconfig | 9 +++++++++ modules/hal_nordic/nrfs/nrfs_config.h | 4 ++++ soc/nordic/nrf54h/Kconfig | 2 ++ soc/nordic/nrf92/Kconfig | 2 ++ west.yml | 2 +- 6 files changed, 19 insertions(+), 1 deletion(-) diff --git a/modules/hal_nordic/nrfs/CMakeLists.txt b/modules/hal_nordic/nrfs/CMakeLists.txt index c601b8a4233..f470eea00e9 100644 --- a/modules/hal_nordic/nrfs/CMakeLists.txt +++ b/modules/hal_nordic/nrfs/CMakeLists.txt @@ -25,6 +25,7 @@ if(CONFIG_NRFS) zephyr_library_sources_ifdef(CONFIG_NRFS_CLOCK_SERVICE_ENABLED ${SRC_DIR}/services/nrfs_clock.c) zephyr_library_sources_ifdef(CONFIG_NRFS_DIAG_SERVICE_ENABLED ${SRC_DIR}/services/nrfs_diag.c) zephyr_library_sources_ifdef(CONFIG_NRFS_DVFS_SERVICE_ENABLED ${SRC_DIR}/services/nrfs_dvfs.c) + zephyr_library_sources_ifdef(CONFIG_NRFS_GDPWR_SERVICE_ENABLED ${SRC_DIR}/services/nrfs_gdpwr.c) zephyr_library_sources_ifdef(CONFIG_NRFS_MRAM_SERVICE_ENABLED ${SRC_DIR}/services/nrfs_mram.c) zephyr_library_sources_ifdef(CONFIG_NRFS_PMIC_SERVICE_ENABLED ${SRC_DIR}/services/nrfs_pmic.c) zephyr_library_sources_ifdef(CONFIG_NRFS_RESET_SERVICE_ENABLED ${SRC_DIR}/services/nrfs_reset.c) diff --git a/modules/hal_nordic/nrfs/Kconfig b/modules/hal_nordic/nrfs/Kconfig index cf7c9be939b..3eee664e480 100644 --- a/modules/hal_nordic/nrfs/Kconfig +++ b/modules/hal_nordic/nrfs/Kconfig @@ -19,6 +19,9 @@ config NRFS_HAS_DIAG_SERVICE config NRFS_HAS_DVFS_SERVICE bool +config NRFS_HAS_GDPWR_SERVICE + bool + config NRFS_HAS_MRAM_SERVICE bool @@ -113,6 +116,12 @@ config NRFS_CLOCK_SERVICE_ENABLED bool "Clock service" depends on NRFS_HAS_CLOCK_SERVICE default y + +config NRFS_GDPWR_SERVICE_ENABLED + bool "Global domain power request service" + depends on NRFS_HAS_GDPWR_SERVICE + default y + endmenu rsource "backends/Kconfig" diff --git a/modules/hal_nordic/nrfs/nrfs_config.h b/modules/hal_nordic/nrfs/nrfs_config.h index 20cf6cece0e..a092adb7850 100644 --- a/modules/hal_nordic/nrfs/nrfs_config.h +++ b/modules/hal_nordic/nrfs/nrfs_config.h @@ -40,6 +40,10 @@ #define NRFS_CLOCK_SERVICE_ENABLED #endif +#ifdef CONFIG_NRFS_GDPWR_SERVICE_ENABLED +#define NRFS_GDPWR_SERVICE_ENABLED +#endif + #ifdef CONFIG_SOC_POSIX #define NRFS_UNIT_TESTS_ENABLED #endif diff --git a/soc/nordic/nrf54h/Kconfig b/soc/nordic/nrf54h/Kconfig index 51dc4e07480..9132ca8458b 100644 --- a/soc/nordic/nrf54h/Kconfig +++ b/soc/nordic/nrf54h/Kconfig @@ -24,6 +24,7 @@ config SOC_NRF54H20_CPUAPP_COMMON select HAS_SEGGER_RTT if ZEPHYR_SEGGER_MODULE select NRFS_HAS_CLOCK_SERVICE select NRFS_HAS_DVFS_SERVICE + select NRFS_HAS_GDPWR_SERVICE select NRFS_HAS_MRAM_SERVICE select NRFS_HAS_TEMP_SERVICE select NRFS_HAS_VBUS_DETECTOR_SERVICE @@ -49,6 +50,7 @@ config SOC_NRF54H20_CPURAD_COMMON select CPU_HAS_CUSTOM_FIXED_SOC_MPU_REGIONS select HAS_SEGGER_RTT if ZEPHYR_SEGGER_MODULE select NRFS_HAS_CLOCK_SERVICE + select NRFS_HAS_GDPWR_SERVICE select NRFS_HAS_MRAM_SERVICE select NRFS_HAS_TEMP_SERVICE select NRFS_HAS_VBUS_DETECTOR_SERVICE diff --git a/soc/nordic/nrf92/Kconfig b/soc/nordic/nrf92/Kconfig index f6efecb6ad0..1f60b944b76 100644 --- a/soc/nordic/nrf92/Kconfig +++ b/soc/nordic/nrf92/Kconfig @@ -22,6 +22,7 @@ config SOC_NRF9230_ENGB_CPUAPP select HAS_NORDIC_DMM select HAS_SEGGER_RTT if ZEPHYR_SEGGER_MODULE select NRFS_HAS_CLOCK_SERVICE + select NRFS_HAS_GDPWR_SERVICE select NRFS_HAS_MRAM_SERVICE select NRFS_HAS_PMIC_SERVICE select NRFS_HAS_TEMP_SERVICE @@ -40,6 +41,7 @@ config SOC_NRF9230_ENGB_CPURAD select HAS_NORDIC_DMM select HAS_SEGGER_RTT if ZEPHYR_SEGGER_MODULE select NRFS_HAS_CLOCK_SERVICE + select NRFS_HAS_GDPWR_SERVICE select NRFS_HAS_MRAM_SERVICE select NRFS_HAS_PMIC_SERVICE select NRFS_HAS_TEMP_SERVICE diff --git a/west.yml b/west.yml index d7fd027b924..239ac8d20d4 100644 --- a/west.yml +++ b/west.yml @@ -188,7 +188,7 @@ manifest: groups: - hal - name: hal_nordic - revision: bc25c094a8cf3064f4f9c1e8060b46e1989edf95 + revision: 4a3ba8eaca8f5255f550db7bc54dc3e23212da64 path: modules/hal/nordic groups: - hal From 0d5a4eb283f94533ce8a694fdbbfa79e7d15ff42 Mon Sep 17 00:00:00 2001 From: Kapil Bhatt Date: Mon, 14 Oct 2024 14:13:47 +0530 Subject: [PATCH 024/299] [nrf fromtree] manifest: update hal_nordic revision for offloaded raw tx mode Updated hal_nordic revision contains changes for offloaded raw tx mode. Signed-off-by: Kapil Bhatt (cherry picked from commit 56a5ac5189ae4293b80e4bca433e7d820f09fdf0) --- west.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/west.yml b/west.yml index 239ac8d20d4..bd588eaaea0 100644 --- a/west.yml +++ b/west.yml @@ -188,7 +188,7 @@ manifest: groups: - hal - name: hal_nordic - revision: 4a3ba8eaca8f5255f550db7bc54dc3e23212da64 + revision: d5c70305b2389641b0a166d0714775a1b13319a2 path: modules/hal/nordic groups: - hal From 01bddd1369cb84b468855aeefa610e456f9aea7d Mon Sep 17 00:00:00 2001 From: Maochen Wang Date: Mon, 14 Oct 2024 14:14:42 +0800 Subject: [PATCH 025/299] [nrf fromtree] manifest: Update hostap to fix build error Fix build error of undefined reference to 'inet_aton' in hostap/src/utils/ip_addr.c Signed-off-by: Maochen Wang (cherry picked from commit 244958c9f482ab0980da07d7565bd86cca377ed7) --- west.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/west.yml b/west.yml index bd588eaaea0..e87e6405424 100644 --- a/west.yml +++ b/west.yml @@ -259,7 +259,7 @@ manifest: - hal - name: hostap path: modules/lib/hostap - revision: 0fd0276b5b65de4d2f7cd0552789a74d3a129441 + revision: 7c32520564908e1220976b6c185dec296b6d4a80 - name: libmetal revision: a6851ba6dba8c9e87d00c42f171a822f7a29639b path: modules/hal/libmetal From 269e7a121cdeea29b2f0578e6a893ca30fcc487b Mon Sep 17 00:00:00 2001 From: Kapil Bhatt Date: Mon, 9 Sep 2024 17:07:09 +0530 Subject: [PATCH 026/299] [nrf fromtree] drivers: nrfwifi: Create separate offloaded raw tx mode Create separate offloaded raw tx mode which will work as stand-alone compile-time mode. Signed-off-by: Kapil Bhatt (cherry picked from commit 5c3cc3730a20a073bf1252c427c01591a9a6a359) --- drivers/wifi/nrfwifi/CMakeLists.txt | 11 +++++++++-- drivers/wifi/nrfwifi/Kconfig.nrfwifi | 5 ++++- drivers/wifi/nrfwifi/inc/fmac_main.h | 6 +++++- drivers/wifi/nrfwifi/src/wifi_util.c | 8 ++++---- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/drivers/wifi/nrfwifi/CMakeLists.txt b/drivers/wifi/nrfwifi/CMakeLists.txt index e8eba37ca01..71c9a5e6c14 100644 --- a/drivers/wifi/nrfwifi/CMakeLists.txt +++ b/drivers/wifi/nrfwifi/CMakeLists.txt @@ -30,7 +30,7 @@ zephyr_include_directories_ifdef(CONFIG_NRF70_RADIO_TEST ) zephyr_include_directories_ifndef(CONFIG_NRF70_RADIO_TEST - ${OS_AGNOSTIC_BASE}/fw_if/umac_if/inc/default + {OS_AGNOSTIC_BASE}/fw_if/umac_if/inc/default ) zephyr_library_sources_ifdef(CONFIG_NRF70_SR_COEX @@ -57,12 +57,15 @@ zephyr_library_sources( src/shim.c src/work.c src/timer.c - src/fmac_main.c src/qspi/src/device.c src/qspi/src/rpu_hw_if.c src/qspi/src/ficr_prog.c ) +zephyr_library_sources_ifndef(CONFIG_NRF70_OFFLOADED_RAW_TX + src/fmac_main.c +) + zephyr_library_sources_ifdef(CONFIG_NRF_WIFI_PATCHES_BUILTIN src/fw_load.c ) @@ -231,6 +234,10 @@ zephyr_compile_definitions_ifdef(CONFIG_NRF70_RADIO_TEST -DNRF70_RADIO_TEST ) +zephyr_compile_definitions_ifdef(CONFIG_NRF70_OFFLOADED_RAW_TX + -DNRF70_OFFLOADED_RAW_TX +) + zephyr_compile_definitions_ifdef(CONFIG_NRF70_TCP_IP_CHECKSUM_OFFLOAD -DNRF70_TCP_IP_CHECKSUM_OFFLOAD ) diff --git a/drivers/wifi/nrfwifi/Kconfig.nrfwifi b/drivers/wifi/nrfwifi/Kconfig.nrfwifi index 5f2e645e575..ce7e0b753f8 100644 --- a/drivers/wifi/nrfwifi/Kconfig.nrfwifi +++ b/drivers/wifi/nrfwifi/Kconfig.nrfwifi @@ -69,6 +69,9 @@ config NRF70_SCAN_ONLY config NRF70_RADIO_TEST bool "Radio test mode of the nRF70 driver" +config NRF70_OFFLOADED_RAW_TX + bool "Offloaded raw Tx mode of the nRF70 driver" + config NRF70_SYSTEM_WITH_RAW_MODES bool "nRF70 system mode with raw modes" depends on WIFI_NRF7002 || WIFI_NRF7001 @@ -83,7 +86,7 @@ config NRF70_SYSTEM_MODE_COMMON default y if NRF70_SYSTEM_MODE || NRF70_SYSTEM_WITH_RAW_MODES config NET_L2_ETHERNET - default y if !NRF70_RADIO_TEST + default y if (!NRF70_RADIO_TEST && !NRF70_OFFLOADED_RAW_TX) config HEAP_MEM_POOL_ADD_SIZE_NRF70 # Use a maximum that works for typical usecases and boards, each sample/app can override diff --git a/drivers/wifi/nrfwifi/inc/fmac_main.h b/drivers/wifi/nrfwifi/inc/fmac_main.h index 92bc2ac28f8..c11d32c487a 100644 --- a/drivers/wifi/nrfwifi/inc/fmac_main.h +++ b/drivers/wifi/nrfwifi/inc/fmac_main.h @@ -34,6 +34,7 @@ #define NRF70_DRIVER_VERSION "1."KERNEL_VERSION_STRING +#ifndef CONFIG_NRF70_OFFLOADED_RAW_TX #ifndef CONFIG_NRF70_RADIO_TEST struct nrf_wifi_vif_ctx_zep { const struct device *zep_dev_ctx; @@ -119,6 +120,7 @@ struct nrf_wifi_drv_priv_zep { extern struct nrf_wifi_drv_priv_zep rpu_drv_priv_zep; void nrf_wifi_scan_timeout_work(struct k_work *work); + void configure_tx_pwr_settings(struct nrf_wifi_tx_pwr_ctrl_params *tx_pwr_ctrl_params, struct nrf_wifi_tx_pwr_ceil_params *tx_pwr_ceil_params); void configure_board_dep_params(struct nrf_wifi_board_params *board_params); @@ -126,6 +128,7 @@ void set_tx_pwr_ceil_default(struct nrf_wifi_tx_pwr_ceil_params *pwr_ceil_params const char *nrf_wifi_get_drv_version(void); enum nrf_wifi_status nrf_wifi_fmac_dev_add_zep(struct nrf_wifi_drv_priv_zep *drv_priv_zep); enum nrf_wifi_status nrf_wifi_fmac_dev_rem_zep(struct nrf_wifi_drv_priv_zep *drv_priv_zep); +#endif /* !CONFIG_NRF_WIFI_BUILD_ONLY_MODE */ #ifdef CONFIG_NRF_WIFI_BUILD_ONLY_MODE inline enum nrf_wifi_status nrf_wifi_fw_load(void *rpu_ctx) { @@ -136,9 +139,10 @@ inline enum nrf_wifi_status nrf_wifi_fw_load(void *rpu_ctx) #else enum nrf_wifi_status nrf_wifi_fw_load(void *rpu_ctx); #endif /* CONFIG_NRF_WIFI_BUILD_ONLY_MODE */ +#ifndef CONFIG_NRF70_OFFLOADED_RAW_TX struct nrf_wifi_vif_ctx_zep *nrf_wifi_get_vif_ctx(struct net_if *iface); void nrf_wifi_rpu_recovery_cb(void *vif_ctx, void *event_data, unsigned int event_len); - +#endif /* !CONFIG_NRF_WIFI_BUILD_ONLY_MODE */ #endif /* __ZEPHYR_FMAC_MAIN_H__ */ diff --git a/drivers/wifi/nrfwifi/src/wifi_util.c b/drivers/wifi/nrfwifi/src/wifi_util.c index 43c527a4b7d..c5e2a8dedfa 100644 --- a/drivers/wifi/nrfwifi/src/wifi_util.c +++ b/drivers/wifi/nrfwifi/src/wifi_util.c @@ -435,7 +435,7 @@ static int nrf_wifi_util_show_vers(const struct shell *sh, return status; } -#ifndef CONFIG_NRF70_RADIO_TEST +#if !defined(CONFIG_NRF70_RADIO_TEST) && !defined(CONFIG_NRF70_OFFLOADED_RAW_TX) static int nrf_wifi_util_dump_rpu_stats(const struct shell *sh, size_t argc, const char *argv[]) @@ -849,7 +849,7 @@ static int nrf_wifi_util_dump_rpu_stats(const struct shell *sh, return 0; } -#endif /* CONFIG_NRF70_RADIO_TEST */ +#endif /* !CONFIG_NRF70_RADIO_TEST && !CONFIG_NRF70_OFFLOADED_RAW_TX */ #ifdef CONFIG_NRF_WIFI_RPU_RECOVERY static int nrf_wifi_util_trigger_rpu_recovery(const struct shell *sh, @@ -964,7 +964,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE( nrf_wifi_util_show_vers, 1, 0), -#ifndef CONFIG_NRF70_RADIO_TEST +#if !defined(CONFIG_NRF70_RADIO_TEST) && !defined(CONFIG_NRF70_OFFLOADED_RAW_TX) SHELL_CMD_ARG(rpu_stats, NULL, "Display RPU stats " @@ -972,7 +972,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE( nrf_wifi_util_dump_rpu_stats, 1, 1), -#endif /* CONFIG_NRF70_RADIO_TEST */ +#endif /* !CONFIG_NRF70_RADIO_TEST && !CONFIG_NRF70_OFFLOADED_RAW_TX*/ #ifdef CONFIG_NRF_WIFI_RPU_RECOVERY SHELL_CMD_ARG(rpu_recovery_test, NULL, From ba2cb8e177ec63d16d9946ad8526f79dd65c9716 Mon Sep 17 00:00:00 2001 From: Kapil Bhatt Date: Fri, 27 Sep 2024 18:08:29 +0530 Subject: [PATCH 027/299] [nrf fromtree] wifi: Add wrapper APIs for offloaded raw TX feature Add wrapper APIs for the offloaded raw TX feature supported by nRF70 devices. Signed-off-by: Kapil Bhatt (cherry picked from commit 28b74947e07822d52187458b5a79a18782269e53) --- drivers/wifi/nrfwifi/CMakeLists.txt | 21 +- .../wifi/nrfwifi/off_raw_tx/inc/off_raw_tx.h | 28 + .../nrfwifi/off_raw_tx/src/off_raw_tx_api.c | 482 ++++++++++++++++++ .../wifi/nrfwifi/off_raw_tx/off_raw_tx_api.h | 260 ++++++++++ 4 files changed, 788 insertions(+), 3 deletions(-) create mode 100644 drivers/wifi/nrfwifi/off_raw_tx/inc/off_raw_tx.h create mode 100644 drivers/wifi/nrfwifi/off_raw_tx/src/off_raw_tx_api.c create mode 100644 include/zephyr/drivers/wifi/nrfwifi/off_raw_tx/off_raw_tx_api.h diff --git a/drivers/wifi/nrfwifi/CMakeLists.txt b/drivers/wifi/nrfwifi/CMakeLists.txt index 71c9a5e6c14..5ea9da5825e 100644 --- a/drivers/wifi/nrfwifi/CMakeLists.txt +++ b/drivers/wifi/nrfwifi/CMakeLists.txt @@ -29,10 +29,15 @@ zephyr_include_directories_ifdef(CONFIG_NRF70_RADIO_TEST ${OS_AGNOSTIC_BASE}/fw_if/umac_if/inc/radio_test ) -zephyr_include_directories_ifndef(CONFIG_NRF70_RADIO_TEST - {OS_AGNOSTIC_BASE}/fw_if/umac_if/inc/default +zephyr_include_directories_ifdef(CONFIG_NRF70_OFFLOADED_RAW_TX + ${OS_AGNOSTIC_BASE}/fw_if/umac_if/inc/offload_raw_tx + off_raw_tx/inc ) +if(NOT CONFIG_NRF70_RADIO_TEST AND NOT CONFIG_NRF70_OFFLOADED_RAW_TX) + zephyr_include_directories(${OS_AGNOSTIC_BASE}/fw_if/umac_if/inc/default) +endif() + zephyr_library_sources_ifdef(CONFIG_NRF70_SR_COEX src/coex.c ) @@ -70,13 +75,15 @@ zephyr_library_sources_ifdef(CONFIG_NRF_WIFI_PATCHES_BUILTIN src/fw_load.c ) -zephyr_library_sources_ifndef(CONFIG_NRF70_RADIO_TEST +if(NOT CONFIG_NRF70_RADIO_TEST AND NOT CONFIG_NRF70_OFFLOADED_RAW_TX) + zephyr_library_sources( ${OS_AGNOSTIC_BASE}/fw_if/umac_if/src/rx.c ${OS_AGNOSTIC_BASE}/fw_if/umac_if/src/fmac_vif.c ${OS_AGNOSTIC_BASE}/fw_if/umac_if/src/fmac_util.c src/net_if.c ${OS_AGNOSTIC_BASE}/fw_if/umac_if/src/default/fmac_api.c ) +endif() zephyr_library_sources_ifdef(CONFIG_NET_L2_WIFI_MGMT src/wifi_mgmt_scan.c @@ -91,6 +98,12 @@ zephyr_library_sources_ifdef(CONFIG_NRF70_RADIO_TEST ${OS_AGNOSTIC_BASE}/fw_if/umac_if/src/fmac_util.c ) +zephyr_library_sources_ifdef(CONFIG_NRF70_OFFLOADED_RAW_TX + ${OS_AGNOSTIC_BASE}/fw_if/umac_if/src/offload_raw_tx/fmac_api.c + ${OS_AGNOSTIC_BASE}/fw_if/umac_if/src/fmac_util.c + off_raw_tx/src/off_raw_tx_api.c +) + zephyr_library_sources_ifdef(CONFIG_NRF70_DATA_TX ${OS_AGNOSTIC_BASE}/fw_if/umac_if/src/tx.c ${OS_AGNOSTIC_BASE}/fw_if/umac_if/src/fmac_peer.c @@ -155,6 +168,8 @@ elseif(CONFIG_NRF_WIFI_PATCHES_BUILTIN) set(NRF70_PATCH ${FW_BINS_BASE}/scan_only/nrf70.bin) elseif (CONFIG_NRF70_SYSTEM_WITH_RAW_MODES) set(NRF70_PATCH ${FW_BINS_BASE}/system_with_raw/nrf70.bin) + elseif(CONFIG_NRF70_OFFLOADED_RAW_TX) + set(NRF70_PATCH ${FW_BINS_BASE}/offloaded_raw_tx/nrf70.bin) else() # Error message(FATAL_ERROR "Unsupported nRF70 patch configuration") diff --git a/drivers/wifi/nrfwifi/off_raw_tx/inc/off_raw_tx.h b/drivers/wifi/nrfwifi/off_raw_tx/inc/off_raw_tx.h new file mode 100644 index 00000000000..1cb6e258462 --- /dev/null +++ b/drivers/wifi/nrfwifi/off_raw_tx/inc/off_raw_tx.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @brief File containing internal structures for the offloaded raw TX feature in the driver. + */ + +#include "fmac_structs_common.h" +#include "osal_api.h" + +struct nrf_wifi_ctx_zep { + void *drv_priv_zep; + void *rpu_ctx; + uint8_t mac_addr[6]; +}; + + +struct nrf_wifi_off_raw_tx_drv_priv { + struct nrf_wifi_fmac_priv *fmac_priv; + /* TODO: Replace with a linked list to handle unlimited RPUs */ + struct nrf_wifi_ctx_zep rpu_ctx_zep; + struct k_spinlock lock; +}; + +enum nrf_wifi_status nrf_wifi_fw_load(void *rpu_ctx); diff --git a/drivers/wifi/nrfwifi/off_raw_tx/src/off_raw_tx_api.c b/drivers/wifi/nrfwifi/off_raw_tx/src/off_raw_tx_api.c new file mode 100644 index 00000000000..3b1dd0bb093 --- /dev/null +++ b/drivers/wifi/nrfwifi/off_raw_tx/src/off_raw_tx_api.c @@ -0,0 +1,482 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @brief File containing API definitions for the Offloaded raw TX feature. + */ + +#include +#include +#include +#include +#include +#include +#include + +#define DT_DRV_COMPAT nordic_wlan +LOG_MODULE_DECLARE(wifi_nrf, CONFIG_WIFI_NRF70_LOG_LEVEL); + +struct nrf_wifi_off_raw_tx_drv_priv off_raw_tx_drv_priv; +extern const struct nrf_wifi_osal_ops nrf_wifi_os_zep_ops; + +static const int valid_data_rates[] = { 1, 2, 55, 11, 6, 9, 12, 18, 24, 36, 48, 54, + 0, 1, 2, 3, 4, 5, 6, 7, -1 }; + +/* DTS uses 1dBm as the unit for TX power, while the RPU uses 0.25dBm */ +#define MAX_TX_PWR(label) DT_PROP(DT_NODELABEL(nrf70), label) * 4 +static void configure_tx_pwr_settings(struct nrf_wifi_tx_pwr_ctrl_params *ctrl_params, + struct nrf_wifi_tx_pwr_ceil_params *ceil_params) +{ + ctrl_params->ant_gain_2g = CONFIG_NRF70_ANT_GAIN_2G; + ctrl_params->ant_gain_5g_band1 = CONFIG_NRF70_ANT_GAIN_5G_BAND1; + ctrl_params->ant_gain_5g_band2 = CONFIG_NRF70_ANT_GAIN_5G_BAND2; + ctrl_params->ant_gain_5g_band3 = CONFIG_NRF70_ANT_GAIN_5G_BAND3; + ctrl_params->band_edge_2g_lo_dss = CONFIG_NRF70_BAND_2G_LOWER_EDGE_BACKOFF_DSSS; + ctrl_params->band_edge_2g_lo_ht = CONFIG_NRF70_BAND_2G_LOWER_EDGE_BACKOFF_HT; + ctrl_params->band_edge_2g_lo_he = CONFIG_NRF70_BAND_2G_LOWER_EDGE_BACKOFF_HE; + ctrl_params->band_edge_2g_hi_dsss = CONFIG_NRF70_BAND_2G_UPPER_EDGE_BACKOFF_DSSS; + ctrl_params->band_edge_2g_hi_ht = CONFIG_NRF70_BAND_2G_UPPER_EDGE_BACKOFF_HT; + ctrl_params->band_edge_2g_hi_he = CONFIG_NRF70_BAND_2G_UPPER_EDGE_BACKOFF_HE; + ctrl_params->band_edge_5g_unii_1_lo_ht = + CONFIG_NRF70_BAND_UNII_1_LOWER_EDGE_BACKOFF_HT; + ctrl_params->band_edge_5g_unii_1_lo_he = + CONFIG_NRF70_BAND_UNII_1_LOWER_EDGE_BACKOFF_HE; + ctrl_params->band_edge_5g_unii_1_hi_ht = + CONFIG_NRF70_BAND_UNII_1_UPPER_EDGE_BACKOFF_HT; + ctrl_params->band_edge_5g_unii_1_hi_he = + CONFIG_NRF70_BAND_UNII_1_UPPER_EDGE_BACKOFF_HE; + ctrl_params->band_edge_5g_unii_2a_lo_ht = + CONFIG_NRF70_BAND_UNII_2A_LOWER_EDGE_BACKOFF_HT; + ctrl_params->band_edge_5g_unii_2a_lo_he = + CONFIG_NRF70_BAND_UNII_2A_LOWER_EDGE_BACKOFF_HE; + ctrl_params->band_edge_5g_unii_2a_hi_ht = + CONFIG_NRF70_BAND_UNII_2A_UPPER_EDGE_BACKOFF_HT; + ctrl_params->band_edge_5g_unii_2a_hi_he = + CONFIG_NRF70_BAND_UNII_2A_UPPER_EDGE_BACKOFF_HE; + ctrl_params->band_edge_5g_unii_2c_lo_ht = + CONFIG_NRF70_BAND_UNII_2C_LOWER_EDGE_BACKOFF_HT; + ctrl_params->band_edge_5g_unii_2c_lo_he = + CONFIG_NRF70_BAND_UNII_2C_LOWER_EDGE_BACKOFF_HE; + ctrl_params->band_edge_5g_unii_2c_hi_ht = + CONFIG_NRF70_BAND_UNII_2C_UPPER_EDGE_BACKOFF_HT; + ctrl_params->band_edge_5g_unii_2c_hi_he = + CONFIG_NRF70_BAND_UNII_2C_UPPER_EDGE_BACKOFF_HE; + ctrl_params->band_edge_5g_unii_3_lo_ht = + CONFIG_NRF70_BAND_UNII_3_LOWER_EDGE_BACKOFF_HT; + ctrl_params->band_edge_5g_unii_3_lo_he = + CONFIG_NRF70_BAND_UNII_3_LOWER_EDGE_BACKOFF_HE; + ctrl_params->band_edge_5g_unii_3_hi_ht = + CONFIG_NRF70_BAND_UNII_3_UPPER_EDGE_BACKOFF_HT; + ctrl_params->band_edge_5g_unii_3_hi_he = + CONFIG_NRF70_BAND_UNII_3_UPPER_EDGE_BACKOFF_HE; + ctrl_params->band_edge_5g_unii_4_lo_ht = + CONFIG_NRF70_BAND_UNII_4_LOWER_EDGE_BACKOFF_HT; + ctrl_params->band_edge_5g_unii_4_lo_he = + CONFIG_NRF70_BAND_UNII_4_LOWER_EDGE_BACKOFF_HE; + ctrl_params->band_edge_5g_unii_4_hi_ht = + CONFIG_NRF70_BAND_UNII_4_UPPER_EDGE_BACKOFF_HT; + ctrl_params->band_edge_5g_unii_4_hi_he = + CONFIG_NRF70_BAND_UNII_4_UPPER_EDGE_BACKOFF_HE; + ceil_params->max_pwr_2g_dsss = MAX_TX_PWR(wifi_max_tx_pwr_2g_dsss); + ceil_params->max_pwr_2g_mcs7 = MAX_TX_PWR(wifi_max_tx_pwr_2g_mcs7); + ceil_params->max_pwr_2g_mcs0 = MAX_TX_PWR(wifi_max_tx_pwr_2g_mcs0); +#ifndef CONFIG_NRF70_2_4G_ONLY + ceil_params->max_pwr_5g_low_mcs7 = MAX_TX_PWR(wifi_max_tx_pwr_5g_low_mcs7); + ceil_params->max_pwr_5g_mid_mcs7 = MAX_TX_PWR(wifi_max_tx_pwr_5g_mid_mcs7); + ceil_params->max_pwr_5g_high_mcs7 = MAX_TX_PWR(wifi_max_tx_pwr_5g_high_mcs7); + ceil_params->max_pwr_5g_low_mcs0 = MAX_TX_PWR(wifi_max_tx_pwr_5g_low_mcs0); + ceil_params->max_pwr_5g_mid_mcs0 = MAX_TX_PWR(wifi_max_tx_pwr_5g_mid_mcs0); + ceil_params->max_pwr_5g_high_mcs0 = MAX_TX_PWR(wifi_max_tx_pwr_5g_high_mcs0); +#endif /* CONFIG_NRF70_2_4G_ONLY */ +} + +static void configure_board_dep_params(struct nrf_wifi_board_params *board_params) +{ + board_params->pcb_loss_2g = CONFIG_NRF70_PCB_LOSS_2G; +#ifndef CONFIG_NRF70_2_4G_ONLY + board_params->pcb_loss_5g_band1 = CONFIG_NRF70_PCB_LOSS_5G_BAND1; + board_params->pcb_loss_5g_band2 = CONFIG_NRF70_PCB_LOSS_5G_BAND2; + board_params->pcb_loss_5g_band3 = CONFIG_NRF70_PCB_LOSS_5G_BAND3; +#endif /* CONFIG_NRF70_2_4G_ONLY */ +} + +#ifdef CONFIG_WIFI_FIXED_MAC_ADDRESS_ENABLED +static int bytes_from_str(uint8_t *buf, int buf_len, const char *src) +{ + size_t i; + size_t src_len = strlen(src); + char *endptr; + + for (i = 0U; i < src_len; i++) { + if (!isxdigit((unsigned char)src[i]) && + src[i] != ':') { + return -EINVAL; + } + } + + (void)memset(buf, 0, buf_len); + + for (i = 0U; i < (size_t)buf_len; i++) { + buf[i] = (uint8_t)strtol(src, &endptr, 16); + src = ++endptr; + } + + return 0; +} +#endif /* CONFIG_WIFI_FIXED_MAC_ADDRESS_ENABLED */ + +int nrf70_off_raw_tx_init(uint8_t *mac_addr) +{ + enum nrf_wifi_status status = NRF_WIFI_STATUS_FAIL; + struct nrf_wifi_ctx_zep *rpu_ctx_zep = NULL; + void *rpu_ctx = NULL; + struct nrf_wifi_tx_pwr_ctrl_params ctrl_params; + struct nrf_wifi_tx_pwr_ceil_params ceil_params; + struct nrf_wifi_board_params board_params; + unsigned int fw_ver = 0; + k_spinlock_key_t key; + + /* The OSAL layer needs to be initialized before any other initialization + * so that other layers (like FW IF,HW IF etc) have access to OS ops + */ + nrf_wifi_osal_init(&nrf_wifi_os_zep_ops); + + key = k_spin_lock(&off_raw_tx_drv_priv.lock); + + off_raw_tx_drv_priv.fmac_priv = nrf_wifi_fmac_off_raw_tx_init(); + + if (off_raw_tx_drv_priv.fmac_priv == NULL) { + LOG_ERR("%s: Failed to initialize nRF70 driver", + __func__); + goto err; + } + + rpu_ctx_zep = &off_raw_tx_drv_priv.rpu_ctx_zep; + + rpu_ctx_zep->drv_priv_zep = &off_raw_tx_drv_priv; + + rpu_ctx = nrf_wifi_fmac_dev_add(off_raw_tx_drv_priv.fmac_priv, + rpu_ctx_zep); + if (!rpu_ctx) { + LOG_ERR("%s: Failed to add nRF70 device", __func__); + rpu_ctx_zep = NULL; + goto err; + } + + rpu_ctx_zep->rpu_ctx = rpu_ctx; + + status = nrf_wifi_fw_load(rpu_ctx); + if (status != NRF_WIFI_STATUS_SUCCESS) { + LOG_ERR("%s: Failed to load the nRF70 firmware patch", __func__); + goto err; + } + + status = nrf_wifi_fmac_ver_get(rpu_ctx, + &fw_ver); + if (status != NRF_WIFI_STATUS_SUCCESS) { + LOG_ERR("%s: Failed to read the nRF70 firmware version", __func__); + goto err; + } + + LOG_DBG("nRF70 firmware (v%d.%d.%d.%d) booted successfully", + NRF_WIFI_UMAC_VER(fw_ver), + NRF_WIFI_UMAC_VER_MAJ(fw_ver), + NRF_WIFI_UMAC_VER_MIN(fw_ver), + NRF_WIFI_UMAC_VER_EXTRA(fw_ver)); + + memset(&ctrl_params, 0, sizeof(ctrl_params)); + memset(&ceil_params, 0, sizeof(ceil_params)); + + configure_tx_pwr_settings(&ctrl_params, + &ceil_params); + + memset(&board_params, 0, sizeof(board_params)); + + configure_board_dep_params(&board_params); + + status = nrf_wifi_fmac_off_raw_tx_dev_init(rpu_ctx_zep->rpu_ctx, +#ifdef CONFIG_NRF_WIFI_LOW_POWER + HW_SLEEP_ENABLE, +#endif /* CONFIG_NRF_WIFI_LOW_POWER */ + NRF_WIFI_DEF_PHY_CALIB, + CONFIG_NRF_WIFI_OP_BAND, + IS_ENABLED(CONFIG_NRF_WIFI_BEAMFORMING), + &ctrl_params, + &ceil_params, + &board_params); + if (status != NRF_WIFI_STATUS_SUCCESS) { + LOG_ERR("%s: nRF70 firmware initialization failed", __func__); + goto err; + } + + if (mac_addr) { + memcpy(rpu_ctx_zep->mac_addr, mac_addr, 6); + } else { +#ifdef CONFIG_WIFI_FIXED_MAC_ADDRESS_ENABLED + int ret = -1; + + ret = bytes_from_str(rpu_ctx_zep->mac_addr, + 6, + CONFIG_WIFI_FIXED_MAC_ADDRESS); + if (ret < 0) { + LOG_ERR("%s: Failed to parse MAC address: %s", + __func__, + CONFIG_WIFI_FIXED_MAC_ADDRESS); + goto err; + } +#elif CONFIG_WIFI_OTP_MAC_ADDRESS + status = nrf_wifi_fmac_otp_mac_addr_get(off_raw_tx_drv_priv.rpu_ctx_zep.rpu_ctx, + 0, + rpu_ctx_zep->mac_addr); + if (status != NRF_WIFI_STATUS_SUCCESS) { + LOG_ERR("%s: Fetching of MAC address from OTP failed", + __func__); + goto err; + } +#endif /* CONFIG_WIFI_FIXED_MAC_ADDRESS_ENABLED */ + + if (!nrf_wifi_utils_is_mac_addr_valid(rpu_ctx_zep->mac_addr)) { + LOG_ERR("%s: Invalid MAC address: %02X:%02X:%02X:%02X:%02X:%02X", + __func__, + rpu_ctx_zep->mac_addr[0], + rpu_ctx_zep->mac_addr[1], + rpu_ctx_zep->mac_addr[2], + rpu_ctx_zep->mac_addr[3], + rpu_ctx_zep->mac_addr[4], + rpu_ctx_zep->mac_addr[5]); + goto err; + } + } + + k_spin_unlock(&off_raw_tx_drv_priv.lock, key); + + return 0; +err: + if (rpu_ctx) { + nrf_wifi_fmac_off_raw_tx_dev_rem(rpu_ctx); + rpu_ctx_zep->rpu_ctx = NULL; + } + + k_spin_unlock(&off_raw_tx_drv_priv.lock, key); + nrf70_off_raw_tx_deinit(); + return -1; +} + + +void nrf70_off_raw_tx_deinit(void) +{ + k_spinlock_key_t key; + + key = k_spin_lock(&off_raw_tx_drv_priv.lock); + + if (!off_raw_tx_drv_priv.fmac_priv) { + k_spin_unlock(&off_raw_tx_drv_priv.lock, key); + return; + } + + nrf_wifi_fmac_off_raw_tx_deinit(off_raw_tx_drv_priv.fmac_priv); + nrf_wifi_osal_deinit(); + + k_spin_unlock(&off_raw_tx_drv_priv.lock, key); +} + +static bool validate_rate(enum nrf_wifi_off_raw_tx_tput_mode tput_mode, + enum nrf_wifi_off_raw_tx_rate rate) +{ + if (tput_mode == TPUT_MODE_LEGACY) { + if (rate > RATE_54M) { + return false; + } + } else { + if (rate <= RATE_54M) { + return false; + } + } + + return true; +} + +int nrf70_off_raw_tx_conf_update(struct nrf_wifi_off_raw_tx_conf *conf) +{ + int ret = -1; + enum nrf_wifi_status status = NRF_WIFI_STATUS_FAIL; + struct nrf_wifi_offload_ctrl_params *off_ctrl_params = NULL; + struct nrf_wifi_offload_tx_ctrl *off_tx_params = NULL; + struct nrf_wifi_fmac_dev_ctx *fmac_dev_ctx = NULL; + k_spinlock_key_t key; + + if (!conf) { + LOG_ERR("%s: Config params is NULL", __func__); + goto out; + } + + off_ctrl_params = nrf_wifi_osal_mem_zalloc(sizeof(*off_ctrl_params)); + if (!off_ctrl_params) { + LOG_ERR("%s: Failed to allocate memory for off_ctrl_params", __func__); + goto out; + } + + key = k_spin_lock(&off_raw_tx_drv_priv.lock); + + fmac_dev_ctx = off_raw_tx_drv_priv.rpu_ctx_zep.rpu_ctx; + + if (!fmac_dev_ctx) { + LOG_ERR("%s: FMAC device context is NULL", __func__); + goto out; + } + + off_tx_params = nrf_wifi_osal_mem_zalloc(sizeof(*off_tx_params)); + if (!off_tx_params) { + LOG_ERR("%s Failed to allocate memory for off_tx_params: ", __func__); + goto out; + } + + if (!validate_rate(conf->tput_mode, conf->rate)) { + LOG_ERR("%s Invalid rate. Throughput mode: %d, rate: %d\n", __func__, + conf->tput_mode, conf->rate); + goto out; + } + + off_ctrl_params->channel_no = conf->chan; + off_ctrl_params->period_in_us = conf->period_us; + off_ctrl_params->tx_pwr = conf->tx_pwr; + off_tx_params->he_gi_type = conf->he_gi; + off_tx_params->he_ltf = conf->he_ltf; + off_tx_params->pkt_ram_ptr = RPU_MEM_PKT_BASE; + off_tx_params->pkt_length = conf->pkt_len; + off_tx_params->rate_flags = conf->tput_mode; + off_tx_params->rate = valid_data_rates[conf->rate]; + off_tx_params->rate_preamble_type = conf->short_preamble; + off_tx_params->rate_retries = conf->num_retries; + + status = hal_rpu_mem_write(fmac_dev_ctx->hal_dev_ctx, + RPU_MEM_PKT_BASE, + conf->pkt, + conf->pkt_len); + if (status != NRF_WIFI_STATUS_SUCCESS) { + LOG_ERR("%s: hal_rpu_mem_write failed", __func__); + goto out; + } + + status = nrf_wifi_fmac_off_raw_tx_conf(fmac_dev_ctx, + off_ctrl_params, + off_tx_params); + if (status != NRF_WIFI_STATUS_SUCCESS) { + LOG_ERR("%s: nRF70 offloaded raw TX configuration failed", + __func__); + goto out; + } + + ret = 0; +out: + nrf_wifi_osal_mem_free(off_ctrl_params); + nrf_wifi_osal_mem_free(off_tx_params); + k_spin_unlock(&off_raw_tx_drv_priv.lock, key); + return ret; +} + + +int nrf70_off_raw_tx_start(struct nrf_wifi_off_raw_tx_conf *conf) +{ + int ret = -1; + enum nrf_wifi_status status = NRF_WIFI_STATUS_FAIL; + k_spinlock_key_t key; + + status = nrf70_off_raw_tx_conf_update(conf); + if (status != NRF_WIFI_STATUS_SUCCESS) { + LOG_ERR("%s: nRF70 offloaded raw TX configuration failed", + __func__); + goto out; + } + + key = k_spin_lock(&off_raw_tx_drv_priv.lock); + if (!off_raw_tx_drv_priv.rpu_ctx_zep.rpu_ctx) { + LOG_ERR("%s: FMAC device context is NULL", __func__); + goto out; + } + + status = nrf_wifi_fmac_off_raw_tx_start(off_raw_tx_drv_priv.rpu_ctx_zep.rpu_ctx); + if (status != NRF_WIFI_STATUS_SUCCESS) { + LOG_ERR("%s: nRF70 offloaded raw TX start failed", + __func__); + goto out; + } + + ret = 0; +out: + k_spin_unlock(&off_raw_tx_drv_priv.lock, key); + return ret; +} + + +int nrf70_off_raw_tx_stop(void) +{ + int ret = -1; + enum nrf_wifi_status status = NRF_WIFI_STATUS_FAIL; + k_spinlock_key_t key; + + key = k_spin_lock(&off_raw_tx_drv_priv.lock); + + if (!off_raw_tx_drv_priv.rpu_ctx_zep.rpu_ctx) { + LOG_ERR("%s: FMAC device context is NULL", __func__); + goto out; + } + + status = nrf_wifi_fmac_off_raw_tx_stop(off_raw_tx_drv_priv.rpu_ctx_zep.rpu_ctx); + if (status != NRF_WIFI_STATUS_SUCCESS) { + LOG_ERR("%s: nRF70 offloaded raw TX stop failed", + __func__); + goto out; + } + + ret = 0; +out: + k_spin_unlock(&off_raw_tx_drv_priv.lock, key); + return ret; +} + + +int nrf70_off_raw_tx_mac_addr_get(uint8_t *mac_addr) +{ + if (!mac_addr) { + LOG_ERR("%s: Invalid param", __func__); + return -EINVAL; + } + + memcpy(mac_addr, off_raw_tx_drv_priv.rpu_ctx_zep.mac_addr, 6); + return 0; +} + +int nrf70_off_raw_tx_stats(struct nrf_wifi_off_raw_tx_stats *off_raw_tx_stats) +{ + int ret = -1; + enum nrf_wifi_status status = NRF_WIFI_STATUS_FAIL; + struct rpu_op_stats stats; + k_spinlock_key_t key; + + memset(&stats, 0, sizeof(struct rpu_op_stats)); + + key = k_spin_lock(&off_raw_tx_drv_priv.lock); + + if (!off_raw_tx_drv_priv.rpu_ctx_zep.rpu_ctx) { + LOG_ERR("%s: FMAC device context is NULL", __func__); + goto out; + } + + status = nrf_wifi_fmac_stats_get(off_raw_tx_drv_priv.rpu_ctx_zep.rpu_ctx, 0, &stats); + if (status != NRF_WIFI_STATUS_SUCCESS) { + LOG_ERR("%s: nRF70 offloaded raw TX stats failed", + __func__); + goto out; + } + + off_raw_tx_stats->off_raw_tx_pkt_sent = stats.fw.offloaded_raw_tx.offload_raw_tx_cnt; + + ret = 0; +out: + k_spin_unlock(&off_raw_tx_drv_priv.lock, key); + return ret; +} diff --git a/include/zephyr/drivers/wifi/nrfwifi/off_raw_tx/off_raw_tx_api.h b/include/zephyr/drivers/wifi/nrfwifi/off_raw_tx/off_raw_tx_api.h new file mode 100644 index 00000000000..b8ff50cd390 --- /dev/null +++ b/include/zephyr/drivers/wifi/nrfwifi/off_raw_tx/off_raw_tx_api.h @@ -0,0 +1,260 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ +/** @file + * + * @addtogroup nrf70_off_raw_tx_api nRF70 Offloaded raw TX API + * @{ + * + * @brief File containing API's for the Offloaded raw TX feature. + */ + +#ifndef INCLUDE_ZEPHYR_DRIVERS_OFF_RAW_TX_API_H_ +#define INCLUDE_ZEPHYR_DRIVERS_OFF_RAW_TX_API_H_ + +#include +#include +#include "osal_api.h" + +/* Minimum frame size for raw packet transmission */ +#define NRF_WIFI_OFF_RAW_TX_FRAME_SIZE_MIN 26 +/* Maximum frame size for raw packet transmission */ +#define NRF_WIFI_OFF_RAW_TX_FRAME_SIZE_MAX 600 + +/** + * @brief- Transmission rates + * Rate to be used for transmitting a packet. + */ +enum nrf_wifi_off_raw_tx_rate { + /** 1 Mbps */ + RATE_1M, + /** 2 Mbps */ + RATE_2M, + /** 5.5 Mbps */ + RATE_5_5M, + /** 11 Mbps */ + RATE_11M, + /** 6 Mbps */ + RATE_6M, + /** 9 Mbps */ + RATE_9M, + /** 12 Mbps */ + RATE_12M, + /** 18 Mbps */ + RATE_18M, + /** 24 Mbps */ + RATE_24M, + /** 36 Mbps */ + RATE_36M, + /** 48 Mbps */ + RATE_48M, + /** 54 Mbps */ + RATE_54M, + /** MCS 0 */ + RATE_MCS0, + /** MCS 1 */ + RATE_MCS1, + /** MCS 2 */ + RATE_MCS2, + /** MCS 3 */ + RATE_MCS3, + /** MCS 4 */ + RATE_MCS4, + /** MCS 5 */ + RATE_MCS5, + /** MCS 6 */ + RATE_MCS6, + /** MCS 7 */ + RATE_MCS7, + /** Invalid rate */ + RATE_MAX +}; + + +/** + * @brief- HE guard interval value + * Value of the guard interval to be used between symbols when transmitting using HE. + */ +enum nrf_wifi_off_raw_tx_he_gi { + /** 800 ns */ + HE_GI_800NS, + /** 1600 ns */ + HE_GI_1600NS, + /** 3200 ns */ + HE_GI_3200NS, + /** Invalid value */ + HE_GI_MAX +}; + + +/** + * @brief- HE long training field duration + * Value of the long training field duration to be used when transmitting using HE. + */ +enum nrf_wifi_off_raw_tx_he_ltf { + /** 3.2us */ + HE_LTF_3200NS, + /** 6.4us */ + HE_LTF_6400NS, + /** 12.8us */ + HE_LTF_12800NS, + /** Invalid value */ + HE_LTF_MAX +}; + +/** + * @brief- Throughput mode + * Throughput mode to be used for transmitting the packet. + */ +enum nrf_wifi_off_raw_tx_tput_mode { + /** Legacy mode */ + TPUT_MODE_LEGACY, + /** High Throughput mode (11n) */ + TPUT_MODE_HT, + /** Very high throughput mode (11ac) */ + TPUT_MODE_VHT, + /** HE SU mode */ + TPUT_MODE_HE_SU, + /** HE ER SU mode */ + TPUT_MODE_HE_ER_SU, + /** HE TB mode */ + TPUT_MODE_HE_TB, + /** Highest throughput mode currently defined */ + TPUT_MODE_MAX +}; + +/** + * @brief This structure defines the Offloaded raw tx debug statistics. + * + */ +struct nrf_wifi_off_raw_tx_stats { + /** Number of packets sent */ + unsigned int off_raw_tx_pkt_sent; +}; + +/** + * @brief- Configuration parameters for offloaded raw TX + * Parameters which can be used to configure the offloaded raw TX operation. + */ +struct nrf_wifi_off_raw_tx_conf { + /** Time interval (in microseconds) between transmissions */ + unsigned int period_us; + /** Transmit power in dBm (0 to 20) */ + unsigned int tx_pwr; + /** Channel number on which to transmit */ + unsigned int chan; + /** Set to TRUE to use short preamble for FALSE to disable short preamble */ + bool short_preamble; + /* Number of times a packet should be retried at each possible rate */ + unsigned int num_retries; + /** Throughput mode for packet transmittion. Refer &enum nrf_wifi_off_raw_tx_tput_mode */ + enum nrf_wifi_off_raw_tx_tput_mode tput_mode; + /* Rate at which packet needs to be transmitted. Refer &enum nrf_wifi_off_raw_tx_rate */ + enum nrf_wifi_off_raw_tx_rate rate; + /** HE GI. Refer &enum nrf_wifi_off_raw_tx_he_gi */ + enum nrf_wifi_off_raw_tx_he_gi he_gi; + /** HE GI. Refer &enum nrf_wifi_off_raw_tx_he_ltf */ + enum nrf_wifi_off_raw_tx_he_ltf he_ltf; + /* Pointer to packet to be transmitted */ + void *pkt; + /** Packet length of the frame to be transmitted, (min 26 bytes and max 600 bytes) */ + unsigned int pkt_len; +}; + + +/** + * @brief Initialize the nRF70 for operating in the offloaded raw TX mode. + * @param mac_addr MAC address to be used for the nRF70 device. + * + * This function is initializes the nRF70 device for offloaded raw TX mode by: + * - Powering it up, + * - Downloading a firmware patch (if any). + * - Initializing the firmware to accept further commands + * + * The mac_addr parameter is used to set the MAC address of the nRF70 device. + * This address can be used to override the MAC addresses programmed in the OTP and + * the value configured (if any) in CONFIG_WIFI_FIXED_MAC_ADDRESS. + * The priority order in which the MAC address values for the nRF70 device are used is: + * - If mac_addr is provided, the MAC address is set to the value provided. + * - If CONFIG_WIFI_FIXED_MAC_ADDRESS is enabled, the MAC address uses the Kconfig value. + * - If none of the above are provided, the MAC address is set to the value programmed in the OTP. + * + * @retval 0 If the operation was successful. + * @retval -1 If the operation failed. + */ +int nrf70_off_raw_tx_init(uint8_t *mac_addr); + +/** + * @brief Initialize the nRF70 for operating in the offloaded raw TX mode. + * + * This function is deinitializes the nRF70 device. + * + */ +void nrf70_off_raw_tx_deinit(void); + +/** + * @brief Update the configured offloaded raw TX parameters. + * @param conf Configuration parameters to be updated for the offloaded raw TX operation. + * + * This function is used to update configured parameters for offloaded raw TX operation. + * This function should be used to when the parameters need to be updated during an ongoing + * raw TX operation without having to stop it. + * + * @retval 0 If the operation was successful. + * @retval -1 If the operation failed. + */ +int nrf70_off_raw_tx_conf_update(struct nrf_wifi_off_raw_tx_conf *conf); + +/** + * @brief Start the offloaded raw TX. + * @param conf Configuration parameters necessary for the offloaded raw TX operation. + * + * This function is used to start offloaded raw TX operation. When this function is invoked + * the nRF70 device will start transmitting frames as per the configuration specified by @p conf. + * + * @retval 0 If the operation was successful. + * @retval -1 If the operation failed. + */ +int nrf70_off_raw_tx_start(struct nrf_wifi_off_raw_tx_conf *conf); + +/** + * @brief Stop the offloaded raw TX. + * + * This function is used to stop offloaded raw TX operation. When this function is invoked + * the nRF70 device will stop transmitting frames. + * + * @retval 0 If the operation was successful. + * @retval -1 If the operation failed. + */ +int nrf70_off_raw_tx_stop(void); + +/** + * @brief Get the MAC address of the nRF70 device. + * @param mac_addr Buffer to store the MAC address. + * + * This function is used to get the MAC address of the nRF70 device. + * The MAC address is stored in the buffer pointed by mac_addr. + * The MAC address is expected to be a 6 byte value. + * + * @retval 0 If the operation was successful. + * @retval -1 If the operation failed. + */ +int nrf70_off_raw_tx_mac_addr_get(uint8_t *mac_addr); + +/** + * @brief Get statistics of the offloaded raw TX. + * @param off_raw_tx_stats Statistics of the offloaded raw TX operation. + * + * This function is used to get statistics of offloaded raw TX operation. When this function + * is invoked the nRF70 device will show statistics. + * + * @retval 0 If the operation was successful. + * @retval -1 If the operation failed. + */ +int nrf70_off_raw_tx_stats(struct nrf_wifi_off_raw_tx_stats *off_raw_tx_stats); +/** + * @} + */ +#endif /* INCLUDE_ZEPHYR_DRIVERS_OFF_RAW_TX_API_H_ */ From df2a63ebc3802c2406aa9f3f65fdaebd5b96d37d Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Thu, 24 Oct 2024 22:11:07 +0530 Subject: [PATCH 028/299] Revert "[nrf fromtree] drivers: nrfwifi: Use Zephyr tooling to load nRF70 FW file" This reverts commit fe2288dd018c9ea83742c8ef3cc00e45356d8602. Signed-off-by: Chaitanya Tata --- drivers/wifi/nrfwifi/CMakeLists.txt | 11 ++----- drivers/wifi/nrfwifi/src/fw_load.c | 49 ++++++++++++++++++++++++++--- 2 files changed, 48 insertions(+), 12 deletions(-) diff --git a/drivers/wifi/nrfwifi/CMakeLists.txt b/drivers/wifi/nrfwifi/CMakeLists.txt index 5ea9da5825e..da458d13a9a 100644 --- a/drivers/wifi/nrfwifi/CMakeLists.txt +++ b/drivers/wifi/nrfwifi/CMakeLists.txt @@ -4,7 +4,7 @@ # SPDX-License-Identifier: Apache-2.0 # -zephyr_library_named(nrfwifi) +zephyr_library() set(OS_AGNOSTIC_BASE ${ZEPHYR_HAL_NORDIC_MODULE_DIR}/drivers/nrf_wifi) set(FW_BINS_BASE ${ZEPHYR_HAL_NORDIC_MODULE_DIR}/zephyr/blobs/wifi_fw_bins) @@ -184,13 +184,8 @@ elseif(CONFIG_NRF_WIFI_PATCHES_BUILTIN) ------------------------------------------------------------------------") endif() - set(gen_inc_dir ${ZEPHYR_BINARY_DIR}/misc/generated) - zephyr_include_directories(${gen_inc_dir}) - set(gen_dir ${gen_inc_dir}/nrf70_fw_patch) - generate_inc_file_for_target( - nrfwifi - ${NRF70_PATCH} - ${gen_dir}/nrf70.bin.inc + zephyr_compile_definitions( + -DCONFIG_NRF_WIFI_FW_BIN=${NRF70_PATCH} ) endif() diff --git a/drivers/wifi/nrfwifi/src/fw_load.c b/drivers/wifi/nrfwifi/src/fw_load.c index 9204d295d30..6bf4c85193f 100644 --- a/drivers/wifi/nrfwifi/src/fw_load.c +++ b/drivers/wifi/nrfwifi/src/fw_load.c @@ -17,16 +17,57 @@ LOG_MODULE_DECLARE(wifi_nrf, CONFIG_WIFI_NRF70_LOG_LEVEL); #include -static const char fw_patch[] = { - #include -}; + +/* INCBIN macro Taken from https://gist.github.com/mmozeiko/ed9655cf50341553d282 */ +#define STR2(x) #x +#define STR(x) STR2(x) + +#ifdef __APPLE__ +#define USTR(x) "_" STR(x) +#else +#define USTR(x) STR(x) +#endif + +#ifdef _WIN32 +#define INCBIN_SECTION ".rdata, \"dr\"" +#elif defined __APPLE__ +#define INCBIN_SECTION "__TEXT,__const" +#else +#define INCBIN_SECTION ".rodata.*" +#endif + +/* this aligns start address to 16 and terminates byte array with explicit 0 + * which is not really needed, feel free to change it to whatever you want/need + */ +#define INCBIN(prefix, name, file) \ + __asm__(".section " INCBIN_SECTION "\n" \ + ".global " USTR(prefix) "_" STR(name) "_start\n" \ + ".balign 16\n" \ + USTR(prefix) "_" STR(name) "_start:\n" \ + ".incbin \"" file "\"\n" \ + \ + ".global " STR(prefix) "_" STR(name) "_end\n" \ + ".balign 1\n" \ + USTR(prefix) "_" STR(name) "_end:\n" \ + ".byte 0\n" \ + ); \ + extern __aligned(16) const char prefix ## _ ## name ## _start[]; \ + extern const char prefix ## _ ## name ## _end[]; + +INCBIN(_bin, nrf70_fw, STR(CONFIG_NRF_WIFI_FW_BIN)); enum nrf_wifi_status nrf_wifi_fw_load(void *rpu_ctx) { enum nrf_wifi_status status = NRF_WIFI_STATUS_FAIL; struct nrf_wifi_fmac_fw_info fw_info = { 0 }; + uint8_t *fw_start; + uint8_t *fw_end; + + fw_start = (uint8_t *)_bin_nrf70_fw_start; + fw_end = (uint8_t *)_bin_nrf70_fw_end; - status = nrf_wifi_fmac_fw_parse(rpu_ctx, fw_patch, sizeof(fw_patch), &fw_info); + status = nrf_wifi_fmac_fw_parse(rpu_ctx, fw_start, fw_end - fw_start, + &fw_info); if (status != NRF_WIFI_STATUS_SUCCESS) { LOG_ERR("%s: nrf_wifi_fmac_fw_parse failed", __func__); return status; From 49ef1c16bedf217d177c09e0a0e72cbfca7f96ec Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Sun, 6 Oct 2024 01:15:15 +0530 Subject: [PATCH 029/299] [nrf fromtree] drivers: nrfwifi: Fix rebuilding when FW blobs are changes Whenever FW blobs are updated manually, we need to tell cmake to auto-build the source files to use the latest firmware without doing a pristine build. This adds a custom target to be run with nRF Wi-Fi driver and updates timestamp of fw_load.c to rebuild whenevr the blob is updated. Signed-off-by: Chaitanya Tata (cherry picked from commit e2e96acebfef43fe619d315587592b8885a1187e) --- drivers/wifi/nrfwifi/CMakeLists.txt | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/drivers/wifi/nrfwifi/CMakeLists.txt b/drivers/wifi/nrfwifi/CMakeLists.txt index da458d13a9a..04d8d7f2bb4 100644 --- a/drivers/wifi/nrfwifi/CMakeLists.txt +++ b/drivers/wifi/nrfwifi/CMakeLists.txt @@ -4,7 +4,7 @@ # SPDX-License-Identifier: Apache-2.0 # -zephyr_library() +zephyr_library_named(nrfwifi) set(OS_AGNOSTIC_BASE ${ZEPHYR_HAL_NORDIC_MODULE_DIR}/drivers/nrf_wifi) set(FW_BINS_BASE ${ZEPHYR_HAL_NORDIC_MODULE_DIR}/zephyr/blobs/wifi_fw_bins) @@ -187,6 +187,22 @@ elseif(CONFIG_NRF_WIFI_PATCHES_BUILTIN) zephyr_compile_definitions( -DCONFIG_NRF_WIFI_FW_BIN=${NRF70_PATCH} ) + + # Rebuild fw_load.c whenever the firmware binary changes + # a bit crude way to do it, but it works + add_custom_command( + OUTPUT ${CMAKE_SOURCE_DIR}/src/fw_load.c + COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_SOURCE_DIR}/src/fw_load.c + DEPENDS ${NRF70_PATCH} + COMMENT "Checking firmware blobs ${NRF70_PATCH}" + ) + + add_custom_target( + check_firmware_blobs ALL + DEPENDS ${CMAKE_SOURCE_DIR}/src/fw_load.c + ) + + add_dependencies(nrfwifi check_firmware_blobs) endif() From 4c14fdc88a19de7c5816899fc18fa355d547da18 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Wed, 9 Oct 2024 23:16:38 +0530 Subject: [PATCH 030/299] [nrf fromtree] Revert "drivers: nrfwifi: Fix rebuilding when FW blobs are changes" This reverts commit e2e96acebfef43fe619d315587592b8885a1187e. This will be properly fixes by adding a target for nRF70.bin and removing INCBIN approach. Signed-off-by: Chaitanya Tata (cherry picked from commit 7f9be548970627306b8bdb65202a1c0f5754d9d2) --- drivers/wifi/nrfwifi/CMakeLists.txt | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/drivers/wifi/nrfwifi/CMakeLists.txt b/drivers/wifi/nrfwifi/CMakeLists.txt index 04d8d7f2bb4..da458d13a9a 100644 --- a/drivers/wifi/nrfwifi/CMakeLists.txt +++ b/drivers/wifi/nrfwifi/CMakeLists.txt @@ -4,7 +4,7 @@ # SPDX-License-Identifier: Apache-2.0 # -zephyr_library_named(nrfwifi) +zephyr_library() set(OS_AGNOSTIC_BASE ${ZEPHYR_HAL_NORDIC_MODULE_DIR}/drivers/nrf_wifi) set(FW_BINS_BASE ${ZEPHYR_HAL_NORDIC_MODULE_DIR}/zephyr/blobs/wifi_fw_bins) @@ -187,22 +187,6 @@ elseif(CONFIG_NRF_WIFI_PATCHES_BUILTIN) zephyr_compile_definitions( -DCONFIG_NRF_WIFI_FW_BIN=${NRF70_PATCH} ) - - # Rebuild fw_load.c whenever the firmware binary changes - # a bit crude way to do it, but it works - add_custom_command( - OUTPUT ${CMAKE_SOURCE_DIR}/src/fw_load.c - COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_SOURCE_DIR}/src/fw_load.c - DEPENDS ${NRF70_PATCH} - COMMENT "Checking firmware blobs ${NRF70_PATCH}" - ) - - add_custom_target( - check_firmware_blobs ALL - DEPENDS ${CMAKE_SOURCE_DIR}/src/fw_load.c - ) - - add_dependencies(nrfwifi check_firmware_blobs) endif() From b2e80b47f4ea7eac75b3a9c9aa836a82e2c6e6dd Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Wed, 9 Oct 2024 23:52:44 +0530 Subject: [PATCH 031/299] [nrf fromtree] drivers: nrfwifi: Use Zephyr tooling to load nRF70 FW file Instead of relying on INCBIN macros which do not properly add dependencies, e.g., modifying FW file doesn't trigger rebuild. Use the Zephyr cmake tooling to load the FW patch file as a header. This also improves memory report where the patch target is clearly visible instead of a hidden section. Signed-off-by: Chaitanya Tata (cherry picked from commit b40cb4c46c093c20aba59034b385786e871560fd) --- drivers/wifi/nrfwifi/CMakeLists.txt | 11 +++++-- drivers/wifi/nrfwifi/src/fw_load.c | 49 +++-------------------------- 2 files changed, 12 insertions(+), 48 deletions(-) diff --git a/drivers/wifi/nrfwifi/CMakeLists.txt b/drivers/wifi/nrfwifi/CMakeLists.txt index da458d13a9a..5ea9da5825e 100644 --- a/drivers/wifi/nrfwifi/CMakeLists.txt +++ b/drivers/wifi/nrfwifi/CMakeLists.txt @@ -4,7 +4,7 @@ # SPDX-License-Identifier: Apache-2.0 # -zephyr_library() +zephyr_library_named(nrfwifi) set(OS_AGNOSTIC_BASE ${ZEPHYR_HAL_NORDIC_MODULE_DIR}/drivers/nrf_wifi) set(FW_BINS_BASE ${ZEPHYR_HAL_NORDIC_MODULE_DIR}/zephyr/blobs/wifi_fw_bins) @@ -184,8 +184,13 @@ elseif(CONFIG_NRF_WIFI_PATCHES_BUILTIN) ------------------------------------------------------------------------") endif() - zephyr_compile_definitions( - -DCONFIG_NRF_WIFI_FW_BIN=${NRF70_PATCH} + set(gen_inc_dir ${ZEPHYR_BINARY_DIR}/misc/generated) + zephyr_include_directories(${gen_inc_dir}) + set(gen_dir ${gen_inc_dir}/nrf70_fw_patch) + generate_inc_file_for_target( + nrfwifi + ${NRF70_PATCH} + ${gen_dir}/nrf70.bin.inc ) endif() diff --git a/drivers/wifi/nrfwifi/src/fw_load.c b/drivers/wifi/nrfwifi/src/fw_load.c index 6bf4c85193f..9204d295d30 100644 --- a/drivers/wifi/nrfwifi/src/fw_load.c +++ b/drivers/wifi/nrfwifi/src/fw_load.c @@ -17,57 +17,16 @@ LOG_MODULE_DECLARE(wifi_nrf, CONFIG_WIFI_NRF70_LOG_LEVEL); #include - -/* INCBIN macro Taken from https://gist.github.com/mmozeiko/ed9655cf50341553d282 */ -#define STR2(x) #x -#define STR(x) STR2(x) - -#ifdef __APPLE__ -#define USTR(x) "_" STR(x) -#else -#define USTR(x) STR(x) -#endif - -#ifdef _WIN32 -#define INCBIN_SECTION ".rdata, \"dr\"" -#elif defined __APPLE__ -#define INCBIN_SECTION "__TEXT,__const" -#else -#define INCBIN_SECTION ".rodata.*" -#endif - -/* this aligns start address to 16 and terminates byte array with explicit 0 - * which is not really needed, feel free to change it to whatever you want/need - */ -#define INCBIN(prefix, name, file) \ - __asm__(".section " INCBIN_SECTION "\n" \ - ".global " USTR(prefix) "_" STR(name) "_start\n" \ - ".balign 16\n" \ - USTR(prefix) "_" STR(name) "_start:\n" \ - ".incbin \"" file "\"\n" \ - \ - ".global " STR(prefix) "_" STR(name) "_end\n" \ - ".balign 1\n" \ - USTR(prefix) "_" STR(name) "_end:\n" \ - ".byte 0\n" \ - ); \ - extern __aligned(16) const char prefix ## _ ## name ## _start[]; \ - extern const char prefix ## _ ## name ## _end[]; - -INCBIN(_bin, nrf70_fw, STR(CONFIG_NRF_WIFI_FW_BIN)); +static const char fw_patch[] = { + #include +}; enum nrf_wifi_status nrf_wifi_fw_load(void *rpu_ctx) { enum nrf_wifi_status status = NRF_WIFI_STATUS_FAIL; struct nrf_wifi_fmac_fw_info fw_info = { 0 }; - uint8_t *fw_start; - uint8_t *fw_end; - - fw_start = (uint8_t *)_bin_nrf70_fw_start; - fw_end = (uint8_t *)_bin_nrf70_fw_end; - status = nrf_wifi_fmac_fw_parse(rpu_ctx, fw_start, fw_end - fw_start, - &fw_info); + status = nrf_wifi_fmac_fw_parse(rpu_ctx, fw_patch, sizeof(fw_patch), &fw_info); if (status != NRF_WIFI_STATUS_SUCCESS) { LOG_ERR("%s: nrf_wifi_fmac_fw_parse failed", __func__); return status; From 412275dbd08154d5a78448a98b2551965020c586 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Mon, 8 Jul 2024 22:42:56 +0530 Subject: [PATCH 032/299] [nrf fromtree] drivers: wifi: Fix RPU recovery not being triggered During watchdog (or any) interrupt processing, RPU accesses are being made and they assert the wakeup_now flag this causes RPU recovery to not trigger. New false or true recovery detection algo: Check the time difference b/w last de-assert and assert, and if it exceeds minimum time needed for RPU to enter sleep, then not the timestamp. This timestamp will be used to compare when a watchdog interrupt is received and see if during the last window if host has given a chance for RPU to attempt sleep, if yes, then attempt recovery else ignore watchdog. Also, add a Kconfig for the 10s active time that triggers recovery, this needs to be passed to the FW (once we have enough patch memory). Also, add a Kconfig for the minimum time needed for RPU to attempt sleep in positive case. Also, add a new _ms API for time stamp fetch, this is to avoid precision loss when converting to and from ms to us and also makes code readable by avoiding *1000 and /1000. Signed-off-by: Chaitanya Tata (cherry picked from commit 5ad733931154799108b0e2e81fce4228770327fa) --- drivers/wifi/nrfwifi/Kconfig.nrfwifi | 26 ++++++++++++++++++++++++++ drivers/wifi/nrfwifi/src/shim.c | 16 ++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/drivers/wifi/nrfwifi/Kconfig.nrfwifi b/drivers/wifi/nrfwifi/Kconfig.nrfwifi index ce7e0b753f8..9d8fad2daaa 100644 --- a/drivers/wifi/nrfwifi/Kconfig.nrfwifi +++ b/drivers/wifi/nrfwifi/Kconfig.nrfwifi @@ -677,6 +677,32 @@ config NRF_WIFI_RPU_RECOVERY_PROPAGATION_DELAY_MS config NET_MGMT_EVENT_QUEUE_SIZE # Doing interface down and up even with delay puts a lot of events in the queue default 16 + +config NRF_WIFI_RPU_RECOVERY_PROPAGATION_DELAY_MS + int "RPU recovery propagation delay in milliseconds" + default 10 + help + Propagation delay in milliseconds to wait after RPU is powered down + before powering it up. This delay is required to ensure that the recovery + is propagated to all the applications and stack and have enough time to + clean up the resources. + +config NRF_WIFI_RPU_RECOVERY_PS_ACTIVE_TIMEOUT_MS + int "RPU recovery power save active timeout in milliseconds" + default 10000 + help + Power save active timeout in milliseconds after which RPU recovery + mechanism will be triggered. This timeout is used to ensure that the + RPU attempts to enter power save mode in case of inactivity. + +config NRF_WIFI_RPU_MIN_TIME_TO_ENTER_SLEEP_MS + int "Minimum idle time to enter sleep in milliseconds" + range 100 5000 + default 1000 + help + Minimum time the host should de-assert WAKEUP_NOW and let RPU enter + sleep mode, assuming there is no activity. + endif # NRF_WIFI_RPU_RECOVERY config NRF_WIFI_FEAT_WMM diff --git a/drivers/wifi/nrfwifi/src/shim.c b/drivers/wifi/nrfwifi/src/shim.c index 19660f727e7..9f8b065ead0 100644 --- a/drivers/wifi/nrfwifi/src/shim.c +++ b/drivers/wifi/nrfwifi/src/shim.c @@ -618,6 +618,20 @@ static unsigned int zep_shim_time_elapsed_us(unsigned long start_time_us) return curr_time_us - start_time_us; } +static unsigned long zep_shim_time_get_curr_ms(void) +{ + return k_uptime_get(); +} + +static unsigned int zep_shim_time_elapsed_ms(unsigned long start_time_ms) +{ + unsigned long curr_time_ms = 0; + + curr_time_ms = zep_shim_time_get_curr_ms(); + + return curr_time_ms - start_time_ms; +} + static enum nrf_wifi_status zep_shim_bus_qspi_dev_init(void *os_qspi_dev_ctx) { ARG_UNUSED(os_qspi_dev_ctx); @@ -938,6 +952,8 @@ const struct nrf_wifi_osal_ops nrf_wifi_os_zep_ops = { .delay_us = k_usleep, .time_get_curr_us = zep_shim_time_get_curr_us, .time_elapsed_us = zep_shim_time_elapsed_us, + .time_get_curr_ms = zep_shim_time_get_curr_ms, + .time_elapsed_ms = zep_shim_time_elapsed_ms, .bus_qspi_init = zep_shim_bus_qspi_init, .bus_qspi_deinit = zep_shim_bus_qspi_deinit, From f538932e8e12f5e8dde88b88cd6aeaab44841a31 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Tue, 9 Jul 2024 22:51:15 +0530 Subject: [PATCH 033/299] [nrf fromtree] drivers: wifi: nrf700x: Ignore all failures in iface down In case RPU is stuck and need a recovery, the failures in interface down should be ignored as they are expected and we should proceed with device removal that in turn removes power to the RPU. TODO: This works for single VIF, but needs more thought for multi-VIF. Signed-off-by: Chaitanya Tata (cherry picked from commit 04ddd6d2b04207d868563b8847e70c720def4e70) --- drivers/wifi/nrfwifi/src/net_if.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/drivers/wifi/nrfwifi/src/net_if.c b/drivers/wifi/nrfwifi/src/net_if.c index 4d4125e8c8a..899e9a87105 100644 --- a/drivers/wifi/nrfwifi/src/net_if.c +++ b/drivers/wifi/nrfwifi/src/net_if.c @@ -802,14 +802,14 @@ int nrf_wifi_if_stop_zep(const struct device *dev) ret = k_mutex_lock(&vif_ctx_zep->vif_lock, K_FOREVER); if (ret != 0) { LOG_ERR("%s: Failed to lock vif_lock", __func__); - goto out; + goto unlock; } rpu_ctx_zep = vif_ctx_zep->rpu_ctx_zep; if (!rpu_ctx_zep) { LOG_ERR("%s: rpu_ctx_zep is NULL", __func__); - goto out; + goto unlock; } #ifdef CONFIG_NRF70_STA_MODE @@ -821,7 +821,6 @@ int nrf_wifi_if_stop_zep(const struct device *dev) if (status != NRF_WIFI_STATUS_SUCCESS) { LOG_ERR("%s: nrf_wifi_fmac_set_power_save failed", __func__); - goto unlock; } #endif /* CONFIG_NRF_WIFI_LOW_POWER */ #endif /* CONFIG_NRF70_STA_MODE */ @@ -840,7 +839,6 @@ int nrf_wifi_if_stop_zep(const struct device *dev) if (status != NRF_WIFI_STATUS_SUCCESS) { LOG_ERR("%s: nrf_wifi_fmac_chg_vif_state failed", __func__); - goto unlock; } status = nrf_wifi_fmac_del_vif(rpu_ctx_zep->rpu_ctx, @@ -849,11 +847,8 @@ int nrf_wifi_if_stop_zep(const struct device *dev) if (status != NRF_WIFI_STATUS_SUCCESS) { LOG_ERR("%s: nrf_wifi_fmac_del_vif failed", __func__); - goto unlock; } - vif_ctx_zep->if_op_state = NRF_WIFI_FMAC_IF_OP_STATE_DOWN; - if (nrf_wifi_fmac_get_num_vifs(rpu_ctx_zep->rpu_ctx) == 0) { nrf_wifi_fmac_dev_rem_zep(&rpu_drv_priv_zep); } From b7e1245536821344a566157caaaca96f1b755ddd Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Wed, 10 Jul 2024 00:51:59 +0530 Subject: [PATCH 034/299] [nrf fromtree] drivers: wifi: Add a sanity check for RPU comms Before proceeding with RPU bringup, do a sanity check by reading a known signature to make sure the Host-RPU comms are operational. Signed-off-by: Chaitanya Tata (cherry picked from commit a23184c473764babf4d3ec8985267caa1c494c88) --- drivers/wifi/nrfwifi/src/qspi/src/rpu_hw_if.c | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/drivers/wifi/nrfwifi/src/qspi/src/rpu_hw_if.c b/drivers/wifi/nrfwifi/src/qspi/src/rpu_hw_if.c index c5f909b4c3a..6fac7412362 100644 --- a/drivers/wifi/nrfwifi/src/qspi/src/rpu_hw_if.c +++ b/drivers/wifi/nrfwifi/src/qspi/src/rpu_hw_if.c @@ -405,6 +405,31 @@ int rpu_clks_on(void) return 0; } +#define RPU_EXP_SIG 0x42000020 +/* Read a known value from RPU memory to validate RPU communication */ +int rpu_validate_comms(void) +{ + uint32_t rpu_test; + int ret; + + /* UCCP_SOC_FAB_MST_READ_IDLE - HW reset value */ + ret = rpu_read(0x0005C, &rpu_test, 4); + if (ret) { + LOG_ERR("Error: RPU comms test: read failed\n"); + return ret; + } + + if (rpu_test != RPU_EXP_SIG) { + LOG_ERR("Error: RPU comms test: sig failed: expected 0x%x, got 0x%x\n", + RPU_EXP_SIG, rpu_test); + return -1; + } + + LOG_DBG("RPU comms test passed\n"); + + return 0; +} + int rpu_init(void) { int ret; @@ -458,6 +483,11 @@ int rpu_enable(void) goto rpu_pwroff; } + ret = rpu_validate_comms(); + if (ret) { + goto rpu_pwroff; + } + return 0; rpu_pwroff: rpu_pwroff(); From feae43925a7c5b1c91c5bdee943dba333a80f24c Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Wed, 10 Jul 2024 00:56:32 +0530 Subject: [PATCH 035/299] [nrf fromtree] drivers: wifi: Add support for separate debugs for RPU recovery These are helpful for debugging RPU recovery only. Signed-off-by: Chaitanya Tata (cherry picked from commit 1e5db78afc6ba25412dd74aae09ecdf56ece5f22) --- drivers/wifi/nrfwifi/Kconfig.nrfwifi | 5 +++++ drivers/wifi/nrfwifi/src/net_if.c | 30 ++++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/drivers/wifi/nrfwifi/Kconfig.nrfwifi b/drivers/wifi/nrfwifi/Kconfig.nrfwifi index 9d8fad2daaa..a3f42a32198 100644 --- a/drivers/wifi/nrfwifi/Kconfig.nrfwifi +++ b/drivers/wifi/nrfwifi/Kconfig.nrfwifi @@ -703,6 +703,11 @@ config NRF_WIFI_RPU_MIN_TIME_TO_ENTER_SLEEP_MS Minimum time the host should de-assert WAKEUP_NOW and let RPU enter sleep mode, assuming there is no activity. +config NRF_WIFI_RPU_RECOVERY_DEBUG + bool "RPU recovery debug logs" + help + Enable RPU recovery debug logs to help debug RPU recovery mechanism. + endif # NRF_WIFI_RPU_RECOVERY config NRF_WIFI_FEAT_WMM diff --git a/drivers/wifi/nrfwifi/src/net_if.c b/drivers/wifi/nrfwifi/src/net_if.c index 899e9a87105..3170b67b975 100644 --- a/drivers/wifi/nrfwifi/src/net_if.c +++ b/drivers/wifi/nrfwifi/src/net_if.c @@ -71,6 +71,7 @@ static void nrf_wifi_rpu_recovery_work_handler(struct k_work *work) struct nrf_wifi_vif_ctx_zep, nrf_wifi_rpu_recovery_work); struct nrf_wifi_ctx_zep *rpu_ctx_zep = NULL; + int ret; if (!vif_ctx_zep) { LOG_ERR("%s: vif_ctx_zep is NULL", __func__); @@ -88,14 +89,39 @@ static void nrf_wifi_rpu_recovery_work_handler(struct k_work *work) return; } +#ifdef CONFIG_NRF_WIFI_RPU_RECOVERY_DEBUG + LOG_ERR("%s: Starting RPU recovery", __func__); +#else + LOG_DBG("%s: Starting RPU recovery", __func__); +#endif k_mutex_lock(&rpu_ctx_zep->rpu_lock, K_FOREVER); +#ifdef CONFIG_NRF_WIFI_RPU_RECOVERY_DEBUG + LOG_ERR("%s: Bringing the interface down", __func__); +#else LOG_DBG("%s: Bringing the interface down", __func__); +#endif /* This indirectly does a cold-boot of RPU */ - net_if_down(vif_ctx_zep->zep_net_if_ctx); + ret = net_if_down(vif_ctx_zep->zep_net_if_ctx); + if (ret) { + LOG_ERR("%s: net_if_down failed: %d", __func__, ret); + /* Continue with the recovery */ + } k_msleep(CONFIG_NRF_WIFI_RPU_RECOVERY_PROPAGATION_DELAY_MS); +#ifdef CONFIG_NRF_WIFI_RPU_RECOVERY_DEBUG + LOG_ERR("%s: Bringing the interface up", __func__); +#else LOG_DBG("%s: Bringing the interface up", __func__); - net_if_up(vif_ctx_zep->zep_net_if_ctx); +#endif + ret = net_if_up(vif_ctx_zep->zep_net_if_ctx); + if (ret) { + LOG_ERR("%s: net_if_up failed: %d", __func__, ret); + } k_mutex_unlock(&rpu_ctx_zep->rpu_lock); +#ifdef CONFIG_NRF_WIFI_RPU_RECOVERY_DEBUG + LOG_ERR("%s: RPU recovery done", __func__); +#else + LOG_DBG("%s: RPU recovery done", __func__); +#endif } void nrf_wifi_rpu_recovery_cb(void *vif_ctx_handle, From 87e7d5449ef50d90004b6313215fbc4be1d3ac4d Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Thu, 11 Jul 2024 13:07:32 +0530 Subject: [PATCH 036/299] [nrf fromtree] drivers: wifi: Increase the propogation delay In order for the interface down to propagate and cleanup it needs more time, using Shell 10ms was working due to human delay, but programatically this needs higher delay. Signed-off-by: Chaitanya Tata (cherry picked from commit c1afe97e94f464da5ed16199f4f03190959dcf37) --- drivers/wifi/nrfwifi/Kconfig.nrfwifi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/wifi/nrfwifi/Kconfig.nrfwifi b/drivers/wifi/nrfwifi/Kconfig.nrfwifi index a3f42a32198..8906a22a5e8 100644 --- a/drivers/wifi/nrfwifi/Kconfig.nrfwifi +++ b/drivers/wifi/nrfwifi/Kconfig.nrfwifi @@ -667,7 +667,7 @@ if NRF_WIFI_RPU_RECOVERY config NRF_WIFI_RPU_RECOVERY_PROPAGATION_DELAY_MS int "RPU recovery propagation delay in milliseconds" - default 10 + default 2000 help Propagation delay in milliseconds to wait after RPU is powered down before powering it up. This delay is required to ensure that the recovery From a4842788b00e84026a98553a0d8bf372a21a6235 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Sat, 13 Jul 2024 21:32:50 +0530 Subject: [PATCH 037/299] [nrf fromtree] drivers: wifi: Ignore parallel recovery requests During recovery we might get further watchdog interrupts causing multiple recovery requests, ignore them if a recovery is already in progress. Signed-off-by: Chaitanya Tata (cherry picked from commit ce521b89ee6b0d311c0b3e5a5c183816981e11f3) --- drivers/wifi/nrfwifi/inc/fmac_main.h | 3 +++ drivers/wifi/nrfwifi/src/net_if.c | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/drivers/wifi/nrfwifi/inc/fmac_main.h b/drivers/wifi/nrfwifi/inc/fmac_main.h index c11d32c487a..88dbd960044 100644 --- a/drivers/wifi/nrfwifi/inc/fmac_main.h +++ b/drivers/wifi/nrfwifi/inc/fmac_main.h @@ -109,6 +109,9 @@ struct nrf_wifi_ctx_zep { unsigned char *extended_capa, *extended_capa_mask; unsigned int extended_capa_len; struct k_mutex rpu_lock; +#ifdef CONFIG_NRF_WIFI_RPU_RECOVERY + bool rpu_recovery_in_progress; +#endif /* CONFIG_NRF_WIFI_RPU_RECOVERY */ }; struct nrf_wifi_drv_priv_zep { diff --git a/drivers/wifi/nrfwifi/src/net_if.c b/drivers/wifi/nrfwifi/src/net_if.c index 3170b67b975..b4e5748dda9 100644 --- a/drivers/wifi/nrfwifi/src/net_if.c +++ b/drivers/wifi/nrfwifi/src/net_if.c @@ -89,12 +89,22 @@ static void nrf_wifi_rpu_recovery_work_handler(struct k_work *work) return; } + if (rpu_ctx_zep->rpu_recovery_in_progress) { +#ifdef CONFIG_NRF_WIFI_RPU_RECOVERY_DEBUG + LOG_ERR("%s: RPU recovery already in progress", __func__); +#else + LOG_DBG("%s: RPU recovery already in progress", __func__); +#endif + return; + } + #ifdef CONFIG_NRF_WIFI_RPU_RECOVERY_DEBUG LOG_ERR("%s: Starting RPU recovery", __func__); #else LOG_DBG("%s: Starting RPU recovery", __func__); #endif k_mutex_lock(&rpu_ctx_zep->rpu_lock, K_FOREVER); + rpu_ctx_zep->rpu_recovery_in_progress = true; #ifdef CONFIG_NRF_WIFI_RPU_RECOVERY_DEBUG LOG_ERR("%s: Bringing the interface down", __func__); #else @@ -116,6 +126,7 @@ static void nrf_wifi_rpu_recovery_work_handler(struct k_work *work) if (ret) { LOG_ERR("%s: net_if_up failed: %d", __func__, ret); } + rpu_ctx_zep->rpu_recovery_in_progress = false; k_mutex_unlock(&rpu_ctx_zep->rpu_lock); #ifdef CONFIG_NRF_WIFI_RPU_RECOVERY_DEBUG LOG_ERR("%s: RPU recovery done", __func__); From c9b628f92e58e54e624119ea10c245bd91dcd6fe Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Sun, 14 Jul 2024 01:20:59 +0530 Subject: [PATCH 038/299] [nrf fromtree] drivers: wifi: Add quiet period for RPU recovery This is to avoid successive recoveries in case we get successive watchdog interrupts from the RPU. Signed-off-by: Chaitanya Tata (cherry picked from commit ed7c10ead3907bafc82900e3c57cfd6a8017ca7d) --- drivers/wifi/nrfwifi/Kconfig.nrfwifi | 6 ++++++ drivers/wifi/nrfwifi/inc/fmac_main.h | 1 + drivers/wifi/nrfwifi/src/net_if.c | 15 +++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/drivers/wifi/nrfwifi/Kconfig.nrfwifi b/drivers/wifi/nrfwifi/Kconfig.nrfwifi index 8906a22a5e8..e5c5e77c8f8 100644 --- a/drivers/wifi/nrfwifi/Kconfig.nrfwifi +++ b/drivers/wifi/nrfwifi/Kconfig.nrfwifi @@ -708,6 +708,12 @@ config NRF_WIFI_RPU_RECOVERY_DEBUG help Enable RPU recovery debug logs to help debug RPU recovery mechanism. +config NRF_WIFI_RPU_RECOVERY_QUIET_PERIOD_MS + int "RPU recovery quiet period in milliseconds" + default 5000 + help + Quiet period in milliseconds after RPU recovery is triggered. During + this period, no new RPU recovery will be triggered. endif # NRF_WIFI_RPU_RECOVERY config NRF_WIFI_FEAT_WMM diff --git a/drivers/wifi/nrfwifi/inc/fmac_main.h b/drivers/wifi/nrfwifi/inc/fmac_main.h index 88dbd960044..bcdae7161e7 100644 --- a/drivers/wifi/nrfwifi/inc/fmac_main.h +++ b/drivers/wifi/nrfwifi/inc/fmac_main.h @@ -111,6 +111,7 @@ struct nrf_wifi_ctx_zep { struct k_mutex rpu_lock; #ifdef CONFIG_NRF_WIFI_RPU_RECOVERY bool rpu_recovery_in_progress; + unsigned long last_rpu_recovery_time_ms; #endif /* CONFIG_NRF_WIFI_RPU_RECOVERY */ }; diff --git a/drivers/wifi/nrfwifi/src/net_if.c b/drivers/wifi/nrfwifi/src/net_if.c index b4e5748dda9..9bcd772d903 100644 --- a/drivers/wifi/nrfwifi/src/net_if.c +++ b/drivers/wifi/nrfwifi/src/net_if.c @@ -98,6 +98,20 @@ static void nrf_wifi_rpu_recovery_work_handler(struct k_work *work) return; } + if (rpu_ctx_zep->last_rpu_recovery_time_ms && + ((k_uptime_get() - rpu_ctx_zep->last_rpu_recovery_time_ms) < + CONFIG_NRF_WIFI_RPU_RECOVERY_QUIET_PERIOD_MS)) { +#ifdef CONFIG_NRF_WIFI_RPU_RECOVERY_DEBUG + LOG_ERR("%s: In quiet period (last_rpu_recovery_time_ms=%ld), ignoring", + __func__, rpu_ctx_zep->last_rpu_recovery_time_ms); +#else + LOG_DBG("%s: In quiet period (last_rpu_recovery_time_ms=%ld), ignoring", + __func__, rpu_ctx_zep->last_rpu_recovery_time_ms); +#endif + return; + } + + #ifdef CONFIG_NRF_WIFI_RPU_RECOVERY_DEBUG LOG_ERR("%s: Starting RPU recovery", __func__); #else @@ -127,6 +141,7 @@ static void nrf_wifi_rpu_recovery_work_handler(struct k_work *work) LOG_ERR("%s: net_if_up failed: %d", __func__, ret); } rpu_ctx_zep->rpu_recovery_in_progress = false; + rpu_ctx_zep->last_rpu_recovery_time_ms = k_uptime_get(); k_mutex_unlock(&rpu_ctx_zep->rpu_lock); #ifdef CONFIG_NRF_WIFI_RPU_RECOVERY_DEBUG LOG_ERR("%s: RPU recovery done", __func__); From 3decbb21b1894329757766acb8ad14c48e06dda1 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Sun, 14 Jul 2024 01:43:43 +0530 Subject: [PATCH 039/299] [nrf fromtree] drivers: wifi: Fix the NULL check Check for RPU context as well. To fix this properly we need more fixes to be backported, but this should suffice for now. Signed-off-by: Chaitanya Tata (cherry picked from commit 6f7fbf845181f437ae5572f1005a1e6514c68f39) --- drivers/wifi/nrfwifi/src/fmac_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/wifi/nrfwifi/src/fmac_main.c b/drivers/wifi/nrfwifi/src/fmac_main.c index 5c0e4f336e6..ca5782a1ee7 100644 --- a/drivers/wifi/nrfwifi/src/fmac_main.c +++ b/drivers/wifi/nrfwifi/src/fmac_main.c @@ -252,7 +252,7 @@ static void nrf_wifi_process_rssi_from_rx(void *vif_ctx, rpu_ctx_zep = vif_ctx_zep->rpu_ctx_zep; - if (!rpu_ctx_zep) { + if (!(rpu_ctx_zep && rpu_ctx_zep->rpu_ctx)) { LOG_ERR("%s: rpu_ctx_zep is NULL", __func__); return; } From 38a6217bd88cce53877eba17bd2ff058b1c12555 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Sun, 14 Jul 2024 01:57:29 +0530 Subject: [PATCH 040/299] [nrf fromtree] drivers: wifi: Add RPU recovery retry mechanism In case RPU is stuck in consecutive recovery over a time period then that means it's not recoverable through RPU recovery, only thing left to do is to trigger a system reboot. This feature is disabled by default, so, either application can do their own implementatio or enable this feature in the driver along with configurable retries and window period. Signed-off-by: Chaitanya Tata (cherry picked from commit 9b105698ede164de7d44bef12effa4a7e8ab547b) --- drivers/wifi/nrfwifi/Kconfig.nrfwifi | 16 ++++++++++++++++ drivers/wifi/nrfwifi/inc/fmac_main.h | 1 + drivers/wifi/nrfwifi/src/net_if.c | 18 +++++++++++++++++- 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/drivers/wifi/nrfwifi/Kconfig.nrfwifi b/drivers/wifi/nrfwifi/Kconfig.nrfwifi index e5c5e77c8f8..003123bdbad 100644 --- a/drivers/wifi/nrfwifi/Kconfig.nrfwifi +++ b/drivers/wifi/nrfwifi/Kconfig.nrfwifi @@ -714,6 +714,22 @@ config NRF_WIFI_RPU_RECOVERY_QUIET_PERIOD_MS help Quiet period in milliseconds after RPU recovery is triggered. During this period, no new RPU recovery will be triggered. + +config NRF_WIFI_RPU_RECOVERY_MAX_RETRIES + int "Maximum number of consecutive RPU recovery retries, 0 to disable" + default 0 + help + Maximum number of consecutive RPU recovery retries before giving up + and resetting the system. Set to 0 to keep retrying indefinitely. + +config NRF_WIFI_RPU_RECOVERY_RETRY_WINDOW_S + int "RPU recovery retry window in seconds" + default 900 + help + Window in seconds during which the number of consecutive RPU recovery + retries are counted. If the number of consecutive RPU recovery retries + exceeds NRF_WIFI_RPU_RECOVERY_MAX_RETRIES within this window, the system + will be reset. endif # NRF_WIFI_RPU_RECOVERY config NRF_WIFI_FEAT_WMM diff --git a/drivers/wifi/nrfwifi/inc/fmac_main.h b/drivers/wifi/nrfwifi/inc/fmac_main.h index bcdae7161e7..24453a4c34f 100644 --- a/drivers/wifi/nrfwifi/inc/fmac_main.h +++ b/drivers/wifi/nrfwifi/inc/fmac_main.h @@ -112,6 +112,7 @@ struct nrf_wifi_ctx_zep { #ifdef CONFIG_NRF_WIFI_RPU_RECOVERY bool rpu_recovery_in_progress; unsigned long last_rpu_recovery_time_ms; + unsigned int rpu_recovery_retries; #endif /* CONFIG_NRF_WIFI_RPU_RECOVERY */ }; diff --git a/drivers/wifi/nrfwifi/src/net_if.c b/drivers/wifi/nrfwifi/src/net_if.c index 9bcd772d903..81369186533 100644 --- a/drivers/wifi/nrfwifi/src/net_if.c +++ b/drivers/wifi/nrfwifi/src/net_if.c @@ -18,6 +18,8 @@ #include LOG_MODULE_DECLARE(wifi_nrf, CONFIG_WIFI_NRF70_LOG_LEVEL); +#include + #include "net_private.h" #include "util.h" @@ -111,13 +113,27 @@ static void nrf_wifi_rpu_recovery_work_handler(struct k_work *work) return; } - #ifdef CONFIG_NRF_WIFI_RPU_RECOVERY_DEBUG LOG_ERR("%s: Starting RPU recovery", __func__); #else LOG_DBG("%s: Starting RPU recovery", __func__); #endif k_mutex_lock(&rpu_ctx_zep->rpu_lock, K_FOREVER); +#if CONFIG_NRF_WIFI_RPU_RECOVERY_MAX_RETRIES > 0 + if (!rpu_ctx_zep->last_rpu_recovery_time_ms || + (k_uptime_get() - rpu_ctx_zep->last_rpu_recovery_time_ms) < + CONFIG_NRF_WIFI_RPU_RECOVERY_RETRY_WINDOW_S * MSEC_PER_SEC) { + if (rpu_ctx_zep->rpu_recovery_retries >= + CONFIG_NRF_WIFI_RPU_RECOVERY_MAX_RETRIES) { + LOG_ERR("%s: Maximum recovery retries reached, rebooting system", + __func__); + sys_reboot(SYS_REBOOT_COLD); + } + rpu_ctx_zep->rpu_recovery_retries++; + } else { + rpu_ctx_zep->rpu_recovery_retries = 0; + } +#endif rpu_ctx_zep->rpu_recovery_in_progress = true; #ifdef CONFIG_NRF_WIFI_RPU_RECOVERY_DEBUG LOG_ERR("%s: Bringing the interface down", __func__); From 0cc01f6577d238daa6da93fb5e985ce13156f02b Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Thu, 18 Jul 2024 00:14:16 +0530 Subject: [PATCH 041/299] [nrf fromtree] drivers: wifi: Fix RPU recovery disabled build failures Fix RPU recovery protection to solve build failures when RPU recovery is disabled. As recovery is primarily based on power-management, add a Kconfig dependency to enforce, this simplies the macros to protect the code. Signed-off-by: Chaitanya Tata (cherry picked from commit 5c8f1807c198b9b246ecd4ad3778412a626894aa) --- drivers/wifi/nrfwifi/Kconfig.nrfwifi | 1 + drivers/wifi/nrfwifi/inc/fmac_main.h | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/wifi/nrfwifi/Kconfig.nrfwifi b/drivers/wifi/nrfwifi/Kconfig.nrfwifi index 003123bdbad..07b286ebdf0 100644 --- a/drivers/wifi/nrfwifi/Kconfig.nrfwifi +++ b/drivers/wifi/nrfwifi/Kconfig.nrfwifi @@ -655,6 +655,7 @@ config NRF_WIFI_AP_DEAD_DETECT_TIMEOUT config NRF_WIFI_RPU_RECOVERY bool "RPU recovery mechanism" + depends on NRF_WIFI_LOW_POWER select EXPERIMENTAL help Enable RPU recovery mechanism to recover from RPU (nRF70) hang. diff --git a/drivers/wifi/nrfwifi/inc/fmac_main.h b/drivers/wifi/nrfwifi/inc/fmac_main.h index 24453a4c34f..9eb98baa518 100644 --- a/drivers/wifi/nrfwifi/inc/fmac_main.h +++ b/drivers/wifi/nrfwifi/inc/fmac_main.h @@ -146,8 +146,9 @@ enum nrf_wifi_status nrf_wifi_fw_load(void *rpu_ctx); #endif /* CONFIG_NRF_WIFI_BUILD_ONLY_MODE */ #ifndef CONFIG_NRF70_OFFLOADED_RAW_TX struct nrf_wifi_vif_ctx_zep *nrf_wifi_get_vif_ctx(struct net_if *iface); +#ifdef CONFIG_NRF_WIFI_RPU_RECOVERY void nrf_wifi_rpu_recovery_cb(void *vif_ctx, void *event_data, unsigned int event_len); -#endif /* !CONFIG_NRF_WIFI_BUILD_ONLY_MODE */ +#endif /* CONFIG_NRF_WIFI_RPU_RECOVERY */ #endif /* __ZEPHYR_FMAC_MAIN_H__ */ From 994efbefeeb017ad8a4ec0e8688a8a1af8d099d4 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Thu, 18 Jul 2024 01:02:57 +0530 Subject: [PATCH 042/299] [nrf fromtree] drivers: wifi: Fix TX buffers leak During interface down in case TX has pending buffers in either TXQ or Pending_Q then they are not freed instead the Q itself is freed. Fix by traversing the Q and freeing all members. Signed-off-by: Chaitanya Tata (cherry picked from commit 9c36d976460ee612f716a191c461c16f40d55936) --- drivers/wifi/nrfwifi/src/shim.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/wifi/nrfwifi/src/shim.c b/drivers/wifi/nrfwifi/src/shim.c index 9f8b065ead0..d0379a6d1f5 100644 --- a/drivers/wifi/nrfwifi/src/shim.c +++ b/drivers/wifi/nrfwifi/src/shim.c @@ -235,6 +235,10 @@ static void *zep_shim_nbuf_alloc(unsigned int size) static void zep_shim_nbuf_free(void *nbuf) { + if (!nbuf) { + return; + } + k_free(((struct nwb *)nbuf)->priv); k_free(nbuf); } From d5a4d971682d3c681a5609831942b11b9e07e62e Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Thu, 18 Jul 2024 20:52:19 +0530 Subject: [PATCH 043/299] [nrf fromtree] drivers: wifi: Add PS state debugs These are very frequent, so, a separate debug is added for debugging host RPU recovery logic. Signed-off-by: Chaitanya Tata (cherry picked from commit a4537a7eea25d2d8b5eeb2544d101419047659f4) --- drivers/wifi/nrfwifi/Kconfig.nrfwifi | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/wifi/nrfwifi/Kconfig.nrfwifi b/drivers/wifi/nrfwifi/Kconfig.nrfwifi index 07b286ebdf0..edf1049a0e8 100644 --- a/drivers/wifi/nrfwifi/Kconfig.nrfwifi +++ b/drivers/wifi/nrfwifi/Kconfig.nrfwifi @@ -731,6 +731,13 @@ config NRF_WIFI_RPU_RECOVERY_RETRY_WINDOW_S retries are counted. If the number of consecutive RPU recovery retries exceeds NRF_WIFI_RPU_RECOVERY_MAX_RETRIES within this window, the system will be reset. + +config NRF_WIFI_RPU_RECOVERY_PS_STATE_DEBUG + bool "RPU recovery power save state debug logs" + help + Enable RPU recovery power save state debug logs to help debug RPU recovery mechanism. + + endif # NRF_WIFI_RPU_RECOVERY config NRF_WIFI_FEAT_WMM From 26f62010e121d4d3054d565796ac644b998fe2be Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Thu, 18 Jul 2024 17:40:46 +0530 Subject: [PATCH 044/299] [nrf fromtree] drivers: wifi: Enable management buffers offload With this offload, host doesn't need to manage RX buffers for management frames, and this saves Host-RPU comms and thus giving RPU to sleep more often and is essential to test RPU recovery. Signed-off-by: Chaitanya Tata (cherry picked from commit dbda09d3e506d391cbd203bd2afdd6444d1bcdc7) --- drivers/wifi/nrfwifi/CMakeLists.txt | 4 ++++ drivers/wifi/nrfwifi/Kconfig.nrfwifi | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/drivers/wifi/nrfwifi/CMakeLists.txt b/drivers/wifi/nrfwifi/CMakeLists.txt index 5ea9da5825e..933be3603a5 100644 --- a/drivers/wifi/nrfwifi/CMakeLists.txt +++ b/drivers/wifi/nrfwifi/CMakeLists.txt @@ -285,6 +285,10 @@ zephyr_compile_definitions_ifdef(CONFIG_NRF70_AP_MODE -DNRF70_AP_MODE ) +zephyr_compile_definitions_ifdef(CONFIG_NRF_WIFI_MGMT_BUFF_OFFLOAD + -DNRF_WIFI_MGMT_BUFF_OFFLOAD +) + zephyr_compile_definitions( -DNRF70_RX_NUM_BUFS=${CONFIG_NRF70_RX_NUM_BUFS} -DNRF70_MAX_TX_TOKENS=${CONFIG_NRF70_MAX_TX_TOKENS} diff --git a/drivers/wifi/nrfwifi/Kconfig.nrfwifi b/drivers/wifi/nrfwifi/Kconfig.nrfwifi index edf1049a0e8..5403ecdf83f 100644 --- a/drivers/wifi/nrfwifi/Kconfig.nrfwifi +++ b/drivers/wifi/nrfwifi/Kconfig.nrfwifi @@ -769,4 +769,12 @@ config NRF_WIFI_QOS_NULL_BASED_RETRIEVAL endchoice +config NRF_WIFI_MGMT_BUFF_OFFLOAD + bool "management buffer offload" + default y + help + This option offloads the refilling of management buffers to UMAC, saves host + having to exchange commands and events for every management packet even if it is + consumed by UMAC. + endif # WIFI_NRF70 From 43614e2db079691d9e713a06802d3af5f41633a7 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Tue, 6 Aug 2024 20:30:58 +0530 Subject: [PATCH 045/299] [nrf fromtree] drivers: wifi: Increase default PS active timeout interval In crowded environments RPU is active for more than 10s due to too many retries and this triggers a false RPU recovery. To avoid this, increase the default to 50s to handle corner cases, as this will only impact the recovery triggered case, higher timeout doesn't have any impact in normal cases. Signed-off-by: Chaitanya Tata (cherry picked from commit 94f9fb95d9e0c6d9db8003feaf26afd7cdd96f11) --- drivers/wifi/nrfwifi/Kconfig.nrfwifi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/wifi/nrfwifi/Kconfig.nrfwifi b/drivers/wifi/nrfwifi/Kconfig.nrfwifi index 5403ecdf83f..5814548cb20 100644 --- a/drivers/wifi/nrfwifi/Kconfig.nrfwifi +++ b/drivers/wifi/nrfwifi/Kconfig.nrfwifi @@ -690,7 +690,7 @@ config NRF_WIFI_RPU_RECOVERY_PROPAGATION_DELAY_MS config NRF_WIFI_RPU_RECOVERY_PS_ACTIVE_TIMEOUT_MS int "RPU recovery power save active timeout in milliseconds" - default 10000 + default 50000 help Power save active timeout in milliseconds after which RPU recovery mechanism will be triggered. This timeout is used to ensure that the From 17b81496b4c2cc54f4d31afe36fdd6148e97608a Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Tue, 6 Aug 2024 21:10:39 +0530 Subject: [PATCH 046/299] [nrf fromtree] drivers: wifi: Add support for keepalive To handle interoperability issue with few APs, add a feature to keep sending keepalive frames periodically to avoid AP disconnecting the STA. This is disabled by default to avoid unnecessary power consumption as it's only seen with few old APs. Signed-off-by: Chaitanya Tata (cherry picked from commit 7c3d3427963e1295b2e8a0ed1b6eb5492bb7ac9e) --- drivers/wifi/nrfwifi/CMakeLists.txt | 8 ++++++++ drivers/wifi/nrfwifi/Kconfig.nrfwifi | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/drivers/wifi/nrfwifi/CMakeLists.txt b/drivers/wifi/nrfwifi/CMakeLists.txt index 933be3603a5..14f3080d1a4 100644 --- a/drivers/wifi/nrfwifi/CMakeLists.txt +++ b/drivers/wifi/nrfwifi/CMakeLists.txt @@ -289,6 +289,14 @@ zephyr_compile_definitions_ifdef(CONFIG_NRF_WIFI_MGMT_BUFF_OFFLOAD -DNRF_WIFI_MGMT_BUFF_OFFLOAD ) +zephyr_compile_definitions_ifdef(CONFIG_NRF_WIFI_FEAT_KEEPALIVE + -DNRF_WIFI_FEAT_KEEPALIVE +) + +zephyr_compile_definitions_ifdef(CONFIG_NRF_WIFI_FEAT_KEEPALIVE + -DNRF_WIFI_KEEPALIVE_PERIOD_S=${CONFIG_NRF_WIFI_KEEPALIVE_PERIOD_S} +) + zephyr_compile_definitions( -DNRF70_RX_NUM_BUFS=${CONFIG_NRF70_RX_NUM_BUFS} -DNRF70_MAX_TX_TOKENS=${CONFIG_NRF70_MAX_TX_TOKENS} diff --git a/drivers/wifi/nrfwifi/Kconfig.nrfwifi b/drivers/wifi/nrfwifi/Kconfig.nrfwifi index 5814548cb20..c4b619315b3 100644 --- a/drivers/wifi/nrfwifi/Kconfig.nrfwifi +++ b/drivers/wifi/nrfwifi/Kconfig.nrfwifi @@ -777,4 +777,22 @@ config NRF_WIFI_MGMT_BUFF_OFFLOAD having to exchange commands and events for every management packet even if it is consumed by UMAC. +config NRF_WIFI_FEAT_KEEPALIVE + bool "Wi-Fi keepalive feature for connection maintenance" + depends on NRF70_STA_MODE + help + Enable Wi-Fi keepalive feature to keep the connection alive by sending + keepalive packets to the AP. Primarily intended to interoperate with APs + that disconnect idle clients without any explicit checks. Slightly increases + power consumption. + +if NRF_WIFI_FEAT_KEEPALIVE +config NRF_WIFI_KEEPALIVE_PERIOD_S + int "Keepalive period in seconds" + range 30 3600 + default 60 + help + Keepalive period in seconds to send keepalive packets to the AP. +endif + endif # WIFI_NRF70 From 986c18ed18705ecec409cbe4b9940efe61c3cdd8 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Tue, 3 Sep 2024 00:02:08 +0530 Subject: [PATCH 047/299] [nrf fromtree] drivers: wifi: Fix shell hang Add a null check for HAL context in the interrupt handler, this was causing locking issue operating on null. The root cause of null is not known, but this solves the locking issue when data and control paths are excited in parallel. Signed-off-by: Chaitanya Tata (cherry picked from commit 5f6dca377a055b419c4caa5c7da8aa1a8d56c19a) --- drivers/wifi/nrfwifi/src/shim.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/wifi/nrfwifi/src/shim.c b/drivers/wifi/nrfwifi/src/shim.c index d0379a6d1f5..9c6c117ddfb 100644 --- a/drivers/wifi/nrfwifi/src/shim.c +++ b/drivers/wifi/nrfwifi/src/shim.c @@ -751,6 +751,11 @@ static void irq_work_handler(struct k_work *work) { int ret = 0; + if (!intr_priv || !intr_priv->callbk_fn || !intr_priv->callbk_data) { + LOG_ERR("%s: Invalid intr_priv handler", __func__); + return; + } + ret = intr_priv->callbk_fn(intr_priv->callbk_data); if (ret) { @@ -766,6 +771,11 @@ static void zep_shim_irq_handler(const struct device *dev, struct gpio_callback ARG_UNUSED(cb); ARG_UNUSED(pins); + if (!(intr_priv && intr_priv->callbk_fn && intr_priv->callbk_data)) { + LOG_ERR("%s: Invalid intr_priv", __func__); + return; + } + k_work_schedule_for_queue(&zep_wifi_intr_q, &intr_priv->work, K_NO_WAIT); } From 63da7d9bb932e12c1f555ca19ae0b8dd4dcafccd Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Thu, 5 Sep 2024 01:44:40 +0530 Subject: [PATCH 048/299] [nrf fromtree] drivers: wifi: Use mutex for spinlock Ideally we should be using Zephyr spinlock APIs but that requires changes to shim API, so, for this maintenance release just replace with mutex to keep the context same and no API changes. This solves the locking issue that we see when control and data path are excited concurrently due to locking semantics of semaphores, the issue is not root caused but mutex enforce strict locking semantics for multiple threads and solve the issue. Signed-off-by: Chaitanya Tata (cherry picked from commit d0d659b675ec256928faf92741f6ea4641f5287e) --- drivers/wifi/nrfwifi/src/shim.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/wifi/nrfwifi/src/shim.c b/drivers/wifi/nrfwifi/src/shim.c index 9c6c117ddfb..93cafa905c2 100644 --- a/drivers/wifi/nrfwifi/src/shim.c +++ b/drivers/wifi/nrfwifi/src/shim.c @@ -116,7 +116,7 @@ static void zep_shim_qspi_cpy_to(void *priv, unsigned long addr, const void *src static void *zep_shim_spinlock_alloc(void) { - struct k_sem *lock = NULL; + struct k_mutex *lock = NULL; lock = k_malloc(sizeof(*lock)); @@ -134,27 +134,29 @@ static void zep_shim_spinlock_free(void *lock) static void zep_shim_spinlock_init(void *lock) { - k_sem_init(lock, 1, 1); + k_mutex_init(lock); } static void zep_shim_spinlock_take(void *lock) { - k_sem_take(lock, K_FOREVER); + k_mutex_lock(lock, K_FOREVER); } static void zep_shim_spinlock_rel(void *lock) { - k_sem_give(lock); + k_mutex_unlock(lock); } static void zep_shim_spinlock_irq_take(void *lock, unsigned long *flags) { - k_sem_take(lock, K_FOREVER); + ARG_UNUSED(flags); + k_mutex_lock(lock, K_FOREVER); } static void zep_shim_spinlock_irq_rel(void *lock, unsigned long *flags) { - k_sem_give(lock); + ARG_UNUSED(flags); + k_mutex_unlock(lock); } static int zep_shim_pr_dbg(const char *fmt, va_list args) From aa74fffa2c6a69653fb72fc1186e0ded150a23d2 Mon Sep 17 00:00:00 2001 From: Ajay Parida Date: Tue, 3 Sep 2024 19:12:09 +0530 Subject: [PATCH 049/299] [nrf fromtree] drivers: wifi: Add PS exit strategy runtime configuration Dynamically set power save exit strategy runtime configuration that allows to switch b/w stratgies depending on conserving power and low-latency traffic download. Signed-off-by: Ajay Parida (cherry picked from commit fe920fc9c911b817ad3df3688611ec4ba20a6732) --- drivers/wifi/nrfwifi/CMakeLists.txt | 1 + drivers/wifi/nrfwifi/Kconfig.nrfwifi | 20 ++++++++++++++++++++ drivers/wifi/nrfwifi/src/wifi_mgmt.c | 23 +++++++++++++++++++++++ 3 files changed, 44 insertions(+) diff --git a/drivers/wifi/nrfwifi/CMakeLists.txt b/drivers/wifi/nrfwifi/CMakeLists.txt index 14f3080d1a4..41611af08a1 100644 --- a/drivers/wifi/nrfwifi/CMakeLists.txt +++ b/drivers/wifi/nrfwifi/CMakeLists.txt @@ -338,4 +338,5 @@ zephyr_compile_definitions( -DNRF70_ANT_GAIN_5G_BAND1=${CONFIG_NRF70_ANT_GAIN_5G_BAND1} -DNRF70_ANT_GAIN_5G_BAND2=${CONFIG_NRF70_ANT_GAIN_5G_BAND2} -DNRF70_ANT_GAIN_5G_BAND3=${CONFIG_NRF70_ANT_GAIN_5G_BAND3} + -DNRF_WIFI_PS_INT_PS=${CONFIG_NRF_WIFI_PS_INT_PS} ) diff --git a/drivers/wifi/nrfwifi/Kconfig.nrfwifi b/drivers/wifi/nrfwifi/Kconfig.nrfwifi index c4b619315b3..b409261b614 100644 --- a/drivers/wifi/nrfwifi/Kconfig.nrfwifi +++ b/drivers/wifi/nrfwifi/Kconfig.nrfwifi @@ -795,4 +795,24 @@ config NRF_WIFI_KEEPALIVE_PERIOD_S Keepalive period in seconds to send keepalive packets to the AP. endif +choice NRF_WIFI_PS_EXIT_STRATEGY + prompt "Power save exit strategy" + default NRF_WIFI_PS_INT_PS + help + Select the power save exit strategy to retrieve buffered data from AP. + +config NRF_WIFI_PS_EXIT_EVERY_TIM + bool "Exit power save every time to retrieve buffered data from AP" + help + Exit power save every time to retrieve buffered data from AP. Entering back to + power save mode might take some time and power. + +config NRF_WIFI_PS_INT_PS + bool "Exit power save based on an intelligent algorithm" + help + Exit power save based on an intelligent algorithm to retrieve buffered data from AP. + The algorithm tracks the buffered data at the AP and then dynamically decides + whether to stay in PS (for lower amount of buffered data) or exit PS (for higher + amount of buffered data). +endchoice endif # WIFI_NRF70 diff --git a/drivers/wifi/nrfwifi/src/wifi_mgmt.c b/drivers/wifi/nrfwifi/src/wifi_mgmt.c index 6232ad245cd..65f6c217bfe 100644 --- a/drivers/wifi/nrfwifi/src/wifi_mgmt.c +++ b/drivers/wifi/nrfwifi/src/wifi_mgmt.c @@ -115,6 +115,24 @@ int nrf_wifi_set_power_save(const struct device *dev, vif_ctx_zep->vif_idx, params->wakeup_mode); break; + case WIFI_PS_PARAM_EXIT_STRATEGY: + unsigned int exit_strategy; + + if (params->exit_strategy == WIFI_PS_EXIT_EVERY_TIM) { + exit_strategy = EVERY_TIM; + } else if (params->exit_strategy == WIFI_PS_EXIT_CUSTOM_ALGO) { + exit_strategy = INT_PS; + } else { + params->fail_reason = + WIFI_PS_PARAM_FAIL_INVALID_EXIT_STRATEGY; + return -EINVAL; + } + + status = nrf_wifi_fmac_set_ps_exit_strategy( + rpu_ctx_zep->rpu_ctx, + vif_ctx_zep->vif_idx, + exit_strategy); + break; default: params->fail_reason = WIFI_PS_PARAM_FAIL_CMD_EXEC_FAIL; @@ -379,6 +397,11 @@ void nrf_wifi_event_proc_get_power_save_info(void *vif_ctx, vif_ctx_zep->ps_info->ps_params.timeout_ms = ps_info->ps_timeout; vif_ctx_zep->ps_info->ps_params.listen_interval = ps_info->listen_interval; vif_ctx_zep->ps_info->ps_params.wakeup_mode = ps_info->extended_ps; + if (ps_info->ps_exit_strategy == EVERY_TIM) { + vif_ctx_zep->ps_info->ps_params.exit_strategy = WIFI_PS_EXIT_EVERY_TIM; + } else if (ps_info->ps_exit_strategy == INT_PS) { + vif_ctx_zep->ps_info->ps_params.exit_strategy = WIFI_PS_EXIT_CUSTOM_ALGO; + } for (int i = 0; i < ps_info->num_twt_flows; i++) { struct twt_interval_float twt_interval_fp; From 017d72c62cd8f6bd3baafb6fbecf41fdad6aebbe Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Wed, 11 Sep 2024 17:53:33 +0530 Subject: [PATCH 050/299] [nrf fromtree] drivers: wifi: Fix crash when recovery is triggered There is a race condition when recovery is in progress and in parallel Wi-Fi util commands are being executed (CTF), where the RPU context is de-initialized as part of recovery but no checks are present in the Wi-Fi util command processing causing a crash. This needs a proper fix for all commands, but for maintenance branch fix is added only for commonly used commands. Signed-off-by: Chaitanya Tata (cherry picked from commit 67216f1b5ae1e9467c6b2e88bfde5609fabd2040) --- drivers/wifi/nrfwifi/src/wifi_util.c | 42 ++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/drivers/wifi/nrfwifi/src/wifi_util.c b/drivers/wifi/nrfwifi/src/wifi_util.c index c5e2a8dedfa..2e514ea6719 100644 --- a/drivers/wifi/nrfwifi/src/wifi_util.c +++ b/drivers/wifi/nrfwifi/src/wifi_util.c @@ -273,6 +273,7 @@ static int nrf_wifi_util_tx_stats(const struct shell *sh, void *queue = NULL; unsigned int tx_pending_pkts = 0; struct nrf_wifi_fmac_dev_ctx_def *def_dev_ctx = NULL; + int ret; vif_index = atoi(argv[1]); if ((vif_index < 0) || (vif_index >= max_vif_index)) { @@ -284,6 +285,15 @@ static int nrf_wifi_util_tx_stats(const struct shell *sh, return -ENOEXEC; } + k_mutex_lock(&ctx->rpu_lock, K_FOREVER); + if (!ctx->rpu_ctx) { + shell_fprintf(shell, + SHELL_ERROR, + "RPU context not initialized\n"); + ret = -ENOEXEC; + goto unlock; + } + fmac_dev_ctx = ctx->rpu_ctx; def_dev_ctx = wifi_dev_priv(fmac_dev_ctx); @@ -306,7 +316,11 @@ static int nrf_wifi_util_tx_stats(const struct shell *sh, tx_pending_pkts); } - return 0; + ret = 0; + +unlock: + k_mutex_unlock(&ctx->rpu_lock); + return ret; } #endif /* CONFIG_NRF70_STA_MODE */ @@ -444,6 +458,7 @@ static int nrf_wifi_util_dump_rpu_stats(const struct shell *sh, struct nrf_wifi_fmac_dev_ctx *fmac_dev_ctx = NULL; struct rpu_op_stats stats; enum rpu_stats_type stats_type = RPU_STATS_TYPE_ALL; + int ret; if (argc == 2) { const char *type = argv[1]; @@ -465,6 +480,14 @@ static int nrf_wifi_util_dump_rpu_stats(const struct shell *sh, } } + k_mutex_lock(&ctx->rpu_lock, K_FOREVER); + if (!ctx->rpu_ctx) { + shell_fprintf(shell, + SHELL_ERROR, + "RPU context not initialized\n"); + ret = -ENOEXEC; + goto unlock; + } fmac_dev_ctx = ctx->rpu_ctx; memset(&stats, 0, sizeof(struct rpu_op_stats)); @@ -474,7 +497,8 @@ static int nrf_wifi_util_dump_rpu_stats(const struct shell *sh, shell_fprintf(sh, SHELL_ERROR, "Failed to get stats\n"); - return -ENOEXEC; + ret = -ENOEXEC; + goto unlock; } if (stats_type == RPU_STATS_TYPE_UMAC || stats_type == RPU_STATS_TYPE_ALL) { @@ -847,7 +871,9 @@ static int nrf_wifi_util_dump_rpu_stats(const struct shell *sh, phy->dsss_crc32_fail_cnt); } - return 0; + ret = 0; +unlock: + return ret; } #endif /* !CONFIG_NRF70_RADIO_TEST && !CONFIG_NRF70_OFFLOADED_RAW_TX */ @@ -858,12 +884,15 @@ static int nrf_wifi_util_trigger_rpu_recovery(const struct shell *sh, { enum nrf_wifi_status status = NRF_WIFI_STATUS_FAIL; struct nrf_wifi_fmac_dev_ctx *fmac_dev_ctx = NULL; + int ret; + k_mutex_lock(&ctx->rpu_lock, K_FOREVER); if (!ctx || !ctx->rpu_ctx) { shell_fprintf(sh, SHELL_ERROR, "RPU context not initialized\n"); - return -ENOEXEC; + ret = -ENOEXEC; + goto unlock; } fmac_dev_ctx = ctx->rpu_ctx; @@ -880,7 +909,10 @@ static int nrf_wifi_util_trigger_rpu_recovery(const struct shell *sh, SHELL_INFO, "RPU recovery triggered\n"); - return 0; + ret = 0; +unlock: + k_mutex_unlock(&ctx->rpu_lock); + return ret; } #endif /* CONFIG_NRF_WIFI_RPU_RECOVERY */ From 5e6c3710e64dd6d2f09864c62958c48dc4db1123 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Thu, 12 Sep 2024 14:45:27 +0530 Subject: [PATCH 051/299] [nrf fromtree] drivers: wifi: Fix missing unlock for stats The RPU context lock is not unlocked this is causing recovery to be stuck waiting for the lock. Signed-off-by: Chaitanya Tata (cherry picked from commit ce9d71c476ba5c0815324086bd0692e56933cfbd) --- drivers/wifi/nrfwifi/src/wifi_util.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/wifi/nrfwifi/src/wifi_util.c b/drivers/wifi/nrfwifi/src/wifi_util.c index 2e514ea6719..cad5662f483 100644 --- a/drivers/wifi/nrfwifi/src/wifi_util.c +++ b/drivers/wifi/nrfwifi/src/wifi_util.c @@ -873,6 +873,7 @@ static int nrf_wifi_util_dump_rpu_stats(const struct shell *sh, ret = 0; unlock: + k_mutex_unlock(&ctx->rpu_lock); return ret; } #endif /* !CONFIG_NRF70_RADIO_TEST && !CONFIG_NRF70_OFFLOADED_RAW_TX */ From 25a8bd07f76600804dd85b1eae8aca75b6471e10 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Fri, 13 Sep 2024 15:31:04 +0530 Subject: [PATCH 052/299] [nrf fromtree] drivers: wifi: Fix mutex re-initialization The mutex is used to protect RPU zephyr context which gets modified for every interface down and up (including recovery), so, it was being re-initialized but also used to protect down and up which is a bug. Move the re-initialization to the driver entry so that it happens only once and we can properly use the mutext for down and up protection. Signed-off-by: Chaitanya Tata (cherry picked from commit d30161cd8bd182de5c725376c98b19bce686c6ac) --- drivers/wifi/nrfwifi/src/fmac_main.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/wifi/nrfwifi/src/fmac_main.c b/drivers/wifi/nrfwifi/src/fmac_main.c index ca5782a1ee7..4778111579e 100644 --- a/drivers/wifi/nrfwifi/src/fmac_main.c +++ b/drivers/wifi/nrfwifi/src/fmac_main.c @@ -656,8 +656,6 @@ enum nrf_wifi_status nrf_wifi_fmac_dev_add_zep(struct nrf_wifi_drv_priv_zep *drv goto err; } - k_mutex_init(&rpu_ctx_zep->rpu_lock); - return status; err: if (rpu_ctx) { @@ -816,6 +814,7 @@ static int nrf_wifi_drv_main_zep(const struct device *dev) nrf_wifi_scan_timeout_work); #endif /* CONFIG_NRF70_RADIO_TEST */ + k_mutex_init(&rpu_drv_priv_zep.rpu_ctx_zep.rpu_lock); return 0; #ifdef CONFIG_NRF70_RADIO_TEST fmac_deinit: From 0dcde521dd07e11b42808125f38f059cb216da86 Mon Sep 17 00:00:00 2001 From: Ajay Parida Date: Tue, 3 Sep 2024 19:03:55 +0530 Subject: [PATCH 053/299] [nrf fromtree] wifi_mgmt: Add support for configuring PS exit strategy If AP indicates the presence of buffered traffic, then it is up to the STA to decide whether to stay in PS or come out of PS, add configuration options that can be used at runtime to choose this. This is tagged as "noup" because it's a backport and "fromlist" cannot be used as it won't apply cleanly. Signed-off-by: Ajay Parida (cherry picked from commit 0ce5da6da8124dfe760e17e87e60746798aae2a3) --- include/zephyr/net/wifi.h | 22 +++++++++++++++++ include/zephyr/net/wifi_mgmt.h | 2 ++ subsys/net/l2/wifi/wifi_mgmt.c | 19 +++++++++++++++ subsys/net/l2/wifi/wifi_shell.c | 43 +++++++++++++++++++++++++++++++++ 4 files changed, 86 insertions(+) diff --git a/include/zephyr/net/wifi.h b/include/zephyr/net/wifi.h index f8a2645f558..4612fe2b0b1 100644 --- a/include/zephyr/net/wifi.h +++ b/include/zephyr/net/wifi.h @@ -450,6 +450,8 @@ enum wifi_ps_param_type { WIFI_PS_PARAM_WAKEUP_MODE, /** Power save mode. */ WIFI_PS_PARAM_MODE, + /** Power save exit strategy. */ + WIFI_PS_PARAM_EXIT_STRATEGY, /** Power save timeout. */ WIFI_PS_PARAM_TIMEOUT, }; @@ -465,6 +467,24 @@ enum wifi_ps_wakeup_mode { /** Helper function to get user-friendly ps wakeup mode name. */ const char *wifi_ps_wakeup_mode_txt(enum wifi_ps_wakeup_mode ps_wakeup_mode); +/** + * @brief Wi-Fi power save exit strategy + */ +enum wifi_ps_exit_strategy { + /** PS-Poll frame based */ + WIFI_PS_EXIT_CUSTOM_ALGO = 0, + /** QoS NULL frame based */ + WIFI_PS_EXIT_EVERY_TIM, + +/** @cond INTERNAL_HIDDEN */ + WIFI_PS_EXIT_LAST, + WIFI_PS_EXIT_MAX = WIFI_PS_EXIT_LAST - 1, +/** @endcond */ +}; + +/** Helper function to get user-friendly ps exit strategy name. */ +const char * const wifi_ps_exit_strategy_txt(enum wifi_ps_exit_strategy ps_exit_strategy); + /** @brief Wi-Fi power save error codes. */ enum wifi_config_ps_param_fail_reason { /** Unspecified error */ @@ -481,6 +501,8 @@ enum wifi_config_ps_param_fail_reason { WIFI_PS_PARAM_FAIL_DEVICE_CONNECTED, /** Listen interval out of range */ WIFI_PS_PARAM_LISTEN_INTERVAL_RANGE_INVALID, + /** Invalid exit strategy */ + WIFI_PS_PARAM_FAIL_INVALID_EXIT_STRATEGY, }; /** @cond INTERNAL_HIDDEN */ diff --git a/include/zephyr/net/wifi_mgmt.h b/include/zephyr/net/wifi_mgmt.h index 68650dd9319..653197bf938 100644 --- a/include/zephyr/net/wifi_mgmt.h +++ b/include/zephyr/net/wifi_mgmt.h @@ -604,6 +604,8 @@ struct wifi_ps_params { enum wifi_ps_param_type type; /** Wi-Fi power save fail reason */ enum wifi_config_ps_param_fail_reason fail_reason; + /** Wi-Fi power save exit strategy */ + enum wifi_ps_exit_strategy exit_strategy; }; /** @brief Wi-Fi TWT parameters */ diff --git a/subsys/net/l2/wifi/wifi_mgmt.c b/subsys/net/l2/wifi/wifi_mgmt.c index d676edd8f99..3cea624b6e3 100644 --- a/subsys/net/l2/wifi/wifi_mgmt.c +++ b/subsys/net/l2/wifi/wifi_mgmt.c @@ -240,6 +240,18 @@ const char *wifi_ps_wakeup_mode_txt(enum wifi_ps_wakeup_mode ps_wakeup_mode) } } +const char * const wifi_ps_exit_strategy_txt(enum wifi_ps_exit_strategy ps_exit_strategy) +{ + switch (ps_exit_strategy) { + case WIFI_PS_EXIT_EVERY_TIM: + return "Every TIM"; + case WIFI_PS_EXIT_CUSTOM_ALGO: + return "Custom algorithm"; + default: + return "UNKNOWN"; + } +} + static const struct wifi_mgmt_ops *const get_wifi_api(struct net_if *iface) { const struct device *dev = net_if_get_device(iface); @@ -570,6 +582,13 @@ static int wifi_set_power_save(uint32_t mgmt_request, struct net_if *iface, case WIFI_PS_PARAM_WAKEUP_MODE: case WIFI_PS_PARAM_TIMEOUT: break; + case WIFI_PS_PARAM_EXIT_STRATEGY: + if (ps_params->exit_strategy > WIFI_PS_EXIT_MAX) { + ps_params->fail_reason = + WIFI_PS_PARAM_FAIL_INVALID_EXIT_STRATEGY; + return -EINVAL; + } + break; default: ps_params->fail_reason = WIFI_PS_PARAM_FAIL_OPERATION_NOT_SUPPORTED; diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 2dbb44de0aa..0817f256b6c 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -1062,6 +1062,9 @@ static int cmd_wifi_ps(const struct shell *sh, size_t argc, char *argv[]) PR("PS timeout: disabled\n"); } + shell_fprintf(sh, SHELL_NORMAL, "PS exit strategy: %s\n", + wifi_ps_exit_strategy_txt(config.ps_params.exit_strategy)); + if (config.num_twt_flows == 0) { PR("No TWT flows\n"); } else { @@ -1777,6 +1780,40 @@ static int cmd_wifi_set_rts_threshold(const struct shell *sh, size_t argc, char return 0; } +static int cmd_wifi_ps_exit_strategy(const struct shell *sh, size_t argc, + char *argv[]) +{ + struct net_if *iface = net_if_get_first_wifi(); + struct wifi_ps_params params = { 0 }; + + context.sh = sh; + + if (!strncmp(argv[1], "tim", 3)) { + params.exit_strategy = WIFI_PS_EXIT_EVERY_TIM; + } else if (!strncmp(argv[1], "custom", 6)) { + params.exit_strategy = WIFI_PS_EXIT_CUSTOM_ALGO; + } else { + shell_fprintf(sh, SHELL_WARNING, "Invalid argument\n"); + shell_fprintf(sh, SHELL_INFO, "Valid argument : / \n"); + return -ENOEXEC; + } + + params.type = WIFI_PS_PARAM_EXIT_STRATEGY; + + if (net_mgmt(NET_REQUEST_WIFI_PS, iface, ¶ms, sizeof(params))) { + shell_fprintf(sh, SHELL_WARNING, + "Setting PS exit strategy to %s failed..Reason :%s\n", + wifi_ps_exit_strategy_txt(params.exit_strategy), + wifi_ps_get_config_err_code_str(params.fail_reason)); + return -ENOEXEC; + } + + shell_fprintf(sh, SHELL_NORMAL, "%s\n", + wifi_ps_exit_strategy_txt(params.exit_strategy)); + + return 0; +} + void parse_mode_args_to_params(const struct shell *sh, int argc, char *argv[], struct wifi_mode_info *mode, bool *do_mode_oper) @@ -2942,6 +2979,12 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, SHELL_SUBCMD_SET_END ); +SHELL_SUBCMD_ADD((wifi), ps_exit_strategy, &wifi_commands, + " : Set PS exit strategy to Every TIM\n" + " : Set PS exit strategy to Custom", + cmd_wifi_ps_exit_strategy, + 2, 0); + SHELL_CMD_REGISTER(wifi, &wifi_commands, "Wi-Fi commands", NULL); static int wifi_shell_init(void) From a0713dc45c7b5dedaa1b0f64f19829ff69dce6ce Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Mon, 7 Oct 2024 22:28:41 +0530 Subject: [PATCH 054/299] [nrf fromtree] drivers: nrfwifi: Fix build errors when Util is enabled This path is disabled by default. Signed-off-by: Chaitanya Tata (cherry picked from commit cd736558ef51f16ffcce86a1a4cfb7a945c62852) --- drivers/wifi/nrfwifi/src/wifi_util.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/wifi/nrfwifi/src/wifi_util.c b/drivers/wifi/nrfwifi/src/wifi_util.c index cad5662f483..528c41fa184 100644 --- a/drivers/wifi/nrfwifi/src/wifi_util.c +++ b/drivers/wifi/nrfwifi/src/wifi_util.c @@ -287,7 +287,7 @@ static int nrf_wifi_util_tx_stats(const struct shell *sh, k_mutex_lock(&ctx->rpu_lock, K_FOREVER); if (!ctx->rpu_ctx) { - shell_fprintf(shell, + shell_fprintf(sh, SHELL_ERROR, "RPU context not initialized\n"); ret = -ENOEXEC; @@ -482,7 +482,7 @@ static int nrf_wifi_util_dump_rpu_stats(const struct shell *sh, k_mutex_lock(&ctx->rpu_lock, K_FOREVER); if (!ctx->rpu_ctx) { - shell_fprintf(shell, + shell_fprintf(sh, SHELL_ERROR, "RPU context not initialized\n"); ret = -ENOEXEC; From d0b13448eafdd517abca68464a085f0b9cfd47a7 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Tue, 22 Oct 2024 01:43:21 +0530 Subject: [PATCH 055/299] Revert "[nrf noup] samples: net: wifi: Enable Wi-Fi driver in sysbuild builds" This reverts commit fe339b14b3effd069458f5e4710f17cda8295229. Signed-off-by: Chaitanya Tata --- samples/net/wifi/Kconfig.sysbuild | 13 ------------- samples/net/wifi/sample.yaml | 2 -- 2 files changed, 15 deletions(-) delete mode 100644 samples/net/wifi/Kconfig.sysbuild diff --git a/samples/net/wifi/Kconfig.sysbuild b/samples/net/wifi/Kconfig.sysbuild deleted file mode 100644 index 158551060c5..00000000000 --- a/samples/net/wifi/Kconfig.sysbuild +++ /dev/null @@ -1,13 +0,0 @@ -# -# Copyright (c) 2024 Nordic Semiconductor ASA -# -# SPDX-License-Identifier: Apache-2.0 -# - -config WIFI_NRF70 - default y if BOARD_NRF7002DK_NRF5340_CPUAPP || \ - BOARD_NRF7002DK_NRF5340_CPUAPP_NS || \ - BOARD_NRF7002DK_NRF5340_CPUAPP_NRF7001 || \ - BOARD_NRF7002DK_NRF5340_CPUAPP_NRF7001_NS - -source "${ZEPHYR_BASE}/share/sysbuild/Kconfig" diff --git a/samples/net/wifi/sample.yaml b/samples/net/wifi/sample.yaml index 51c52edbd6f..1c106e4897a 100644 --- a/samples/net/wifi/sample.yaml +++ b/samples/net/wifi/sample.yaml @@ -53,7 +53,6 @@ tests: - nrf7002dk/nrf5340/cpuapp/nrf7001 sample.net.wifi.nrf7002ek: extra_args: - - SB_CONFIG_WIFI_NRF70=y - CONFIG_NRF_WIFI_BUILD_ONLY_MODE=y - SHIELD=nrf7002ek platform_allow: @@ -65,7 +64,6 @@ tests: - nucleo_h723zg sample.net.wifi.nrf7002eb: extra_args: - - SB_CONFIG_WIFI_NRF70=y - CONFIG_NRF_WIFI_BUILD_ONLY_MODE=y - SHIELD=nrf7002eb platform_allow: From 1d6965af80b24c938cc6abe70c40483ef849d56c Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Mon, 7 Oct 2024 22:29:35 +0530 Subject: [PATCH 056/299] [nrf fromtree] samples: net: wifi: Enable nRF70 Util in nRF70 build This ensures we catch basic issues in nRF70 util, which is handy in debugging. Signed-off-by: Chaitanya Tata (cherry picked from commit c08b846b4767bc3b02a3a288f17974bccd1adafe) --- samples/net/wifi/sample.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/samples/net/wifi/sample.yaml b/samples/net/wifi/sample.yaml index 1c106e4897a..e7ca553ecaf 100644 --- a/samples/net/wifi/sample.yaml +++ b/samples/net/wifi/sample.yaml @@ -64,6 +64,7 @@ tests: - nucleo_h723zg sample.net.wifi.nrf7002eb: extra_args: + - NRF70_UTIL=y - CONFIG_NRF_WIFI_BUILD_ONLY_MODE=y - SHIELD=nrf7002eb platform_allow: From be6309215a27d5b3fd1286d999f505dc5fe76a1c Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Wed, 16 Oct 2024 01:39:19 +0530 Subject: [PATCH 057/299] [nrf fromtree] drivers: nrfwifi: Fix build error This crept-in due to bad merge conflict resolution. Signed-off-by: Chaitanya Tata (cherry picked from commit 9eedb6d7c8e67b5c48ce016ce57f294e4d3207f1) --- drivers/wifi/nrfwifi/inc/fmac_main.h | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/drivers/wifi/nrfwifi/inc/fmac_main.h b/drivers/wifi/nrfwifi/inc/fmac_main.h index 9eb98baa518..57d4b8b9df5 100644 --- a/drivers/wifi/nrfwifi/inc/fmac_main.h +++ b/drivers/wifi/nrfwifi/inc/fmac_main.h @@ -133,7 +133,13 @@ void set_tx_pwr_ceil_default(struct nrf_wifi_tx_pwr_ceil_params *pwr_ceil_params const char *nrf_wifi_get_drv_version(void); enum nrf_wifi_status nrf_wifi_fmac_dev_add_zep(struct nrf_wifi_drv_priv_zep *drv_priv_zep); enum nrf_wifi_status nrf_wifi_fmac_dev_rem_zep(struct nrf_wifi_drv_priv_zep *drv_priv_zep); -#endif /* !CONFIG_NRF_WIFI_BUILD_ONLY_MODE */ +struct nrf_wifi_vif_ctx_zep *nrf_wifi_get_vif_ctx(struct net_if *iface); +#ifdef CONFIG_NRF_WIFI_RPU_RECOVERY +void nrf_wifi_rpu_recovery_cb(void *vif_ctx, + void *event_data, + unsigned int event_len); +#endif /* CONFIG_NRF_WIFI_RPU_RECOVERY */ +#endif /* !CONFIG_NRF70_OFFLOADED_RAW_TX */ #ifdef CONFIG_NRF_WIFI_BUILD_ONLY_MODE inline enum nrf_wifi_status nrf_wifi_fw_load(void *rpu_ctx) { @@ -144,11 +150,4 @@ inline enum nrf_wifi_status nrf_wifi_fw_load(void *rpu_ctx) #else enum nrf_wifi_status nrf_wifi_fw_load(void *rpu_ctx); #endif /* CONFIG_NRF_WIFI_BUILD_ONLY_MODE */ -#ifndef CONFIG_NRF70_OFFLOADED_RAW_TX -struct nrf_wifi_vif_ctx_zep *nrf_wifi_get_vif_ctx(struct net_if *iface); -#ifdef CONFIG_NRF_WIFI_RPU_RECOVERY -void nrf_wifi_rpu_recovery_cb(void *vif_ctx, - void *event_data, - unsigned int event_len); -#endif /* CONFIG_NRF_WIFI_RPU_RECOVERY */ #endif /* __ZEPHYR_FMAC_MAIN_H__ */ From 163b8dae1b7e776ef1c60dce4cd9729abad8a06e Mon Sep 17 00:00:00 2001 From: Fengming Ye Date: Wed, 16 Oct 2024 17:27:14 +0900 Subject: [PATCH 058/299] [nrf fromtree] modules: hostap: fix DPP build error Fix DPP build error when HOSTAPD enabled and DPP disabled. Guard hapd_dpp_dispatch in both CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP and CONFIG_WIFI_NM_HOSTAPD_AP. Signed-off-by: Fengming Ye (cherry picked from commit 9e8b7bd3adac4b232d0ae05aa443f7fee06a8e6c) --- modules/hostap/src/supp_api.c | 2 +- modules/hostap/src/supp_api.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/hostap/src/supp_api.c b/modules/hostap/src/supp_api.c index e39e358393a..aac8c097fb8 100644 --- a/modules/hostap/src/supp_api.c +++ b/modules/hostap/src/supp_api.c @@ -2057,7 +2057,6 @@ int supplicant_dpp_dispatch(const struct device *dev, struct wifi_dpp_params *pa os_free(cmd); return 0; } -#endif /* CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP */ #ifdef CONFIG_WIFI_NM_HOSTAPD_AP int hapd_dpp_dispatch(const struct device *dev, struct wifi_dpp_params *params) @@ -2091,3 +2090,4 @@ int hapd_dpp_dispatch(const struct device *dev, struct wifi_dpp_params *params) return 0; } #endif /* CONFIG_WIFI_NM_HOSTAPD_AP */ +#endif /* CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP */ diff --git a/modules/hostap/src/supp_api.h b/modules/hostap/src/supp_api.h index 9dc37cbd88a..d5edce626de 100644 --- a/modules/hostap/src/supp_api.h +++ b/modules/hostap/src/supp_api.h @@ -278,7 +278,6 @@ int supplicant_ap_sta_disconnect(const struct device *dev, * @return 0 for OK; -1 for ERROR */ int supplicant_dpp_dispatch(const struct device *dev, struct wifi_dpp_params *params); -#endif /* CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP */ #ifdef CONFIG_WIFI_NM_HOSTAPD_AP /** @@ -290,4 +289,5 @@ int supplicant_dpp_dispatch(const struct device *dev, struct wifi_dpp_params *pa */ int hapd_dpp_dispatch(const struct device *dev, struct wifi_dpp_params *params); #endif /* CONFIG_WIFI_NM_HOSTAPD_AP */ +#endif /* CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP */ #endif /* ZEPHYR_SUPP_MGMT_H */ From e566c615705a82b752fc16b945daaa94e123525e Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Thu, 19 Sep 2024 17:16:23 +0530 Subject: [PATCH 059/299] [nrf fromtree] doc: wifi: Update enumeration for EAP-TLS EAP-TLS enumeration is now changed due to recent SAE additions. Signed-off-by: Chaitanya Tata (cherry picked from commit 6cac9540ec44b44f551dbdca758f613bdd9571b7) --- doc/connectivity/networking/api/wifi.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/connectivity/networking/api/wifi.rst b/doc/connectivity/networking/api/wifi.rst index 7803a456055..f1bc744a831 100644 --- a/doc/connectivity/networking/api/wifi.rst +++ b/doc/connectivity/networking/api/wifi.rst @@ -44,7 +44,7 @@ To initiate Wi-Fi connection, the following command can be used: .. code-block:: console - uart:~$ wifi connect -s -k 5 -a anon -K whatever + uart:~$ wifi connect -s -k 7 -a anon -K whatever Server certificate is also provided in the same directory for testing purposes. Any AAA server can be used for testing purposes, for example, ``FreeRADIUS`` or ``hostapd``. From 5f00ff732595320a98f0376d199ef24696a0a15b Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Sun, 6 Oct 2024 15:05:34 +0530 Subject: [PATCH 060/299] [nrf fromtree] doc: wifi: Update build command for Enterprise mode Now, Enterprise mode has a separate overlay. Signed-off-by: Chaitanya Tata (cherry picked from commit b6430705572b53b712168255e934418c8b6f7b19) --- doc/connectivity/networking/api/wifi.rst | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/doc/connectivity/networking/api/wifi.rst b/doc/connectivity/networking/api/wifi.rst index f1bc744a831..84c407cd4a8 100644 --- a/doc/connectivity/networking/api/wifi.rst +++ b/doc/connectivity/networking/api/wifi.rst @@ -38,7 +38,15 @@ module. $ cp client.pem samples/net/wifi/test_certs/ $ cp client-key.pem samples/net/wifi/test_certs/ $ cp ca.pem samples/net/wifi/test_certs/ - $ west build -p -b samples/net/wifi + $ west build -p -b samples/net/wifi -- -DEXTRA_CONF_FILE=overlay-enterprise.conf + +For using variable size network buffer, the following overlay file can be used: + +.. code-block:: bash + + $ west build -p -b samples/net/wifi -- -DEXTRA_CONF_FILE=overlay-enterprise-variable-bufs.conf + + To initiate Wi-Fi connection, the following command can be used: From aa0853406737e462d7a681224d8e66c3a6dba579 Mon Sep 17 00:00:00 2001 From: Rex Chen Date: Sun, 29 Sep 2024 18:38:42 +0900 Subject: [PATCH 061/299] [nrf fromtree] samples: net: wifi: enable time checking for mbedtls cert files enable time checking for mbedtls certificate files, return failed if certificate files expired. Signed-off-by: Rex Chen (cherry picked from commit 6551e4083ff527437d79b78d4fa437b64f615cee) --- samples/net/wifi/boards/rd_rw612_bga.conf | 1 + 1 file changed, 1 insertion(+) diff --git a/samples/net/wifi/boards/rd_rw612_bga.conf b/samples/net/wifi/boards/rd_rw612_bga.conf index 1df1baa0be7..d20b5af0b3e 100644 --- a/samples/net/wifi/boards/rd_rw612_bga.conf +++ b/samples/net/wifi/boards/rd_rw612_bga.conf @@ -91,6 +91,7 @@ CONFIG_MBEDTLS=y CONFIG_MBEDTLS_BUILTIN=y CONFIG_MBEDTLS_USER_CONFIG_ENABLE=y CONFIG_MBEDTLS_USER_CONFIG_FILE="wpa_supp_els_pkc_mbedtls_config.h" +CONFIG_MBEDTLS_HAVE_TIME_DATE=y # Include els_pkc in build CONFIG_ENTROPY_GENERATOR=y From a5139521f777b25e3f1cfe1076ce893c36ec93c3 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Thu, 19 Sep 2024 17:15:29 +0530 Subject: [PATCH 062/299] [nrf fromtree] samples: wifi: Add overlays for Enterprise mode This overlay has all necessary configuration needed for Enterprise mode. Two variants are given, once with fixed size network buffers and other with variable size network buffers (still experimental). Signed-off-by: Chaitanya Tata (cherry picked from commit d107b04c9d708035779de23eb397da1bd69a85dc) --- samples/net/wifi/overlay-enterprise-variable-bufs.conf | 9 +++++++++ samples/net/wifi/overlay-enterprise.conf | 10 ++++++++++ 2 files changed, 19 insertions(+) create mode 100644 samples/net/wifi/overlay-enterprise-variable-bufs.conf create mode 100644 samples/net/wifi/overlay-enterprise.conf diff --git a/samples/net/wifi/overlay-enterprise-variable-bufs.conf b/samples/net/wifi/overlay-enterprise-variable-bufs.conf new file mode 100644 index 00000000000..627d77a9247 --- /dev/null +++ b/samples/net/wifi/overlay-enterprise-variable-bufs.conf @@ -0,0 +1,9 @@ +CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE=y +# EAP frames are ~1100 bytes, so, for efficiency, we set the data size to 1100 +CONFIG_NET_BUF_DATA_SIZE=1100 +# Use variable data size to reduce memory usage for small data packets +CONFIG_NET_BUF_VARIABLE_DATA_SIZE=y +# For TLS and X.509 processing MbedTLS needs large heap size and using separate heap +# for MbedTLS gives us more control over the heap size. +CONFIG_MBEDTLS_ENABLE_HEAP=y +CONFIG_MBEDTLS_HEAP_SIZE=55000 diff --git a/samples/net/wifi/overlay-enterprise.conf b/samples/net/wifi/overlay-enterprise.conf new file mode 100644 index 00000000000..34416282811 --- /dev/null +++ b/samples/net/wifi/overlay-enterprise.conf @@ -0,0 +1,10 @@ +CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE=y +# EAP frames are ~1100 bytes, so, need higher packet counts as default packet size is 128 +CONFIG_NET_PKT_TX_COUNT=36 +CONFIG_NET_PKT_RX_COUNT=36 +CONFIG_NET_BUF_TX_COUNT=72 +CONFIG_NET_BUF_RX_COUNT=36 +# For TLS and X.509 processing MbedTLS needs large heap size and using separate heap +# for MbedTLS gives us more control over the heap size. +CONFIG_MBEDTLS_ENABLE_HEAP=y +CONFIG_MBEDTLS_HEAP_SIZE=55000 From 0bae840c3ce3222bdb294ca1d4c9653074779fad Mon Sep 17 00:00:00 2001 From: Daniel DeGrasse Date: Thu, 19 Sep 2024 11:05:47 -0500 Subject: [PATCH 063/299] [nrf fromtree] net: l2: wifi: ensure certificates directory is created Ensure that the output certificates directory is created, where generated certificates will be placed. This fixes a build error seen when using `make` to build samples/net/wifi for the rd_rw612_bga board, where the output directory for generated certificates did not exist at build time. Signed-off-by: Daniel DeGrasse (cherry picked from commit bc8cb0be4ca5db93c567fbdef79fe10a42f8bdb2) --- subsys/net/l2/wifi/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/subsys/net/l2/wifi/CMakeLists.txt b/subsys/net/l2/wifi/CMakeLists.txt index bab445e8262..9f190dda307 100644 --- a/subsys/net/l2/wifi/CMakeLists.txt +++ b/subsys/net/l2/wifi/CMakeLists.txt @@ -26,6 +26,8 @@ endif() # Wi-Fi Enterprise test certificates handling set(gen_inc_dir ${ZEPHYR_BINARY_DIR}/misc/generated) set(gen_dir ${gen_inc_dir}/wifi_enterprise_test_certs) +# Create output directory for test certs +file(MAKE_DIRECTORY ${gen_dir}) # convert .pem files to array data at build time zephyr_include_directories(${gen_inc_dir}) From 4867660f00df7bfba7d01cfc252544117565a775 Mon Sep 17 00:00:00 2001 From: Pisit Sawangvonganan Date: Sat, 21 Sep 2024 15:42:59 +0700 Subject: [PATCH 064/299] [nrf fromtree] net: wifi: shell: enhance consistency in `cmd_wifi_dpp_ap_auth_init` The `cmd_wifi_dpp_ap_auth_init` function was added but is not yet aligned with others. This update enhances consistency with the following changes: - Unified the order of declaration for `opt`, `opt_index`, `state`, and `long_options`. - Wrapped lines in the `long_options` declaration to prevent them from extending too far to the right. - Applied `struct option` as `static const` - Unified the wrapping of `getopt_long` calls, regardless of the length of the `options` string. - Using `getopt_state` to access `optarg` and also `optopt` offers a better alternative to direct global access. Signed-off-by: Pisit Sawangvonganan (cherry picked from commit 7d1953918a615f53ef06a020d7ebc645576fb3ba) --- subsys/net/l2/wifi/wifi_shell.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 0817f256b6c..70a4e9a8e59 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -2617,24 +2617,27 @@ static int cmd_wifi_dpp_ap_qr_code(const struct shell *sh, size_t argc, char *ar static int cmd_wifi_dpp_ap_auth_init(const struct shell *sh, size_t argc, char *argv[]) { - int ret = 0; - struct net_if *iface = net_if_get_wifi_sap(); - struct wifi_dpp_params params = {0}; int opt; int opt_index = 0; struct getopt_state *state; - static struct option long_options[] = {{"peer", required_argument, 0, 'p'}, {0, 0, 0, 0}}; + static const struct option long_options[] = { + {"peer", required_argument, 0, 'p'}, + {0, 0, 0, 0}}; + int ret = 0; + struct net_if *iface = net_if_get_wifi_sap(); + struct wifi_dpp_params params = {0}; params.action = WIFI_DPP_AUTH_INIT; - while ((opt = getopt_long(argc, argv, "p:", long_options, &opt_index)) != -1) { + while ((opt = getopt_long(argc, argv, "p:", + long_options, &opt_index)) != -1) { state = getopt_state_get(); switch (opt) { case 'p': - params.auth_init.peer = shell_strtol(optarg, 10, &ret); + params.auth_init.peer = shell_strtol(state->optarg, 10, &ret); break; default: - PR_ERROR("Invalid option %c\n", optopt); + PR_ERROR("Invalid option %c\n", state->optopt); return -EINVAL; } From a5b2b24148a71d23c667ac5303e94faf119c8ad8 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Tue, 22 Oct 2024 00:51:15 +0530 Subject: [PATCH 065/299] Revert "[nrf fromlist] net: wifi: Fix DPP disabled build" This reverts commit 330eb8146a5b694fb90d738cc04e6ef76d80f636. Signed-off-by: Chaitanya Tata --- include/zephyr/net/wifi_mgmt.h | 8 -------- modules/hostap/src/supp_api.c | 1 - modules/hostap/src/supp_api.h | 1 - modules/hostap/src/supp_main.c | 2 -- subsys/net/l2/wifi/wifi_mgmt.c | 3 --- subsys/net/l2/wifi/wifi_shell.c | 6 ------ 6 files changed, 21 deletions(-) diff --git a/include/zephyr/net/wifi_mgmt.h b/include/zephyr/net/wifi_mgmt.h index 653197bf938..dcf6e7001d0 100644 --- a/include/zephyr/net/wifi_mgmt.h +++ b/include/zephyr/net/wifi_mgmt.h @@ -219,13 +219,11 @@ NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_RTS_THRESHOLD); NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_AP_CONFIG_PARAM); -#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP /** Request a Wi-Fi DPP operation */ #define NET_REQUEST_WIFI_DPP \ (_NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_DPP) NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_DPP); -#endif /* CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP */ #ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_WNM /** Request a Wi-Fi BTM query */ @@ -852,7 +850,6 @@ struct wifi_ap_config_params { uint32_t max_num_sta; }; -#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP /** @brief Wi-Fi DPP configuration parameter */ /** Wi-Fi DPP QR-CODE in string max len for SHA512 */ #define WIFI_DPP_QRCODE_MAX_LEN 255 @@ -1029,8 +1026,6 @@ struct wifi_dpp_params { }; }; -#endif /* CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP */ - #include /** Scan result callback @@ -1237,8 +1232,6 @@ struct wifi_mgmt_ops { * @return 0 if ok, < 0 if error */ int (*ap_config_params)(const struct device *dev, struct wifi_ap_config_params *params); - -#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP /** Dispatch DPP operations by action enum, with or without arguments in string format * * @param dev Pointer to the device structure for the driver instance @@ -1247,7 +1240,6 @@ struct wifi_mgmt_ops { * @return 0 if ok, < 0 if error */ int (*dpp_dispatch)(const struct device *dev, struct wifi_dpp_params *params); -#endif /* CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP */ /** Flush PMKSA cache entries * * @param dev Pointer to the device structure for the driver instance. diff --git a/modules/hostap/src/supp_api.c b/modules/hostap/src/supp_api.c index aac8c097fb8..af3df3c6278 100644 --- a/modules/hostap/src/supp_api.c +++ b/modules/hostap/src/supp_api.c @@ -1767,7 +1767,6 @@ int supplicant_ap_sta_disconnect(const struct device *dev, } #endif /* CONFIG_AP */ -#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP static const char *dpp_params_to_args_curve(int curve) { switch (curve) { diff --git a/modules/hostap/src/supp_api.h b/modules/hostap/src/supp_api.h index d5edce626de..12298ad6544 100644 --- a/modules/hostap/src/supp_api.h +++ b/modules/hostap/src/supp_api.h @@ -269,7 +269,6 @@ int supplicant_ap_sta_disconnect(const struct device *dev, #endif /* CONFIG_AP */ -#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP /** * @brief Dispatch DPP operations for STA * diff --git a/modules/hostap/src/supp_main.c b/modules/hostap/src/supp_main.c index b111f43a4e8..ce91c1a6e8e 100644 --- a/modules/hostap/src/supp_main.c +++ b/modules/hostap/src/supp_main.c @@ -80,9 +80,7 @@ static const struct wifi_mgmt_ops mgmt_ops = { .ap_disable = supplicant_ap_disable, .ap_sta_disconnect = supplicant_ap_sta_disconnect, #endif /* CONFIG_AP */ -#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP .dpp_dispatch = supplicant_dpp_dispatch, -#endif /* CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP */ .pmksa_flush = supplicant_pmksa_flush, #ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE .enterprise_creds = supplicant_add_enterprise_creds, diff --git a/subsys/net/l2/wifi/wifi_mgmt.c b/subsys/net/l2/wifi/wifi_mgmt.c index 3cea624b6e3..6e0de6f42b8 100644 --- a/subsys/net/l2/wifi/wifi_mgmt.c +++ b/subsys/net/l2/wifi/wifi_mgmt.c @@ -852,7 +852,6 @@ static int wifi_set_rts_threshold(uint32_t mgmt_request, struct net_if *iface, NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_RTS_THRESHOLD, wifi_set_rts_threshold); -#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP static int wifi_dpp(uint32_t mgmt_request, struct net_if *iface, void *data, size_t len) { @@ -869,8 +868,6 @@ static int wifi_dpp(uint32_t mgmt_request, struct net_if *iface, NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_DPP, wifi_dpp); -#endif /* CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP */ - static int wifi_pmksa_flush(uint32_t mgmt_request, struct net_if *iface, void *data, size_t len) { diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 70a4e9a8e59..4adbf48c8c8 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -2143,7 +2143,6 @@ static int cmd_wifi_version(const struct shell *sh, size_t argc, char *argv[]) return 0; } -#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP static int parse_dpp_args_auth_init(const struct shell *sh, size_t argc, char *argv[], struct wifi_dpp_params *params) { @@ -2681,7 +2680,6 @@ static int cmd_wifi_dpp_reconfig(const struct shell *sh, size_t argc, char *argv return 0; } -#endif /* CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP */ static int cmd_wifi_pmksa_flush(const struct shell *sh, size_t argc, char *argv[]) { struct net_if *iface = net_if_get_wifi_sta(); @@ -2759,7 +2757,6 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_twt_ops, SHELL_SUBCMD_SET_END ); -#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP SHELL_STATIC_SUBCMD_SET_CREATE( wifi_cmd_dpp, SHELL_CMD_ARG(configurator_add, NULL, @@ -2836,7 +2833,6 @@ SHELL_STATIC_SUBCMD_SET_CREATE( cmd_wifi_dpp_reconfig, 2, 0), SHELL_SUBCMD_SET_END ); -#endif /* CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP */ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, SHELL_CMD_ARG(version, NULL, "Print Wi-Fi Driver and Firmware versions\n", @@ -2973,9 +2969,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, ".\n", cmd_wifi_set_rts_threshold, 1, 1), -#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP SHELL_CMD(dpp, &wifi_cmd_dpp, "DPP actions\n", NULL), -#endif /* CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP */ SHELL_CMD_ARG(pmksa_flush, NULL, "Flush PMKSA cache entries.\n", cmd_wifi_pmksa_flush, 1, 0), From 359ef372541f85100f9654c56e9887a81d198745 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Mon, 30 Sep 2024 21:52:16 +0200 Subject: [PATCH 066/299] [nrf fromtree] net: wifi: Fix DPP disabled build In case WPA supplicant disabled DPP, we need to compile out the corresponding DPP code in Wi-Fi shell too. Signed-off-by: Chaitanya Tata (cherry picked from commit 1da74ef705bcf1723a3271266622948251253c0a) --- include/zephyr/net/wifi_mgmt.h | 7 +++++++ modules/hostap/src/supp_api.c | 2 ++ modules/hostap/src/supp_api.h | 2 ++ modules/hostap/src/supp_main.c | 2 ++ subsys/net/l2/wifi/wifi_mgmt.c | 3 +++ subsys/net/l2/wifi/wifi_shell.c | 6 ++++++ 6 files changed, 22 insertions(+) diff --git a/include/zephyr/net/wifi_mgmt.h b/include/zephyr/net/wifi_mgmt.h index dcf6e7001d0..528e72dffe9 100644 --- a/include/zephyr/net/wifi_mgmt.h +++ b/include/zephyr/net/wifi_mgmt.h @@ -219,11 +219,13 @@ NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_RTS_THRESHOLD); NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_AP_CONFIG_PARAM); +#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP /** Request a Wi-Fi DPP operation */ #define NET_REQUEST_WIFI_DPP \ (_NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_DPP) NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_DPP); +#endif /* CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP */ #ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_WNM /** Request a Wi-Fi BTM query */ @@ -850,6 +852,7 @@ struct wifi_ap_config_params { uint32_t max_num_sta; }; +#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP /** @brief Wi-Fi DPP configuration parameter */ /** Wi-Fi DPP QR-CODE in string max len for SHA512 */ #define WIFI_DPP_QRCODE_MAX_LEN 255 @@ -1025,6 +1028,7 @@ struct wifi_dpp_params { char resp[WIFI_DPP_QRCODE_MAX_LEN + 1]; }; }; +#endif /* CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP */ #include @@ -1232,6 +1236,8 @@ struct wifi_mgmt_ops { * @return 0 if ok, < 0 if error */ int (*ap_config_params)(const struct device *dev, struct wifi_ap_config_params *params); + +#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP /** Dispatch DPP operations by action enum, with or without arguments in string format * * @param dev Pointer to the device structure for the driver instance @@ -1240,6 +1246,7 @@ struct wifi_mgmt_ops { * @return 0 if ok, < 0 if error */ int (*dpp_dispatch)(const struct device *dev, struct wifi_dpp_params *params); +#endif /* CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP */ /** Flush PMKSA cache entries * * @param dev Pointer to the device structure for the driver instance. diff --git a/modules/hostap/src/supp_api.c b/modules/hostap/src/supp_api.c index af3df3c6278..f1a3017b70d 100644 --- a/modules/hostap/src/supp_api.c +++ b/modules/hostap/src/supp_api.c @@ -1767,6 +1767,7 @@ int supplicant_ap_sta_disconnect(const struct device *dev, } #endif /* CONFIG_AP */ +#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP static const char *dpp_params_to_args_curve(int curve) { switch (curve) { @@ -2056,6 +2057,7 @@ int supplicant_dpp_dispatch(const struct device *dev, struct wifi_dpp_params *pa os_free(cmd); return 0; } +#endif /* CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP */ #ifdef CONFIG_WIFI_NM_HOSTAPD_AP int hapd_dpp_dispatch(const struct device *dev, struct wifi_dpp_params *params) diff --git a/modules/hostap/src/supp_api.h b/modules/hostap/src/supp_api.h index 12298ad6544..1abcd2166c9 100644 --- a/modules/hostap/src/supp_api.h +++ b/modules/hostap/src/supp_api.h @@ -269,6 +269,7 @@ int supplicant_ap_sta_disconnect(const struct device *dev, #endif /* CONFIG_AP */ +#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP /** * @brief Dispatch DPP operations for STA * @@ -277,6 +278,7 @@ int supplicant_ap_sta_disconnect(const struct device *dev, * @return 0 for OK; -1 for ERROR */ int supplicant_dpp_dispatch(const struct device *dev, struct wifi_dpp_params *params); +#endif /* CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP */ #ifdef CONFIG_WIFI_NM_HOSTAPD_AP /** diff --git a/modules/hostap/src/supp_main.c b/modules/hostap/src/supp_main.c index ce91c1a6e8e..b111f43a4e8 100644 --- a/modules/hostap/src/supp_main.c +++ b/modules/hostap/src/supp_main.c @@ -80,7 +80,9 @@ static const struct wifi_mgmt_ops mgmt_ops = { .ap_disable = supplicant_ap_disable, .ap_sta_disconnect = supplicant_ap_sta_disconnect, #endif /* CONFIG_AP */ +#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP .dpp_dispatch = supplicant_dpp_dispatch, +#endif /* CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP */ .pmksa_flush = supplicant_pmksa_flush, #ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE .enterprise_creds = supplicant_add_enterprise_creds, diff --git a/subsys/net/l2/wifi/wifi_mgmt.c b/subsys/net/l2/wifi/wifi_mgmt.c index 6e0de6f42b8..3cea624b6e3 100644 --- a/subsys/net/l2/wifi/wifi_mgmt.c +++ b/subsys/net/l2/wifi/wifi_mgmt.c @@ -852,6 +852,7 @@ static int wifi_set_rts_threshold(uint32_t mgmt_request, struct net_if *iface, NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_RTS_THRESHOLD, wifi_set_rts_threshold); +#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP static int wifi_dpp(uint32_t mgmt_request, struct net_if *iface, void *data, size_t len) { @@ -868,6 +869,8 @@ static int wifi_dpp(uint32_t mgmt_request, struct net_if *iface, NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_DPP, wifi_dpp); +#endif /* CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP */ + static int wifi_pmksa_flush(uint32_t mgmt_request, struct net_if *iface, void *data, size_t len) { diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 4adbf48c8c8..70a4e9a8e59 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -2143,6 +2143,7 @@ static int cmd_wifi_version(const struct shell *sh, size_t argc, char *argv[]) return 0; } +#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP static int parse_dpp_args_auth_init(const struct shell *sh, size_t argc, char *argv[], struct wifi_dpp_params *params) { @@ -2680,6 +2681,7 @@ static int cmd_wifi_dpp_reconfig(const struct shell *sh, size_t argc, char *argv return 0; } +#endif /* CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP */ static int cmd_wifi_pmksa_flush(const struct shell *sh, size_t argc, char *argv[]) { struct net_if *iface = net_if_get_wifi_sta(); @@ -2757,6 +2759,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_twt_ops, SHELL_SUBCMD_SET_END ); +#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP SHELL_STATIC_SUBCMD_SET_CREATE( wifi_cmd_dpp, SHELL_CMD_ARG(configurator_add, NULL, @@ -2833,6 +2836,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE( cmd_wifi_dpp_reconfig, 2, 0), SHELL_SUBCMD_SET_END ); +#endif /* CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP */ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, SHELL_CMD_ARG(version, NULL, "Print Wi-Fi Driver and Firmware versions\n", @@ -2969,7 +2973,9 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, ".\n", cmd_wifi_set_rts_threshold, 1, 1), +#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP SHELL_CMD(dpp, &wifi_cmd_dpp, "DPP actions\n", NULL), +#endif /* CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP */ SHELL_CMD_ARG(pmksa_flush, NULL, "Flush PMKSA cache entries.\n", cmd_wifi_pmksa_flush, 1, 0), From 461a4ed985655993f04c6355be745ece15d5a55c Mon Sep 17 00:00:00 2001 From: Jukka Rissanen Date: Wed, 9 Oct 2024 15:28:01 +0300 Subject: [PATCH 067/299] [nrf fromtree] wifi: shell: Add missing newlines when printing error The parse_number() did not print newline after error or warning message. Signed-off-by: Jukka Rissanen (cherry picked from commit 8105f70d7a0504ce88132a3247fb204b6caa2226) --- subsys/net/l2/wifi/wifi_shell.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 70a4e9a8e59..ac5240a918d 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -125,16 +125,16 @@ static bool parse_number(const struct shell *sh, long *param, char *str, } if (*endptr != '\0') { - PR_ERROR("Invalid number: %s", str_tmp); + PR_ERROR("Invalid number: %s\n", str_tmp); return false; } if ((num) < (min) || (num) > (max)) { if (pname) { - PR_WARNING("%s value out of range: %s, (%ld-%ld)", + PR_WARNING("%s value out of range: %s, (%ld-%ld)\n", pname, str_tmp, min, max); } else { - PR_WARNING("Value out of range: %s, (%ld-%ld)", + PR_WARNING("Value out of range: %s, (%ld-%ld)\n", str_tmp, min, max); } return false; From 8c70792036b76deb37ee7bd15da5d4d0c3da931e Mon Sep 17 00:00:00 2001 From: Jukka Rissanen Date: Wed, 9 Oct 2024 15:32:58 +0300 Subject: [PATCH 068/299] [nrf fromtree] wifi: shell: btm_query: Fix invalid pointer cast The 11v_btm_query shell command was calling parse_number() using a pointer to uint8_t. This will cause memory overwrite and possible crash. Convert to use long temporary value to avoid this. Fix also the output prints in case of an error. Signed-off-by: Jukka Rissanen (cherry picked from commit c6aa9e3803f10ac44152df604089495f37037094) --- subsys/net/l2/wifi/wifi_shell.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index ac5240a918d..576de45a437 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -1674,16 +1674,19 @@ static int cmd_wifi_btm_query(const struct shell *sh, size_t argc, char *argv[]) { struct net_if *iface = net_if_get_first_wifi(); uint8_t query_reason = 0; + long tmp = 0; context.sh = sh; - if (!parse_number(sh, (long *)&query_reason, argv[1], NULL, + if (!parse_number(sh, &tmp, argv[1], NULL, WIFI_BTM_QUERY_REASON_UNSPECIFIED, WIFI_BTM_QUERY_REASON_LEAVING_ESS)) { return -EINVAL; } + query_reason = tmp; + if (net_mgmt(NET_REQUEST_WIFI_BTM_QUERY, iface, &query_reason, sizeof(query_reason))) { - PR_WARNING("Setting BTM query Reason failed..Reason :%d\n", query_reason); + PR_WARNING("Setting BTM query Reason failed. Reason : %d\n", query_reason); return -ENOEXEC; } From c3d56f0de4da50731e221669df98ade9138bbc74 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Fri, 20 Sep 2024 00:17:52 +0530 Subject: [PATCH 069/299] [nrf fromtree] net: wifi: Fix PEM certificate parsing errors MbedTLS specifically checks for null-terminator, else it skips PEM format processing and tries to parse it as DER causing parsing failures. Signed-off-by: Chaitanya Tata (cherry picked from commit 4c5a72f9e0ecd03f8e1c4e93aa9cf3f58fb79616) --- subsys/net/l2/wifi/wifi_shell.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 576de45a437..c40edab2fd7 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -32,14 +32,17 @@ LOG_MODULE_REGISTER(net_wifi_shell, LOG_LEVEL_INF); #ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE static const char ca_cert_test[] = { #include + '\0' }; static const char client_cert_test[] = { #include + '\0' }; static const char client_key_test[] = { #include + '\0' }; #endif From 0af7001bad89f0ed89c4ebdc28953ef7c66cda6c Mon Sep 17 00:00:00 2001 From: Maochen Wang Date: Wed, 16 Oct 2024 12:10:01 +0800 Subject: [PATCH 070/299] [nrf fromtree] net: l2: wifi: fix AP sets band failed with channel 0 Should support setting band for both STA and SAP mode. Signed-off-by: Maochen Wang (cherry picked from commit 4af697ad6b1c1587201efd8660e73799bc9e803a) --- subsys/net/l2/wifi/wifi_shell.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index c40edab2fd7..22e3f0e83e7 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -587,7 +587,8 @@ static int __wifi_args_to_params(const struct shell *sh, size_t argc, char *argv params->channel = channel; break; case 'b': - if (iface_mode == WIFI_MODE_INFRA) { + if (iface_mode == WIFI_MODE_INFRA || + iface_mode == WIFI_MODE_AP) { switch (atoi(state->optarg)) { case 2: params->band = WIFI_FREQ_BAND_2_4_GHZ; From 4162b773da57781e5a6661356aa597b124dbbbe3 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Sat, 12 Oct 2024 02:45:02 +0530 Subject: [PATCH 071/299] [nrf fromtree] modules: hostap: Fix memory leak of network In "connect" all networks are removed and new network is always added, but in disconnect the network isn't deleted, so, the memory is unnecessarily held till next connect. This is not exactly a leak, but if someone profiles using "kernel heap" then this can be construed as a leak. Fix this by removing network during the disconnection (for now "all") so that the memory can be used by someone else. Signed-off-by: Chaitanya Tata (cherry picked from commit be65de0d09d19ba2d03e106b81183ec7af996d24) --- modules/hostap/src/supp_api.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/hostap/src/supp_api.c b/modules/hostap/src/supp_api.c index f1a3017b70d..ea4afcbcbf4 100644 --- a/modules/hostap/src/supp_api.c +++ b/modules/hostap/src/supp_api.c @@ -840,6 +840,10 @@ static int wpas_disconnect_network(const struct device *dev, int cur_mode) wifi_mgmt_raise_disconnect_complete_event(iface, ret); } + if (!wpa_cli_cmd_v("remove_network all")) { + wpa_printf(MSG_ERROR, "Failed to remove all networks"); + } + return ret; } From ff0bd82792ac46991768801e674cf3d7c72d4f67 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Sat, 12 Oct 2024 02:52:02 +0530 Subject: [PATCH 072/299] [nrf fromtree] manifest: hostap: Pull fix for WPA3 connection Fixes WPA3 connection regression. Signed-off-by: Chaitanya Tata (cherry picked from commit 734fc58b62eac8a8091f29b98224d433d514a00c) --- west.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/west.yml b/west.yml index e87e6405424..cb4a1de93b2 100644 --- a/west.yml +++ b/west.yml @@ -259,7 +259,7 @@ manifest: - hal - name: hostap path: modules/lib/hostap - revision: 7c32520564908e1220976b6c185dec296b6d4a80 + revision: ac59d28778b20cd68702f55dad2a27d648e3d571 - name: libmetal revision: a6851ba6dba8c9e87d00c42f171a822f7a29639b path: modules/hal/libmetal From bd030766909f9b61892d3d499ceb36003f2e6ac3 Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Mon, 14 Oct 2024 09:57:17 +0200 Subject: [PATCH 073/299] [nrf fromtree] manifest: hal_nordic: include lpcomp-int-dis-on-stop patch Update hal_nordic manifest to include lpcomp-int-dis-on-stop patch Signed-off-by: Bjarki Arge Andreasen (cherry picked from commit 0f6a35c36393976c24886d72b6026ba327360bad) --- west.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/west.yml b/west.yml index cb4a1de93b2..58c40f7b327 100644 --- a/west.yml +++ b/west.yml @@ -188,7 +188,7 @@ manifest: groups: - hal - name: hal_nordic - revision: d5c70305b2389641b0a166d0714775a1b13319a2 + revision: 1abc0519d768c203eb27d19a0fa26dbae07e2b71 path: modules/hal/nordic groups: - hal From a64b8ff0146d3e4e627311862b3767aa456e8e57 Mon Sep 17 00:00:00 2001 From: Vivekananda Uppunda Date: Mon, 7 Oct 2024 09:28:55 +0530 Subject: [PATCH 074/299] [nrf fromtree] manifest: Pull promiscuous mode filtering support in driver This pulls in changes to support promiscuous mode filtering in driver. Signed-off-by: Vivekananda Uppunda (cherry picked from commit 2f23313e37e431d64972133e3c946a2829dad142) --- west.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/west.yml b/west.yml index 58c40f7b327..126048a0a1c 100644 --- a/west.yml +++ b/west.yml @@ -188,7 +188,7 @@ manifest: groups: - hal - name: hal_nordic - revision: 1abc0519d768c203eb27d19a0fa26dbae07e2b71 + revision: af91488c6edc4cebaf8b072c8bb258122a055cdb path: modules/hal/nordic groups: - hal From e5c5f0942fb6d16f6e4dcc217ff154118254e090 Mon Sep 17 00:00:00 2001 From: Vivekananda Uppunda Date: Mon, 7 Oct 2024 09:20:40 +0530 Subject: [PATCH 075/299] [nrf fromtree] drivers: wifi: nrfwifi: Promiscuous mode filtering support in driver This set of changes brings in promiscuous mode filtering support in driver. Since, firmware would be unable to filter packets due to connection issues, the filtering support for promiscuous mode is moved to the driver. Signed-off-by: Vivekananda Uppunda (cherry picked from commit c9b56de0400422be2385c45abbac0d3138bd4b11) --- drivers/wifi/nrfwifi/src/fmac_main.c | 2 +- drivers/wifi/nrfwifi/src/wifi_mgmt.c | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/drivers/wifi/nrfwifi/src/fmac_main.c b/drivers/wifi/nrfwifi/src/fmac_main.c index 4778111579e..fce5da67722 100644 --- a/drivers/wifi/nrfwifi/src/fmac_main.c +++ b/drivers/wifi/nrfwifi/src/fmac_main.c @@ -715,7 +715,7 @@ static int nrf_wifi_drv_main_zep(const struct device *dev) callbk_fns.if_carr_state_chg_callbk_fn = nrf_wifi_if_carr_state_chg; callbk_fns.rx_frm_callbk_fn = nrf_wifi_if_rx_frm; #if defined(CONFIG_NRF70_RAW_DATA_RX) || defined(CONFIG_NRF70_PROMISC_DATA_RX) - callbk_fns.rx_sniffer_frm_callbk_fn = nrf_wifi_if_sniffer_rx_frm; + callbk_fns.sniffer_callbk_fn = nrf_wifi_if_sniffer_rx_frm; #endif /* CONFIG_NRF70_RAW_DATA_RX || CONFIG_NRF70_PROMISC_DATA_RX */ #endif rx_buf_pools[0].num_bufs = rx1_num_bufs; diff --git a/drivers/wifi/nrfwifi/src/wifi_mgmt.c b/drivers/wifi/nrfwifi/src/wifi_mgmt.c index 65f6c217bfe..5effb759fa4 100644 --- a/drivers/wifi/nrfwifi/src/wifi_mgmt.c +++ b/drivers/wifi/nrfwifi/src/wifi_mgmt.c @@ -935,6 +935,21 @@ int nrf_wifi_filter(const struct device *dev, def_dev_ctx = wifi_dev_priv(fmac_dev_ctx); if (filter->oper == WIFI_MGMT_SET) { + /** + * If promiscuous mode is enabled, filter settings + * cannot be plumbed to the lower layers as that might + * affect connectivity. Save the filter settings in the + * driver and filter packet type on packet receive by + * checking the 802.11 header in the packet + */ + if (((def_dev_ctx->vif_ctx[vif_ctx_zep->vif_idx]->mode) & + (NRF_WIFI_PROMISCUOUS_MODE)) == NRF_WIFI_PROMISCUOUS_MODE) { + def_dev_ctx->vif_ctx[vif_ctx_zep->vif_idx]->packet_filter = + filter->filter; + ret = 0; + goto out; + } + /** * In case a user sets data + management + ctrl bits * or all the filter bits. Map it to bit 0 set to From fa20ccc366513dbd06994d15a3c4f4880dbe2b1a Mon Sep 17 00:00:00 2001 From: Vivekananda Uppunda Date: Tue, 8 Oct 2024 10:03:40 +0530 Subject: [PATCH 076/299] [nrf fromtree] drivers: wifi: nrfwifi: Add promiscuous mode support functions This adds promiscuous mode support functions into build for filter operation when the configuration CONFIG_NRF70_PROMISC_DATA_RX is enabled. Signed-off-by: Vivekananda Uppunda (cherry picked from commit da0c30d52ad3af4bf7a866e866fcaf860a73386e) --- drivers/wifi/nrfwifi/CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/wifi/nrfwifi/CMakeLists.txt b/drivers/wifi/nrfwifi/CMakeLists.txt index 41611af08a1..0cd45829318 100644 --- a/drivers/wifi/nrfwifi/CMakeLists.txt +++ b/drivers/wifi/nrfwifi/CMakeLists.txt @@ -128,6 +128,10 @@ zephyr_library_sources_ifdef(CONFIG_NRF70_STA_MODE ${OS_AGNOSTIC_BASE}/fw_if/umac_if/src/fmac_util.c ) +zephyr_library_sources_ifdef(CONFIG_NRF70_PROMISC_DATA_RX + ${OS_AGNOSTIC_BASE}/fw_if/umac_if/src/fmac_promisc.c +) + zephyr_library_sources_ifdef(CONFIG_NRF70_ON_QSPI src/qspi/src/qspi_if.c ) From 1afb1bfcd190d3b2c4827ab625b078816ab636a8 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Wed, 16 Oct 2024 02:35:30 +0530 Subject: [PATCH 077/299] [nrf fromtree] drivers: wifi: Add regulatory debug log This log helps in identifing if the event is solicited or not. Signed-off-by: Chaitanya Tata (cherry picked from commit f333e1f00fe0757464eea17c43c88211e9069e3b) --- drivers/wifi/nrfwifi/src/fmac_main.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/wifi/nrfwifi/src/fmac_main.c b/drivers/wifi/nrfwifi/src/fmac_main.c index fce5da67722..30bd150e811 100644 --- a/drivers/wifi/nrfwifi/src/fmac_main.c +++ b/drivers/wifi/nrfwifi/src/fmac_main.c @@ -453,6 +453,8 @@ void reg_change_callbk_fn(void *vif_ctx, struct nrf_wifi_ctx_zep *rpu_ctx_zep = NULL; struct nrf_wifi_fmac_dev_ctx *fmac_dev_ctx = NULL; + LOG_DBG("%s: Regulatory change event received", __func__); + vif_ctx_zep = vif_ctx; if (!vif_ctx_zep) { From 5c11cb7de70d3a4427732c81f1aa7638652887a5 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Wed, 16 Oct 2024 03:09:06 +0530 Subject: [PATCH 078/299] [nrf fromtree] manifest: hal_nordic: Pull the flag to identify unsolicited reg event This flag can be used to drop unsolicited regulatory event as it's not supported. Signed-off-by: Chaitanya Tata (cherry picked from commit 0baff426c4acfd1a12005c4198f8b62e4abcc853) --- west.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/west.yml b/west.yml index 126048a0a1c..31647ae878c 100644 --- a/west.yml +++ b/west.yml @@ -188,7 +188,7 @@ manifest: groups: - hal - name: hal_nordic - revision: af91488c6edc4cebaf8b072c8bb258122a055cdb + revision: 5f1210074cb8bb7ec66317af294596a97ac48815 path: modules/hal/nordic groups: - hal From 591291f2e905b7e80587a317350063db506ef67f Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Wed, 16 Oct 2024 02:43:28 +0530 Subject: [PATCH 079/299] [nrf fromtree] drivers: wifi: Fix memory leak in regulatory processing During Wi-Fi connection UMAC sends an unsolicited regulatory change event but the driver code always assumes that this event is solicited hence doesn't free the memory for the event. Fix this by dropping the unsolicited event as it's not supported yet. Fixes #79733. Signed-off-by: Chaitanya Tata (cherry picked from commit ea7d3bea9360a850a2586ade12f170fbfdeaf71a) --- drivers/wifi/nrfwifi/src/fmac_main.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/wifi/nrfwifi/src/fmac_main.c b/drivers/wifi/nrfwifi/src/fmac_main.c index 30bd150e811..82ea0f99267 100644 --- a/drivers/wifi/nrfwifi/src/fmac_main.c +++ b/drivers/wifi/nrfwifi/src/fmac_main.c @@ -474,6 +474,12 @@ void reg_change_callbk_fn(void *vif_ctx, return; } + if (!fmac_dev_ctx->waiting_for_reg_event) { + LOG_DBG("%s: Unsolicited regulatory change event", __func__); + /* TODO: Handle unsolicited regulatory change event */ + return; + } + fmac_dev_ctx->reg_change = k_malloc(sizeof(struct nrf_wifi_event_regulatory_change)); if (!fmac_dev_ctx->reg_change) { LOG_ERR("%s: Failed to allocate memory for reg_change", __func__); From e8f571603f91001cc6cc358afd31e3d2bea5863c Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Wed, 16 Oct 2024 02:49:19 +0530 Subject: [PATCH 080/299] [nrf fromtree] drivers: wifi: Clean up exit path Fix couple of bugs in exit path: - In case of calloc failure, return's without unlocking - memory is freed outside lock, in case of a tiny window of race, this can cause a crash when this function is called from two threads. Signed-off-by: Chaitanya Tata (cherry picked from commit a21648d7e6df946f3cc1676228f519b5fc054944) --- drivers/wifi/nrfwifi/src/net_if.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/wifi/nrfwifi/src/net_if.c b/drivers/wifi/nrfwifi/src/net_if.c index 81369186533..b8ca8915ff4 100644 --- a/drivers/wifi/nrfwifi/src/net_if.c +++ b/drivers/wifi/nrfwifi/src/net_if.c @@ -440,7 +440,7 @@ static void ip_maddr_event_handler(struct net_if *iface, ret = k_mutex_lock(&vif_ctx_zep->vif_lock, K_FOREVER); if (ret != 0) { LOG_ERR("%s: Failed to lock vif_lock", __func__); - goto out; + return; } rpu_ctx_zep = vif_ctx_zep->rpu_ctx_zep; @@ -455,7 +455,7 @@ static void ip_maddr_event_handler(struct net_if *iface, if (!mcast_info) { LOG_ERR("%s: Unable to allocate memory of size %d " "for mcast_info", __func__, sizeof(*mcast_info)); - return; + goto unlock; } switch (addr->family) { @@ -492,9 +492,8 @@ static void ip_maddr_event_handler(struct net_if *iface, sizeof(mac_string_buf))); } unlock: - k_mutex_unlock(&vif_ctx_zep->vif_lock); -out: k_free(mcast_info); + k_mutex_unlock(&vif_ctx_zep->vif_lock); } #endif /* CONFIG_NRF70_STA_MODE */ From e039e8ec535cc1bc8a181a763fd858cf3720865c Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Wed, 16 Oct 2024 20:35:01 +0530 Subject: [PATCH 081/299] [nrf fromtree] drivers: nrfwifi: Remove non-existing member Opriv was removed but the doxygen doc string was left. Signed-off-by: Chaitanya Tata (cherry picked from commit 9a9f8998f9fec877c3af58a8743c4dd12dd8bc59) --- drivers/wifi/nrfwifi/src/shim.h | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/wifi/nrfwifi/src/shim.h b/drivers/wifi/nrfwifi/src/shim.h index a4162bf8931..be26fd6355e 100644 --- a/drivers/wifi/nrfwifi/src/shim.h +++ b/drivers/wifi/nrfwifi/src/shim.h @@ -19,7 +19,6 @@ /** * struct zep_shim_bus_qspi_priv - Structure to hold context information for the Linux OS * shim. - * @opriv: Pointer to OSAL context. * @pcie_callbk_data: Callback data to be passed to the PCIe callback functions. * @pcie_prb_callbk: The callback function to be called when a PCIe device * has been probed. From cbcb2dba63e70283439f6cc86540f7e7450b73c1 Mon Sep 17 00:00:00 2001 From: Triveni Danda Date: Thu, 3 Oct 2024 10:40:46 +0530 Subject: [PATCH 082/299] [nrf fromlist] net: ip: Add a name to existing Kconfig choice Update kconfig choice name to enable overriding from other parts of the code. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/78852 Signed-off-by: Triveni Danda --- subsys/net/ip/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/net/ip/Kconfig b/subsys/net/ip/Kconfig index cb08b3846ca..f8c215b4fc3 100644 --- a/subsys/net/ip/Kconfig +++ b/subsys/net/ip/Kconfig @@ -663,7 +663,7 @@ config NET_BUF_TX_COUNT Each data buffer will occupy CONFIG_NET_BUF_DATA_SIZE + smallish header (sizeof(struct net_buf)) amount of data. -choice +choice NET_PKT_DATA_ALLOC_TYPE prompt "Network packet data allocator type" default NET_BUF_FIXED_DATA_SIZE help From b58ca22706146b743c73d329f2e263f365dc4015 Mon Sep 17 00:00:00 2001 From: Triveni Danda Date: Thu, 19 Sep 2024 13:10:39 +0530 Subject: [PATCH 083/299] [nrf fromlist] drivers: wifi: nrfwifi: Enable variable network configurations Add variable network configuration control into the driver to optimize RAM usage by default. The pool sizes are default, and tuning is left to the applications or samples. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/78852 Signed-off-by: Triveni Danda --- drivers/wifi/nrfwifi/Kconfig.nrfwifi | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/wifi/nrfwifi/Kconfig.nrfwifi b/drivers/wifi/nrfwifi/Kconfig.nrfwifi index b409261b614..a5a12a03e26 100644 --- a/drivers/wifi/nrfwifi/Kconfig.nrfwifi +++ b/drivers/wifi/nrfwifi/Kconfig.nrfwifi @@ -570,6 +570,12 @@ config NET_TC_TX_COUNT endif # NETWORKING +# nRF70 now uses variable buffers as default to optimize RAM usage. Default pool sizes are used, samples/apps can override +# for higher performance. +choice NET_PKT_DATA_ALLOC_TYPE + default NET_BUF_VARIABLE_DATA_SIZE +endchoice + config MAIN_STACK_SIZE default 4096 From ec256065bf919ca7f08cbb86ded8c8f81b2a699b Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Wed, 9 Oct 2024 12:18:59 +0200 Subject: [PATCH 084/299] [nrf fromlist] dts: bindings: wifi: split nrf700x coex and wifi models The nrf7000, nrf7001 and nrf7002 expose a coex hardware interface which is independent from the wifi/control interface (spi and control pins) These interfaces where previously combined into a single model. This is incompatible with the actual usage of the interfaces where one core may interact only with the coex interface, and another with the wifi/control interface. This commit moves the coex interface, commonly described in "nordic,nrf70-coex.yaml", out of the wifi/control models "nrf700-.yaml" to its own models "nrf700-coex.yaml" Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/79606 Signed-off-by: Bjarki Arge Andreasen --- dts/bindings/wifi/nordic,nrf70-coex.yaml | 6 ------ dts/bindings/wifi/nordic,nrf70.yaml | 9 ++++++--- dts/bindings/wifi/nordic,nrf7000-coex.yaml | 9 +++++++++ dts/bindings/wifi/nordic,nrf7001-coex.yaml | 9 +++++++++ dts/bindings/wifi/nordic,nrf7002-coex.yaml | 9 +++++++++ 5 files changed, 33 insertions(+), 9 deletions(-) create mode 100644 dts/bindings/wifi/nordic,nrf7000-coex.yaml create mode 100644 dts/bindings/wifi/nordic,nrf7001-coex.yaml create mode 100644 dts/bindings/wifi/nordic,nrf7002-coex.yaml diff --git a/dts/bindings/wifi/nordic,nrf70-coex.yaml b/dts/bindings/wifi/nordic,nrf70-coex.yaml index 208657f3fb5..0a9c12f587e 100644 --- a/dts/bindings/wifi/nordic,nrf70-coex.yaml +++ b/dts/bindings/wifi/nordic,nrf70-coex.yaml @@ -27,9 +27,3 @@ properties: description: | GPIO of the SOC controlling the Priority (STATUS1) pin (in 4-wire coex case) of the nRF7002 - - srrf-switch-gpios: - type: phandle-array - description: | - GPIO of the RF Switch to control SR RF output to either SR Antenna - or shared Antenna with Wi-Fi diff --git a/dts/bindings/wifi/nordic,nrf70.yaml b/dts/bindings/wifi/nordic,nrf70.yaml index ff9021739ac..abdc7ec2cb0 100644 --- a/dts/bindings/wifi/nordic,nrf70.yaml +++ b/dts/bindings/wifi/nordic,nrf70.yaml @@ -1,9 +1,6 @@ # Copyright (c) 2024 Nordic Semiconductor ASA # SPDX-License-Identifier: Apache-2.0 -# GPIO lines for controlling the nRF70 Series Wi-Fi chip. -include: nordic,nrf70-coex.yaml - properties: iovdd-ctrl-gpios: type: phandle-array @@ -19,3 +16,9 @@ properties: type: phandle-array required: true description: GPIO of the SoC controlling the HOST_IRQ pin of the nRF70 + + srrf-switch-gpios: + type: phandle-array + description: | + GPIO of the RF Switch to control SR RF output to either SR Antenna + or shared Antenna with Wi-Fi diff --git a/dts/bindings/wifi/nordic,nrf7000-coex.yaml b/dts/bindings/wifi/nordic,nrf7000-coex.yaml new file mode 100644 index 00000000000..94dcc2181d3 --- /dev/null +++ b/dts/bindings/wifi/nordic,nrf7000-coex.yaml @@ -0,0 +1,9 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +description: This is a representation of the nRF7000 Wi-Fi chip with COEX interface. + +compatible: nordic,nrf7000-coex + +include: + - "nordic,nrf70-coex.yaml" diff --git a/dts/bindings/wifi/nordic,nrf7001-coex.yaml b/dts/bindings/wifi/nordic,nrf7001-coex.yaml new file mode 100644 index 00000000000..d58afe7d44c --- /dev/null +++ b/dts/bindings/wifi/nordic,nrf7001-coex.yaml @@ -0,0 +1,9 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +description: This is a representation of the nRF7001 Wi-Fi chip with COEX interface. + +compatible: nordic,nrf7001-coex + +include: + - "nordic,nrf70-coex.yaml" diff --git a/dts/bindings/wifi/nordic,nrf7002-coex.yaml b/dts/bindings/wifi/nordic,nrf7002-coex.yaml new file mode 100644 index 00000000000..1df61d0bf98 --- /dev/null +++ b/dts/bindings/wifi/nordic,nrf7002-coex.yaml @@ -0,0 +1,9 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +description: This is a representation of the nRF7002 Wi-Fi chip with COEX interface. + +compatible: nordic,nrf7002-coex + +include: + - "nordic,nrf70-coex.yaml" From 1492f1d8c29a586a3dca4168cf98fe8601c0acd3 Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Wed, 9 Oct 2024 12:36:43 +0200 Subject: [PATCH 085/299] [nrf fromlist] boards: nordic: nrf7002dk: align with nrf700x split interface Remove the unused coex interface from the cpuapp of the nrf7002dk nrf5340 SoC. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/79606 Signed-off-by: Bjarki Arge Andreasen --- boards/nordic/nrf7002dk/nrf7002dk_nrf5340_cpuapp.dts | 1 - .../nrf7002dk/nrf7002dk_nrf5340_cpuapp_nrf7001.dts | 1 - boards/nordic/nrf7002dk/nrf7002dk_nrf5340_cpunet.dts | 7 +++++-- boards/nordic/nrf7002dk/nrf70_common.dtsi | 1 + boards/nordic/nrf7002dk/nrf70_common_coex.dtsi | 11 ----------- 5 files changed, 6 insertions(+), 15 deletions(-) delete mode 100644 boards/nordic/nrf7002dk/nrf70_common_coex.dtsi diff --git a/boards/nordic/nrf7002dk/nrf7002dk_nrf5340_cpuapp.dts b/boards/nordic/nrf7002dk/nrf7002dk_nrf5340_cpuapp.dts index fbe74a82224..9b62eafea17 100644 --- a/boards/nordic/nrf7002dk/nrf7002dk_nrf5340_cpuapp.dts +++ b/boards/nordic/nrf7002dk/nrf7002dk_nrf5340_cpuapp.dts @@ -32,7 +32,6 @@ qspi-quad-mode; #include "nrf70_common.dtsi" - #include "nrf70_common_coex.dtsi" #include "nrf70_common_5g.dtsi" }; }; diff --git a/boards/nordic/nrf7002dk/nrf7002dk_nrf5340_cpuapp_nrf7001.dts b/boards/nordic/nrf7002dk/nrf7002dk_nrf5340_cpuapp_nrf7001.dts index 1d78dddbe68..8d955c67fc7 100644 --- a/boards/nordic/nrf7002dk/nrf7002dk_nrf5340_cpuapp_nrf7001.dts +++ b/boards/nordic/nrf7002dk/nrf7002dk_nrf5340_cpuapp_nrf7001.dts @@ -32,6 +32,5 @@ qspi-quad-mode; #include "nrf70_common.dtsi" - #include "nrf70_common_coex.dtsi" }; }; diff --git a/boards/nordic/nrf7002dk/nrf7002dk_nrf5340_cpunet.dts b/boards/nordic/nrf7002dk/nrf7002dk_nrf5340_cpunet.dts index 823c9fafacb..8e36e678581 100644 --- a/boards/nordic/nrf7002dk/nrf7002dk_nrf5340_cpunet.dts +++ b/boards/nordic/nrf7002dk/nrf7002dk_nrf5340_cpunet.dts @@ -84,9 +84,12 @@ nrf70: coex { status = "okay"; - compatible = "nordic,nrf70-coex"; + compatible = "nordic,nrf7002-coex"; - #include "nrf70_common_coex.dtsi" + req-gpios = <&gpio0 28 GPIO_ACTIVE_HIGH>; + status0-gpios = <&gpio0 30 GPIO_ACTIVE_HIGH>; + grant-gpios = <&gpio0 24 (GPIO_PULL_DOWN | GPIO_ACTIVE_LOW)>; + swctrl1-gpios = <&gpio0 29 GPIO_ACTIVE_HIGH>; }; /* These aliases are provided for compatibility with samples */ diff --git a/boards/nordic/nrf7002dk/nrf70_common.dtsi b/boards/nordic/nrf7002dk/nrf70_common.dtsi index f40f8ad9bb7..cd9cd23bb89 100644 --- a/boards/nordic/nrf7002dk/nrf70_common.dtsi +++ b/boards/nordic/nrf7002dk/nrf70_common.dtsi @@ -7,6 +7,7 @@ iovdd-ctrl-gpios = <&gpio0 31 GPIO_ACTIVE_HIGH>; bucken-gpios = <&gpio0 12 GPIO_ACTIVE_HIGH>; host-irq-gpios = <&gpio0 23 GPIO_ACTIVE_HIGH>; +srrf-switch-gpios = <&gpio1 10 GPIO_ACTIVE_HIGH>; wifi-max-tx-pwr-2g-dsss = <21>; wifi-max-tx-pwr-2g-mcs0 = <16>; diff --git a/boards/nordic/nrf7002dk/nrf70_common_coex.dtsi b/boards/nordic/nrf7002dk/nrf70_common_coex.dtsi deleted file mode 100644 index 03f22c3edba..00000000000 --- a/boards/nordic/nrf7002dk/nrf70_common_coex.dtsi +++ /dev/null @@ -1,11 +0,0 @@ -/* - * Copyright (c) 2024 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -req-gpios = <&gpio0 28 GPIO_ACTIVE_HIGH>; -status0-gpios = <&gpio0 30 GPIO_ACTIVE_HIGH>; -grant-gpios = <&gpio0 24 (GPIO_PULL_DOWN | GPIO_ACTIVE_LOW)>; -swctrl1-gpios = <&gpio0 29 GPIO_ACTIVE_HIGH>; -srrf-switch-gpios = <&gpio1 10 GPIO_ACTIVE_HIGH>; From 32f30a89b8fa02a3b83aea24fd96cfc3b5b3afb8 Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Wed, 9 Oct 2024 12:49:38 +0200 Subject: [PATCH 086/299] [nrf fromlist] boards: shields: nrf7002eb: align with nrf700x split interface Exclude the coex interface if the coex variant of the nrf7002eb is selected instead of adding the interface alongside the wifi/control interface. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/79606 Signed-off-by: Bjarki Arge Andreasen --- boards/shields/nrf7002eb/nrf7002eb_coex.overlay | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/boards/shields/nrf7002eb/nrf7002eb_coex.overlay b/boards/shields/nrf7002eb/nrf7002eb_coex.overlay index a8925c25567..59007ebe58e 100644 --- a/boards/shields/nrf7002eb/nrf7002eb_coex.overlay +++ b/boards/shields/nrf7002eb/nrf7002eb_coex.overlay @@ -4,10 +4,13 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "nrf7002eb.overlay" +/ { + nrf70: coex { + compatible = "nordic,nrf7002-coex"; + status = "okay"; -&nrf70 { - status0-gpios = <&edge_connector 5 GPIO_ACTIVE_HIGH>; - req-gpios = <&edge_connector 6 GPIO_ACTIVE_HIGH>; - grant-gpios = <&edge_connector 15 (GPIO_PULL_DOWN | GPIO_ACTIVE_LOW)>; + status0-gpios = <&edge_connector 5 GPIO_ACTIVE_HIGH>; + req-gpios = <&edge_connector 6 GPIO_ACTIVE_HIGH>; + grant-gpios = <&edge_connector 15 (GPIO_PULL_DOWN | GPIO_ACTIVE_LOW)>; + }; }; From 6b38f1ad94c87cfc45930fe6e609e0b39fb9ece5 Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Wed, 9 Oct 2024 12:58:33 +0200 Subject: [PATCH 087/299] [nrf fromlist] boards: shields: nrf7002ek: align with nrf700x split interface Add variant for the coex interface and move the coex interface out if the wifi/control interface variants. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/79606 Signed-off-by: Bjarki Arge Andreasen --- boards/shields/nrf7002ek/Kconfig.shield | 3 +++ boards/shields/nrf7002ek/doc/index.rst | 13 ++++++------ .../shields/nrf7002ek/nrf7002ek_coex.overlay | 21 +++++++++++++++++++ .../shields/nrf7002ek/nrf7002ek_common.dtsi | 9 +------- 4 files changed, 32 insertions(+), 14 deletions(-) create mode 100644 boards/shields/nrf7002ek/nrf7002ek_coex.overlay diff --git a/boards/shields/nrf7002ek/Kconfig.shield b/boards/shields/nrf7002ek/Kconfig.shield index 7627ff96dbd..5b52d5710f2 100644 --- a/boards/shields/nrf7002ek/Kconfig.shield +++ b/boards/shields/nrf7002ek/Kconfig.shield @@ -9,3 +9,6 @@ config SHIELD_NRF7002EK_NRF7001 config SHIELD_NRF7002EK_NRF7000 def_bool $(shields_list_contains,nrf7002ek_nrf7000) + +config SHIELD_NRF7002EK_COEX + def_bool $(shields_list_contains,nrf7002ek_coex) diff --git a/boards/shields/nrf7002ek/doc/index.rst b/boards/shields/nrf7002ek/doc/index.rst index 9f247be3501..cfe08750f57 100644 --- a/boards/shields/nrf7002ek/doc/index.rst +++ b/boards/shields/nrf7002ek/doc/index.rst @@ -47,24 +47,25 @@ SR Co-existence ############### The nRF7002 EK supports SR co-existence provided the host board supports it. The SR co-existence -pins are connected to the host board's GPIO pins. +pins are connected to the host board's GPIO pins. The interface is selected by setting +``--shield nrf7002ek_coex`` when invoking ``west build``. Two Kconfig options are available to enable SR co-existence: -- :kconfig:option:`CONFIG_NRF70_SR_COEX`: Enables SR co-existence. +- :kconfig:option:`CONFIG_NRF70_SR_COEX`: Enables SR co-existence driver. - :kconfig:option:`CONFIG_NRF70_SR_COEX_RF_SWITCH`: Control SR side RF switch. Shield Variants ############### -The nRF7002 EK is available in three variants: +The nRF7002 EK is available in four variants: - ``nrf7002ek``: The default variant. - ``nrf7002ek_nrf7001``: Variant for the nRF7001 SoC or nRF7002 SoC emulating nRF7001 - that supports only 2.4GHz Wi-Fi. + that supports only 2.4GHz Wi-Fi. - ``nrf7002ek_nrf7000``: Variant for the nRF7000 SoC or nRF7002 SoC emulating nRF7000 - that supports only 2.4GHz Wi-Fi. - + that supports only 2.4GHz Wi-Fi. +- ``nrf7002ek_coex``: Variant for the SR co-existence interface References ********** diff --git a/boards/shields/nrf7002ek/nrf7002ek_coex.overlay b/boards/shields/nrf7002ek/nrf7002ek_coex.overlay new file mode 100644 index 00000000000..4b592acbfb2 --- /dev/null +++ b/boards/shields/nrf7002ek/nrf7002ek_coex.overlay @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + nrf70: coex { + compatible = "nordic,nrf7002-coex"; + status = "okay"; + + /* D2 */ + status0-gpios = <&arduino_header 8 GPIO_ACTIVE_HIGH>; + /* D3 */ + req-gpios = <&arduino_header 9 GPIO_ACTIVE_HIGH>; + /* D4 */ + grant-gpios = <&arduino_header 10 (GPIO_PULL_DOWN | GPIO_ACTIVE_LOW)>; + /* D6 */ + swctrl1-gpios = <&arduino_header 12 GPIO_ACTIVE_HIGH>; + }; +}; diff --git a/boards/shields/nrf7002ek/nrf7002ek_common.dtsi b/boards/shields/nrf7002ek/nrf7002ek_common.dtsi index 102e0078d5f..c9bbbde4b92 100644 --- a/boards/shields/nrf7002ek/nrf7002ek_common.dtsi +++ b/boards/shields/nrf7002ek/nrf7002ek_common.dtsi @@ -12,15 +12,8 @@ iovdd-ctrl-gpios = <&arduino_header 6 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>; bucken-gpios = <&arduino_header 7 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>; /* D7 */ host-irq-gpios = <&arduino_header 13 GPIO_ACTIVE_HIGH>; + /* Short-range (SR) co-existence */ -/* D2 */ -status0-gpios = <&arduino_header 8 GPIO_ACTIVE_HIGH>; -/* D3 */ -req-gpios = <&arduino_header 9 GPIO_ACTIVE_HIGH>; -/* D4 */ -grant-gpios = <&arduino_header 10 (GPIO_PULL_DOWN | GPIO_ACTIVE_LOW)>; -/* D6 */ -swctrl1-gpios = <&arduino_header 12 GPIO_ACTIVE_HIGH>; /* D8 */ srrf-switch-gpios = <&arduino_header 14 GPIO_ACTIVE_HIGH>; From 5f477d0fb50ac2879ac670cfbc14156f46550083 Mon Sep 17 00:00:00 2001 From: Kapil Bhatt Date: Thu, 17 Oct 2024 19:01:23 +0530 Subject: [PATCH 088/299] [nrf fromtree] drivers: wifi: Add Kconfig option for passive scan Add kconfig option for forced passive scan, It will use for only scan only mode. Signed-off-by: Kapil Bhatt (cherry picked from commit 0b11b39461958c25be6855e139124a8a4352e88a) --- drivers/wifi/nrfwifi/Kconfig.nrfwifi | 7 +++++++ drivers/wifi/nrfwifi/src/wifi_mgmt_scan.c | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/drivers/wifi/nrfwifi/Kconfig.nrfwifi b/drivers/wifi/nrfwifi/Kconfig.nrfwifi index a5a12a03e26..b0c5e6cb63e 100644 --- a/drivers/wifi/nrfwifi/Kconfig.nrfwifi +++ b/drivers/wifi/nrfwifi/Kconfig.nrfwifi @@ -821,4 +821,11 @@ config NRF_WIFI_PS_INT_PS whether to stay in PS (for lower amount of buffered data) or exit PS (for higher amount of buffered data). endchoice + +config NRF70_PASSIVE_SCAN_ONLY + bool "Forced Passive scan" + depends on NRF70_SCAN_ONLY + help + Enable this configuration to force passive scan on all channels. + This will override application specified scan type. endif # WIFI_NRF70 diff --git a/drivers/wifi/nrfwifi/src/wifi_mgmt_scan.c b/drivers/wifi/nrfwifi/src/wifi_mgmt_scan.c index c5c6f18804e..e30f572aeb3 100644 --- a/drivers/wifi/nrfwifi/src/wifi_mgmt_scan.c +++ b/drivers/wifi/nrfwifi/src/wifi_mgmt_scan.c @@ -206,6 +206,10 @@ int nrf_wifi_disp_scan_zep(const struct device *dev, struct wifi_scan_params *pa vif_ctx_zep->scan_res_cnt = 0; +#ifdef CONFIG_NRF70_PASSIVE_SCAN_ONLY + scan_info->scan_params.passive_scan = 1; +#endif /* CONFIG_NRF70_PASSIVE_SCAN_ONLY */ + status = nrf_wifi_fmac_scan(rpu_ctx_zep->rpu_ctx, vif_ctx_zep->vif_idx, scan_info); if (status != NRF_WIFI_STATUS_SUCCESS) { From 4b7b89df5d82f8aac9895a6312fbe0f903cbe9a8 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Fri, 18 Oct 2024 20:55:29 +0530 Subject: [PATCH 089/299] [nrf fromtree] drivers: nrfwifi: Allow scan-only for all platforms Though nRF7000 is a special Scan only chipset, scan only can work with any nRF70 platforms, no need for this enforcement and we can keep things flexible. Signed-off-by: Chaitanya Tata (cherry picked from commit f7ef64df28dc71e89eb0a80a5174c76bc8461330) --- drivers/wifi/nrfwifi/Kconfig.nrfwifi | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/wifi/nrfwifi/Kconfig.nrfwifi b/drivers/wifi/nrfwifi/Kconfig.nrfwifi index b0c5e6cb63e..36935ed8ba1 100644 --- a/drivers/wifi/nrfwifi/Kconfig.nrfwifi +++ b/drivers/wifi/nrfwifi/Kconfig.nrfwifi @@ -62,7 +62,6 @@ config NRF70_SYSTEM_MODE config NRF70_SCAN_ONLY bool "nRF70 scan only mode" - depends on WIFI_NRF7000 help Select this option to enable scan only mode of the nRF70 driver From da64b654f46220eace789332edb39fe0895ce0de Mon Sep 17 00:00:00 2001 From: Kapil Bhatt Date: Fri, 18 Oct 2024 16:56:41 +0530 Subject: [PATCH 090/299] [nrf fromtree] drivers: wifi: Add changes for regulatory domain Add changes for offloaded raw tx regulatory domain. Signed-off-by: Kapil Bhatt (cherry picked from commit 7161a7a06ab58ce2338c51974813e270dcd5b7d9) --- drivers/wifi/nrfwifi/off_raw_tx/src/off_raw_tx_api.c | 5 +++-- drivers/wifi/nrfwifi/src/fmac_main.c | 6 ++++-- .../zephyr/drivers/wifi/nrfwifi/off_raw_tx/off_raw_tx_api.h | 6 ++++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/drivers/wifi/nrfwifi/off_raw_tx/src/off_raw_tx_api.c b/drivers/wifi/nrfwifi/off_raw_tx/src/off_raw_tx_api.c index 3b1dd0bb093..520814865d6 100644 --- a/drivers/wifi/nrfwifi/off_raw_tx/src/off_raw_tx_api.c +++ b/drivers/wifi/nrfwifi/off_raw_tx/src/off_raw_tx_api.c @@ -128,7 +128,7 @@ static int bytes_from_str(uint8_t *buf, int buf_len, const char *src) } #endif /* CONFIG_WIFI_FIXED_MAC_ADDRESS_ENABLED */ -int nrf70_off_raw_tx_init(uint8_t *mac_addr) +int nrf70_off_raw_tx_init(uint8_t *mac_addr, unsigned char *country_code) { enum nrf_wifi_status status = NRF_WIFI_STATUS_FAIL; struct nrf_wifi_ctx_zep *rpu_ctx_zep = NULL; @@ -206,7 +206,8 @@ int nrf70_off_raw_tx_init(uint8_t *mac_addr) IS_ENABLED(CONFIG_NRF_WIFI_BEAMFORMING), &ctrl_params, &ceil_params, - &board_params); + &board_params, + country_code); if (status != NRF_WIFI_STATUS_SUCCESS) { LOG_ERR("%s: nRF70 firmware initialization failed", __func__); goto err; diff --git a/drivers/wifi/nrfwifi/src/fmac_main.c b/drivers/wifi/nrfwifi/src/fmac_main.c index 82ea0f99267..f2f7ba41340 100644 --- a/drivers/wifi/nrfwifi/src/fmac_main.c +++ b/drivers/wifi/nrfwifi/src/fmac_main.c @@ -644,7 +644,8 @@ enum nrf_wifi_status nrf_wifi_fmac_dev_add_zep(struct nrf_wifi_drv_priv_zep *drv IS_ENABLED(CONFIG_NRF_WIFI_BEAMFORMING), &tx_pwr_ctrl_params, &tx_pwr_ceil_params, - &board_params); + &board_params, + STRINGIFY(CONFIG_NRF70_REG_DOMAIN)); #else status = nrf_wifi_fmac_dev_init(rpu_ctx_zep->rpu_ctx, #ifdef CONFIG_NRF_WIFI_LOW_POWER @@ -655,7 +656,8 @@ enum nrf_wifi_status nrf_wifi_fmac_dev_add_zep(struct nrf_wifi_drv_priv_zep *drv IS_ENABLED(CONFIG_NRF_WIFI_BEAMFORMING), &tx_pwr_ctrl_params, &tx_pwr_ceil_params, - &board_params); + &board_params, + STRINGIFY(CONFIG_NRF70_REG_DOMAIN)); #endif /* CONFIG_NRF70_RADIO_TEST */ diff --git a/include/zephyr/drivers/wifi/nrfwifi/off_raw_tx/off_raw_tx_api.h b/include/zephyr/drivers/wifi/nrfwifi/off_raw_tx/off_raw_tx_api.h index b8ff50cd390..b14ae39488d 100644 --- a/include/zephyr/drivers/wifi/nrfwifi/off_raw_tx/off_raw_tx_api.h +++ b/include/zephyr/drivers/wifi/nrfwifi/off_raw_tx/off_raw_tx_api.h @@ -22,7 +22,8 @@ #define NRF_WIFI_OFF_RAW_TX_FRAME_SIZE_MIN 26 /* Maximum frame size for raw packet transmission */ #define NRF_WIFI_OFF_RAW_TX_FRAME_SIZE_MAX 600 - +/* Maximum length of country code*/ +#define NRF_WIFI_COUNTRY_CODE_LEN 2 /** * @brief- Transmission rates * Rate to be used for transmitting a packet. @@ -167,6 +168,7 @@ struct nrf_wifi_off_raw_tx_conf { /** * @brief Initialize the nRF70 for operating in the offloaded raw TX mode. * @param mac_addr MAC address to be used for the nRF70 device. + * @param country_code Country code to be set for regularity domain. * * This function is initializes the nRF70 device for offloaded raw TX mode by: * - Powering it up, @@ -184,7 +186,7 @@ struct nrf_wifi_off_raw_tx_conf { * @retval 0 If the operation was successful. * @retval -1 If the operation failed. */ -int nrf70_off_raw_tx_init(uint8_t *mac_addr); +int nrf70_off_raw_tx_init(uint8_t *mac_addr, unsigned char *country_code); /** * @brief Initialize the nRF70 for operating in the offloaded raw TX mode. From 553569ed2c14af883340aef57997db6c6f0a0267 Mon Sep 17 00:00:00 2001 From: Kapil Bhatt Date: Tue, 22 Oct 2024 13:00:50 +0530 Subject: [PATCH 091/299] [nrf fromtree] manifest: update hal_nordic revision for regularity domain Update update hal_nordic revision for regularity domain changes. Set regularity domain in umac command init. Signed-off-by: Kapil Bhatt (cherry picked from commit b8c18f55447e3781299242e3af83e949a0e67bc1) --- west.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/west.yml b/west.yml index 31647ae878c..31a525b6eaf 100644 --- a/west.yml +++ b/west.yml @@ -188,7 +188,7 @@ manifest: groups: - hal - name: hal_nordic - revision: 5f1210074cb8bb7ec66317af294596a97ac48815 + revision: 957d1a803d0663330e870af2985503ba0cdbb152 path: modules/hal/nordic groups: - hal From 893037de2ffedca18a33b8ef0ce9d1992b8dd3db Mon Sep 17 00:00:00 2001 From: Fengming Ye Date: Wed, 16 Oct 2024 17:27:14 +0900 Subject: [PATCH 092/299] [nrf fromtree] modules: hostap: fix DPP build error Fix DPP build error when HOSTAPD enabled and DPP disabled. Guard hapd_dpp_dispatch in both CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP and CONFIG_WIFI_NM_HOSTAPD_AP. Signed-off-by: Fengming Ye (cherry picked from commit 9e8b7bd3adac4b232d0ae05aa443f7fee06a8e6c) --- modules/hostap/src/supp_api.c | 1 - modules/hostap/src/supp_api.h | 1 - 2 files changed, 2 deletions(-) diff --git a/modules/hostap/src/supp_api.c b/modules/hostap/src/supp_api.c index ea4afcbcbf4..a29bc1c8296 100644 --- a/modules/hostap/src/supp_api.c +++ b/modules/hostap/src/supp_api.c @@ -2061,7 +2061,6 @@ int supplicant_dpp_dispatch(const struct device *dev, struct wifi_dpp_params *pa os_free(cmd); return 0; } -#endif /* CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP */ #ifdef CONFIG_WIFI_NM_HOSTAPD_AP int hapd_dpp_dispatch(const struct device *dev, struct wifi_dpp_params *params) diff --git a/modules/hostap/src/supp_api.h b/modules/hostap/src/supp_api.h index 1abcd2166c9..d5edce626de 100644 --- a/modules/hostap/src/supp_api.h +++ b/modules/hostap/src/supp_api.h @@ -278,7 +278,6 @@ int supplicant_ap_sta_disconnect(const struct device *dev, * @return 0 for OK; -1 for ERROR */ int supplicant_dpp_dispatch(const struct device *dev, struct wifi_dpp_params *params); -#endif /* CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP */ #ifdef CONFIG_WIFI_NM_HOSTAPD_AP /** From 9f1a2440d0be6907f23b85b101db29ea97ec3c1c Mon Sep 17 00:00:00 2001 From: Rex Chen Date: Mon, 19 Aug 2024 23:09:26 -0700 Subject: [PATCH 093/299] [nrf fromtree] net: wifi: shell: add wps support Add wps pin and wps pbc L2 layer cmd support. Signed-off-by: Rex Chen (cherry picked from commit 82ec1d7862102cfb72da60b1a7a215a7b70c2713) --- include/zephyr/net/wifi_mgmt.h | 36 ++++++++- modules/hostap/src/supp_api.c | 89 ++++++++++++++++++++++- modules/hostap/src/supp_api.h | 9 +++ modules/hostap/src/supp_main.c | 1 + samples/net/wifi/boards/rd_rw612_bga.conf | 1 + subsys/net/l2/wifi/wifi_mgmt.c | 15 ++++ subsys/net/l2/wifi/wifi_shell.c | 58 +++++++++++++++ 7 files changed, 207 insertions(+), 2 deletions(-) diff --git a/include/zephyr/net/wifi_mgmt.h b/include/zephyr/net/wifi_mgmt.h index 528e72dffe9..8e4b00b31a9 100644 --- a/include/zephyr/net/wifi_mgmt.h +++ b/include/zephyr/net/wifi_mgmt.h @@ -106,7 +106,9 @@ enum net_request_wifi_cmd { NET_REQUEST_WIFI_CMD_ENTERPRISE_CREDS, /** Get RTS threshold */ NET_REQUEST_WIFI_CMD_RTS_THRESHOLD_CONFIG, -/** @cond INTERNAL_HIDDEN */ + /** WPS config */ + NET_REQUEST_WIFI_CMD_WPS_CONFIG, + /** @cond INTERNAL_HIDDEN */ NET_REQUEST_WIFI_CMD_MAX /** @endcond */ }; @@ -252,6 +254,10 @@ NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_ENTERPRISE_CREDS); NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_RTS_THRESHOLD_CONFIG); +#define NET_REQUEST_WIFI_WPS_CONFIG (_NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_WPS_CONFIG) + +NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_WPS_CONFIG); + /** @brief Wi-Fi management events */ enum net_event_wifi_cmd { /** Scan results available */ @@ -1030,6 +1036,26 @@ struct wifi_dpp_params { }; #endif /* CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP */ +#define WIFI_WPS_PIN_MAX_LEN 8 + +/** Operation for WPS */ +enum wifi_wps_op { + /** WPS pbc */ + WIFI_WPS_PBC = 0, + /** Get WPS pin number */ + WIFI_WPS_PIN_GET = 1, + /** Set WPS pin number */ + WIFI_WPS_PIN_SET = 2, +}; + +/** Wi-Fi wps setup */ +struct wifi_wps_config_params { + /** wps operation */ + enum wifi_wps_op oper; + /** pin value*/ + char pin[WIFI_WPS_PIN_MAX_LEN + 1]; +}; + #include /** Scan result callback @@ -1273,6 +1299,14 @@ struct wifi_mgmt_ops { * @return 0 if ok, < 0 if error */ int (*get_rts_threshold)(const struct device *dev, unsigned int *rts_threshold); + /** Start a WPS PBC/PIN connection + * + * @param dev Pointer to the device structure for the driver instance + * @param params wps operarion parameters + * + * @return 0 if ok, < 0 if error + */ + int (*wps_config)(const struct device *dev, struct wifi_wps_config_params *params); }; /** Wi-Fi management offload API */ diff --git a/modules/hostap/src/supp_api.c b/modules/hostap/src/supp_api.c index a29bc1c8296..087b70644bd 100644 --- a/modules/hostap/src/supp_api.c +++ b/modules/hostap/src/supp_api.c @@ -35,7 +35,9 @@ static struct wifi_connect_req_params last_wifi_conn_params; enum requested_ops { CONNECT = 0, - DISCONNECT + DISCONNECT, + WPS_PBC, + WPS_PIN, }; enum status_thread_state { @@ -1320,6 +1322,91 @@ int supplicant_get_wifi_conn_params(const struct device *dev, return ret; } +static int supplicant_wps_pbc(const struct device *dev) +{ + struct wpa_supplicant *wpa_s; + int ret = -1; + + k_mutex_lock(&wpa_supplicant_mutex, K_FOREVER); + + wpa_s = get_wpa_s_handle(dev); + if (!wpa_s) { + ret = -1; + wpa_printf(MSG_ERROR, "Interface %s not found", dev->name); + goto out; + } + + if (!wpa_cli_cmd_v("wps_pbc")) { + goto out; + } + + wpas_api_ctrl.dev = dev; + wpas_api_ctrl.requested_op = WPS_PBC; + + ret = 0; + +out: + k_mutex_unlock(&wpa_supplicant_mutex); + + return ret; +} + +static int supplicant_wps_pin(const struct device *dev, struct wifi_wps_config_params *params) +{ + struct wpa_supplicant *wpa_s; + char *get_pin_cmd = "WPS_PIN get"; + int ret = -1; + + k_mutex_lock(&wpa_supplicant_mutex, K_FOREVER); + + wpa_s = get_wpa_s_handle(dev); + if (!wpa_s) { + ret = -1; + wpa_printf(MSG_ERROR, "Interface %s not found", dev->name); + goto out; + } + + if (params->oper == WIFI_WPS_PIN_GET) { + if (zephyr_wpa_cli_cmd_resp(get_pin_cmd, params->pin)) { + goto out; + } + } else if (params->oper == WIFI_WPS_PIN_SET) { + if (!wpa_cli_cmd_v("wps_check_pin %s", params->pin)) { + goto out; + } + + if (!wpa_cli_cmd_v("wps_pin any %s", params->pin)) { + goto out; + } + + wpas_api_ctrl.dev = dev; + wpas_api_ctrl.requested_op = WPS_PIN; + } else { + wpa_printf(MSG_ERROR, "Error wps pin operation : %d", params->oper); + goto out; + } + + ret = 0; + +out: + k_mutex_unlock(&wpa_supplicant_mutex); + + return ret; +} + +int supplicant_wps_config(const struct device *dev, struct wifi_wps_config_params *params) +{ + int ret = 0; + + if (params->oper == WIFI_WPS_PBC) { + ret = supplicant_wps_pbc(dev); + } else if (params->oper == WIFI_WPS_PIN_GET || params->oper == WIFI_WPS_PIN_SET) { + ret = supplicant_wps_pin(dev, params); + } + + return ret; +} + #ifdef CONFIG_AP #ifdef CONFIG_WIFI_NM_HOSTAPD_AP int hapd_state(const struct device *dev, int *state) diff --git a/modules/hostap/src/supp_api.h b/modules/hostap/src/supp_api.h index d5edce626de..3cd4ccac113 100644 --- a/modules/hostap/src/supp_api.h +++ b/modules/hostap/src/supp_api.h @@ -215,6 +215,15 @@ int supplicant_btm_query(const struct device *dev, uint8_t reason); int supplicant_get_wifi_conn_params(const struct device *dev, struct wifi_connect_req_params *params); +/** Start a WPS PBC/PIN connection + * + * @param dev Pointer to the device structure for the driver instance + * @param params wps operarion parameters + * + * @return 0 if ok, < 0 if error + */ +int supplicant_wps_config(const struct device *dev, struct wifi_wps_config_params *params); + #ifdef CONFIG_AP #ifdef CONFIG_WIFI_NM_HOSTAPD_AP /** diff --git a/modules/hostap/src/supp_main.c b/modules/hostap/src/supp_main.c index b111f43a4e8..380c32dfc16 100644 --- a/modules/hostap/src/supp_main.c +++ b/modules/hostap/src/supp_main.c @@ -75,6 +75,7 @@ static const struct wifi_mgmt_ops mgmt_ops = { .btm_query = supplicant_btm_query, #endif .get_conn_params = supplicant_get_wifi_conn_params, + .wps_config = supplicant_wps_config, #ifdef CONFIG_AP .ap_enable = supplicant_ap_enable, .ap_disable = supplicant_ap_disable, diff --git a/samples/net/wifi/boards/rd_rw612_bga.conf b/samples/net/wifi/boards/rd_rw612_bga.conf index d20b5af0b3e..a916ff131ad 100644 --- a/samples/net/wifi/boards/rd_rw612_bga.conf +++ b/samples/net/wifi/boards/rd_rw612_bga.conf @@ -85,6 +85,7 @@ 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 # Enable mbedtls CONFIG_MBEDTLS=y diff --git a/subsys/net/l2/wifi/wifi_mgmt.c b/subsys/net/l2/wifi/wifi_mgmt.c index 3cea624b6e3..f0d25d864d0 100644 --- a/subsys/net/l2/wifi/wifi_mgmt.c +++ b/subsys/net/l2/wifi/wifi_mgmt.c @@ -832,6 +832,21 @@ static int wifi_get_connection_params(uint32_t mgmt_request, struct net_if *ifac NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_CONN_PARAMS, wifi_get_connection_params); +static int wifi_wps_config(uint32_t mgmt_request, struct net_if *iface, void *data, size_t len) +{ + const struct device *dev = net_if_get_device(iface); + const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_api(iface); + struct wifi_wps_config_params *params = data; + + if (wifi_mgmt_api == NULL || wifi_mgmt_api->wps_config == NULL) { + return -ENOTSUP; + } + + return wifi_mgmt_api->wps_config(dev, params); +} + +NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_WPS_CONFIG, wifi_wps_config); + static int wifi_set_rts_threshold(uint32_t mgmt_request, struct net_if *iface, void *data, size_t len) { diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 22e3f0e83e7..a7085ee3760 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -1700,6 +1700,57 @@ static int cmd_wifi_btm_query(const struct shell *sh, size_t argc, char *argv[]) } #endif +static int cmd_wifi_wps_pbc(const struct shell *sh, size_t argc, char *argv[]) +{ + struct net_if *iface = net_if_get_first_wifi(); + struct wifi_wps_config_params params = {0}; + + context.sh = sh; + + if (argc == 1) { + params.oper = WIFI_WPS_PBC; + } else { + shell_help(sh); + return -ENOEXEC; + } + + if (net_mgmt(NET_REQUEST_WIFI_WPS_CONFIG, iface, ¶ms, sizeof(params))) { + PR_WARNING("Start wps pbc connection failed\n"); + return -ENOEXEC; + } + + return 0; +} + +static int cmd_wifi_wps_pin(const struct shell *sh, size_t argc, char *argv[]) +{ + struct net_if *iface = net_if_get_first_wifi(); + struct wifi_wps_config_params params = {0}; + + context.sh = sh; + + if (argc == 1) { + params.oper = WIFI_WPS_PIN_GET; + } else if (argc == 2) { + params.oper = WIFI_WPS_PIN_SET; + strncpy(params.pin, argv[1], WIFI_WPS_PIN_MAX_LEN); + } else { + shell_help(sh); + return -ENOEXEC; + } + + if (net_mgmt(NET_REQUEST_WIFI_WPS_CONFIG, iface, ¶ms, sizeof(params))) { + PR_WARNING("Start wps pin connection failed\n"); + return -ENOEXEC; + } + + if (params.oper == WIFI_WPS_PIN_GET) { + PR("WPS PIN is: %s\n", params.pin); + } + + return 0; +} + static int cmd_wifi_ps_wakeup_mode(const struct shell *sh, size_t argc, char *argv[]) { struct net_if *iface = net_if_get_first_wifi(); @@ -2960,6 +3011,13 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, cmd_wifi_btm_query, 2, 0), #endif + SHELL_CMD_ARG(wps_pbc, NULL, + "Start a WPS PBC connection.\n", + cmd_wifi_wps_pbc, 1, 0), + SHELL_CMD_ARG(wps_pin, NULL, + "Set and get WPS pin.\n" + "[pin] Only applicable for set.\n", + cmd_wifi_wps_pin, 1, 1), SHELL_CMD_ARG(ps_timeout, NULL, " - PS inactivity timer(in ms).\n", From fd127c93c583796ff4e012aeddb4dfd893d3179e Mon Sep 17 00:00:00 2001 From: Maochen Wang Date: Tue, 8 Oct 2024 17:16:01 +0800 Subject: [PATCH 094/299] [nrf fromtree] net: fix build error in DPP struct Fix build error in DPP struct when building Matter over Wi-Fi. The struct declaration must be done outside of the anonymous union. Only struct definition can be done inside the anonymous union. Signed-off-by: Maochen Wang (cherry picked from commit 9487952a4fd054ccb47a7b26fb071a744fc6c59d) --- include/zephyr/net/wifi_mgmt.h | 134 +++++++++++++++++++-------------- 1 file changed, 76 insertions(+), 58 deletions(-) diff --git a/include/zephyr/net/wifi_mgmt.h b/include/zephyr/net/wifi_mgmt.h index 8e4b00b31a9..4927bc1c9c5 100644 --- a/include/zephyr/net/wifi_mgmt.h +++ b/include/zephyr/net/wifi_mgmt.h @@ -949,6 +949,76 @@ enum wifi_dpp_bootstrap_type { WIFI_DPP_BOOTSTRAP_TYPE_NFC_URI }; +/** Params to add DPP configurator */ +struct wifi_dpp_configurator_add_params { + /** ECP curves for private key */ + int curve; + /** ECP curves for net access key */ + int net_access_key_curve; +}; + +/** Params to initiate a DPP auth procedure */ +struct wifi_dpp_auth_init_params { + /** Peer bootstrap id */ + int peer; + /** Configuration parameter id */ + int configurator; + /** Role configurator or enrollee */ + int role; + /** Security type */ + int conf; + /** SSID in string */ + char ssid[WIFI_SSID_MAX_LEN + 1]; +}; + +/** Params to do DPP chirp */ +struct wifi_dpp_chirp_params { + /** Own bootstrap id */ + int id; + /** Chirp on frequency */ + int freq; +}; + +/** Params to do DPP listen */ +struct wifi_dpp_listen_params { + /** Listen on frequency */ + int freq; + /** Role configurator or enrollee */ + int role; +}; + +/** Params to generate a DPP bootstrap */ +struct wifi_dpp_bootstrap_gen_params { + /** Bootstrap type */ + int type; + /** Own operating class */ + int op_class; + /** Own working channel */ + int chan; + /** ECP curves */ + int curve; + /** Own mac address */ + uint8_t mac[WIFI_MAC_ADDR_LEN]; +}; + +/** Params to set specific DPP configurator */ +struct wifi_dpp_configurator_set_params { + /** Peer bootstrap id */ + int peer; + /** Configuration parameter id */ + int configurator; + /** Role configurator or enrollee */ + int role; + /** Security type */ + int conf; + /** ECP curves for private key */ + int curve; + /** ECP curves for net access key */ + int net_access_key_curve; + /** Own mac address */ + char ssid[WIFI_SSID_MAX_LEN + 1]; +}; + /** Wi-Fi DPP params for various operations */ struct wifi_dpp_params { @@ -956,69 +1026,17 @@ struct wifi_dpp_params { int action; union { /** Params to add DPP configurator */ - struct wifi_dpp_configurator_add_params { - /** ECP curves for private key */ - int curve; - /** ECP curves for net access key */ - int net_access_key_curve; - } configurator_add; + struct wifi_dpp_configurator_add_params configurator_add; /** Params to initiate a DPP auth procedure */ - struct wifi_dpp_auth_init_params { - /** Peer bootstrap id */ - int peer; - /** Configuration parameter id */ - int configurator; - /** Role configurator or enrollee */ - int role; - /** Security type */ - int conf; - /** SSID in string */ - char ssid[WIFI_SSID_MAX_LEN + 1]; - } auth_init; + struct wifi_dpp_auth_init_params auth_init; /** Params to do DPP chirp */ - struct wifi_dpp_chirp_params { - /** Own bootstrap id */ - int id; - /** Chirp on frequency */ - int freq; - } chirp; + struct wifi_dpp_chirp_params chirp; /** Params to do DPP listen */ - struct wifi_dpp_listen_params { - /** Listen on frequency */ - int freq; - /** Role configurator or enrollee */ - int role; - } listen; + struct wifi_dpp_listen_params listen; /** Params to generate a DPP bootstrap */ - struct wifi_dpp_bootstrap_gen_params { - /** Bootstrap type */ - int type; - /** Own operating class */ - int op_class; - /** Own working channel */ - int chan; - /** ECP curves */ - int curve; - /** Own mac address */ - uint8_t mac[WIFI_MAC_ADDR_LEN]; - } bootstrap_gen; + struct wifi_dpp_bootstrap_gen_params bootstrap_gen; /** Params to set specific DPP configurator */ - struct wifi_dpp_configurator_set_params { - /** Peer bootstrap id */ - int peer; - /** Configuration parameter id */ - int configurator; - /** Role configurator or enrollee */ - int role; - /** Security type */ - int conf; - /** ECP curves for private key */ - int curve; - /** ECP curves for net access key */ - int net_access_key_curve; - /** Own mac address */ - char ssid[WIFI_SSID_MAX_LEN + 1]; - } configurator_set; + struct wifi_dpp_configurator_set_params configurator_set; /** Bootstrap get uri id */ int id; /** Timeout for DPP frame response rx */ From 1ad08d46bbf2133a99ca242f0e2ad329885b9218 Mon Sep 17 00:00:00 2001 From: Gaofeng Zhang Date: Sun, 29 Sep 2024 14:24:22 +0800 Subject: [PATCH 095/299] [nrf fromtree] hostapd: add ap status in l2 wifi add ap status in l2 wifi Signed-off-by: Gaofeng Zhang (cherry picked from commit 0c54a3f8c7b4770820d3c2cfc02add29cc42f525) --- include/zephyr/net/wifi_mgmt.h | 12 ++++ modules/hostap/src/supp_api.c | 80 ++++++++++++++++++++- modules/hostap/src/supp_api.h | 9 +++ modules/hostap/src/supp_main.c | 1 + subsys/net/l2/wifi/wifi_mgmt.c | 2 + subsys/net/l2/wifi/wifi_shell.c | 120 +++++++++++++++++++++++--------- 6 files changed, 188 insertions(+), 36 deletions(-) diff --git a/include/zephyr/net/wifi_mgmt.h b/include/zephyr/net/wifi_mgmt.h index 4927bc1c9c5..c0c9643602a 100644 --- a/include/zephyr/net/wifi_mgmt.h +++ b/include/zephyr/net/wifi_mgmt.h @@ -1074,6 +1074,18 @@ struct wifi_wps_config_params { char pin[WIFI_WPS_PIN_MAX_LEN + 1]; }; +/** Wi-Fi AP status + */ +enum wifi_hostapd_iface_state { + WIFI_HAPD_IFACE_UNINITIALIZED, + WIFI_HAPD_IFACE_DISABLED, + WIFI_HAPD_IFACE_COUNTRY_UPDATE, + WIFI_HAPD_IFACE_ACS, + WIFI_HAPD_IFACE_HT_SCAN, + WIFI_HAPD_IFACE_DFS, + WIFI_HAPD_IFACE_ENABLED +}; + #include /** Scan result callback diff --git a/modules/hostap/src/supp_api.c b/modules/hostap/src/supp_api.c index 087b70644bd..e62fbfca0be 100644 --- a/modules/hostap/src/supp_api.c +++ b/modules/hostap/src/supp_api.c @@ -378,6 +378,8 @@ static inline enum wifi_security_type wpas_key_mgmt_to_zephyr(int key_mgmt, int return WIFI_SECURITY_TYPE_PSK_SHA256; case WPA_KEY_MGMT_SAE: return WIFI_SECURITY_TYPE_SAE; + case WPA_KEY_MGMT_SAE | WPA_KEY_MGMT_PSK: + return WIFI_SECURITY_TYPE_WPA_AUTO_PERSONAL; default: return WIFI_SECURITY_TYPE_UNKNOWN; } @@ -1574,7 +1576,7 @@ int hapd_config_network(struct hostapd_iface *iface, if (!hostapd_cli_cmd_v("set wpa 0")) { goto out; } - iface->bss[0]->conf->wpa_key_mgmt = 0; + iface->bss[0]->conf->wpa_key_mgmt = WPA_KEY_MGMT_NONE; } if (!hostapd_cli_cmd_v("set ieee80211w %d", params->mfp)) { @@ -1636,6 +1638,80 @@ int supplicant_ap_config_params(const struct device *dev, struct wifi_ap_config_ } #endif +int supplicant_ap_status(const struct device *dev, struct wifi_iface_status *status) +{ + int ret = 0; + struct hostapd_iface *iface; + struct hostapd_config *conf; + struct hostapd_data *hapd; + struct hostapd_bss_config *bss; + struct hostapd_ssid *ssid; + struct hostapd_hw_modes *hw_mode; + int proto; /* Wi-Fi secure protocol */ + int key_mgmt; /* Wi-Fi key management */ + + k_mutex_lock(&wpa_supplicant_mutex, K_FOREVER); + + iface = get_hostapd_handle(dev); + if (!iface) { + ret = -1; + wpa_printf(MSG_ERROR, "Interface %s not found", dev->name); + goto out; + } + + conf = iface->conf; + if (!conf) { + ret = -1; + wpa_printf(MSG_ERROR, "Conf %s not found", dev->name); + goto out; + } + + bss = conf->bss[0]; + if (!bss) { + ret = -1; + wpa_printf(MSG_ERROR, "Bss_conf %s not found", dev->name); + goto out; + } + + hapd = iface->bss[0]; + if (!hapd) { + ret = -1; + wpa_printf(MSG_ERROR, "Bss %s not found", dev->name); + goto out; + } + + status->state = iface->state; + ssid = &bss->ssid; + + os_memcpy(status->bssid, hapd->own_addr, WIFI_MAC_ADDR_LEN); + status->iface_mode = WPAS_MODE_AP; + status->band = wpas_band_to_zephyr(wpas_freq_to_band(iface->freq)); + key_mgmt = bss->wpa_key_mgmt; + proto = bss->wpa; + status->security = wpas_key_mgmt_to_zephyr(key_mgmt, proto); + status->mfp = bss->ieee80211w; + status->channel = conf->channel; + os_memcpy(status->ssid, ssid->ssid, ssid->ssid_len); + + status->dtim_period = bss->dtim_period; + status->beacon_interval = conf->beacon_int; + + hw_mode = iface->current_mode; + + status->link_mode = conf->ieee80211ax ? WIFI_6 + : conf->ieee80211ac ? WIFI_5 + : conf->ieee80211n ? WIFI_4 + : hw_mode->mode == HOSTAPD_MODE_IEEE80211G ? WIFI_3 + : hw_mode->mode == HOSTAPD_MODE_IEEE80211A ? WIFI_2 + : hw_mode->mode == HOSTAPD_MODE_IEEE80211B ? WIFI_1 + : WIFI_0; + status->twt_capable = (hw_mode->he_capab[IEEE80211_MODE_AP].mac_cap[0] & 0x04); + +out: + k_mutex_unlock(&wpa_supplicant_mutex); + return ret; +} + int supplicant_ap_enable(const struct device *dev, struct wifi_connect_req_params *params) { @@ -1717,7 +1793,7 @@ int supplicant_ap_enable(const struct device *dev, goto out; } - /* No need to check for existing network to join for SoftAP*/ + /* No need to check for existing network to join for SoftAP */ wpa_s->conf->ap_scan = 2; /* Set BSS parameter max_num_sta to default configured value */ wpa_s->conf->max_num_sta = CONFIG_WIFI_MGMT_AP_MAX_NUM_STA; diff --git a/modules/hostap/src/supp_api.h b/modules/hostap/src/supp_api.h index 3cd4ccac113..f6584d86126 100644 --- a/modules/hostap/src/supp_api.h +++ b/modules/hostap/src/supp_api.h @@ -250,6 +250,15 @@ static inline int hapd_state(const struct device *dev, int *state) } #endif +/** + * @brief Get Wi-Fi SAP status + * + * @param dev Wi-Fi device + * @param status SAP status + * @return 0 for OK; -1 for ERROR + */ +int supplicant_ap_status(const struct device *dev, struct wifi_iface_status *status); + /** * @brief Set Wi-Fi AP configuration * diff --git a/modules/hostap/src/supp_main.c b/modules/hostap/src/supp_main.c index 380c32dfc16..b47b322e2aa 100644 --- a/modules/hostap/src/supp_main.c +++ b/modules/hostap/src/supp_main.c @@ -99,6 +99,7 @@ static const struct wifi_mgmt_ops mgmt_ap_ops = { .ap_disable = supplicant_ap_disable, .ap_sta_disconnect = supplicant_ap_sta_disconnect, .ap_bandwidth = supplicant_ap_bandwidth, + .iface_status = supplicant_ap_status, #ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP .dpp_dispatch = hapd_dpp_dispatch, #endif /* CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP */ diff --git a/subsys/net/l2/wifi/wifi_mgmt.c b/subsys/net/l2/wifi/wifi_mgmt.c index f0d25d864d0..5974cde6a1a 100644 --- a/subsys/net/l2/wifi/wifi_mgmt.c +++ b/subsys/net/l2/wifi/wifi_mgmt.c @@ -41,6 +41,8 @@ const char *wifi_security_txt(enum wifi_security_type security) return "WAPI"; case WIFI_SECURITY_TYPE_EAP_TLS: return "EAP"; + case WIFI_SECURITY_TYPE_WPA_AUTO_PERSONAL: + return "WPA/WPA2/WPA3 PSK"; case WIFI_SECURITY_TYPE_UNKNOWN: default: return "UNKNOWN"; diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index a7085ee3760..93005936f09 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -954,6 +954,65 @@ static int cmd_wifi_status(const struct shell *sh, size_t argc, char *argv[]) return 0; } +static int cmd_wifi_ap_status(const struct shell *sh, size_t argc, char *argv[]) +{ + struct net_if *iface = net_if_get_wifi_sap(); + struct wifi_iface_status status = {0}; + uint8_t mac_string_buf[sizeof("xx:xx:xx:xx:xx:xx")]; + + context.sh = sh; + + if (net_mgmt(NET_REQUEST_WIFI_IFACE_STATUS, iface, &status, + sizeof(struct wifi_iface_status))) { + PR_WARNING("Status request failed\n"); + + return -ENOEXEC; + } + + switch (status.state) { + case WIFI_HAPD_IFACE_UNINITIALIZED: + PR("State: %s\n", "HAPD_IFACE_UNINITIALIZED"); + return 0; + case WIFI_HAPD_IFACE_DISABLED: + PR("State: %s\n", "HAPD_IFACE_DISABLED"); + return 0; + case WIFI_HAPD_IFACE_COUNTRY_UPDATE: + PR("State: %s\n", "HAPD_IFACE_DISABLED"); + return 0; + case WIFI_HAPD_IFACE_ACS: + PR("State: %s\n", "HAPD_IFACE_DISABLED"); + return 0; + case WIFI_HAPD_IFACE_HT_SCAN: + PR("State: %s\n", "HAPD_IFACE_DISABLED"); + return 0; + case WIFI_HAPD_IFACE_DFS: + PR("State: %s\n", "HAPD_IFACE_DISABLED"); + break; + case WIFI_HAPD_IFACE_ENABLED: + break; + default: + return 0; + } + + PR("Interface Mode: %s\n", wifi_mode_txt(status.iface_mode)); + PR("Link Mode: %s\n", wifi_link_mode_txt(status.link_mode)); + PR("SSID: %.32s\n", status.ssid); + PR("BSSID: %s\n", net_sprint_ll_addr_buf(status.bssid, WIFI_MAC_ADDR_LEN, mac_string_buf, + sizeof(mac_string_buf))); + PR("Band: %s\n", wifi_band_txt(status.band)); + PR("Channel: %d\n", status.channel); + PR("Security: %s\n", wifi_security_txt(status.security)); + PR("MFP: %s\n", wifi_mfp_txt(status.mfp)); + if (status.iface_mode == WIFI_MODE_INFRA) { + PR("RSSI: %d\n", status.rssi); + } + PR("Beacon Interval: %d\n", status.beacon_interval); + PR("DTIM: %d\n", status.dtim_period); + PR("TWT: %s\n", status.twt_capable ? "Supported" : "Not supported"); + + return 0; +} + #if defined(CONFIG_NET_STATISTICS_WIFI) && \ defined(CONFIG_NET_STATISTICS_USER_API) static void print_wifi_stats(struct net_if *iface, struct net_stats_wifi *data, @@ -2754,43 +2813,36 @@ static int cmd_wifi_pmksa_flush(const struct shell *sh, size_t argc, char *argv[ return 0; } -SHELL_STATIC_SUBCMD_SET_CREATE(wifi_cmd_ap, - SHELL_CMD_ARG(disable, NULL, - "Disable Access Point mode.\n", - cmd_wifi_ap_disable, - 1, 0), +SHELL_STATIC_SUBCMD_SET_CREATE( + wifi_cmd_ap, + SHELL_CMD_ARG(disable, NULL, "Disable Access Point mode.\n", cmd_wifi_ap_disable, 1, 0), SHELL_CMD_ARG(enable, NULL, - "-s --ssid=\n" - "-c --channel=\n" - "-p --passphrase= (valid only for secure SSIDs)\n" - "-k --key-mgmt= (valid only for secure SSIDs)\n" - "0:None, 1:WPA2-PSK, 2:WPA2-PSK-256, 3:SAE, 4:WAPI, 5:EAP-TLS, 6:WEP\n" - "7: WPA-PSK, 11: DPP\n" - "-w --ieee-80211w= (optional: needs security type to be specified)\n" - "0:Disable, 1:Optional, 2:Required\n" - "-b --band= (2 -2.6GHz, 5 - 5Ghz, 6 - 6GHz)\n" - "-m --bssid=\n" - "-h --help (prints help)", - cmd_wifi_ap_enable, - 2, 13), - SHELL_CMD_ARG(stations, NULL, - "List stations connected to the AP", - cmd_wifi_ap_stations, - 1, 0), + "-s --ssid=\n" + "-c --channel=\n" + "-p --passphrase= (valid only for secure SSIDs)\n" + "-k --key-mgmt= (valid only for secure SSIDs)\n" + "0:None, 1:WPA2-PSK, 2:WPA2-PSK-256, 3:SAE, 4:WAPI, 5:EAP-TLS, 6:WEP\n" + "7: WPA-PSK, 11: DPP\n" + "-w --ieee-80211w= (optional: needs security type to be specified)\n" + "0:Disable, 1:Optional, 2:Required\n" + "-b --band= (2 -2.6GHz, 5 - 5Ghz, 6 - 6GHz)\n" + "-m --bssid=\n" + "-h --help (prints help)", + cmd_wifi_ap_enable, 2, 13), + SHELL_CMD_ARG(stations, NULL, "List stations connected to the AP", cmd_wifi_ap_stations, 1, + 0), SHELL_CMD_ARG(disconnect, NULL, - "Disconnect a station from the AP\n" - "\n", - cmd_wifi_ap_sta_disconnect, - 2, 0), + "Disconnect a station from the AP\n" + "\n", + cmd_wifi_ap_sta_disconnect, 2, 0), SHELL_CMD_ARG(config, NULL, - "Configure AP parameters.\n" - "-i --max_inactivity=