diff --git a/drivers/wifi/nrf_wifi/inc/fmac_main.h b/drivers/wifi/nrf_wifi/inc/fmac_main.h index be8c9d763679..857205eeebbc 100644 --- a/drivers/wifi/nrf_wifi/inc/fmac_main.h +++ b/drivers/wifi/nrf_wifi/inc/fmac_main.h @@ -75,6 +75,9 @@ struct nrf_wifi_vif_ctx_zep { #endif /* CONFIG_NET_STATISTICS_ETHERNET_VENDOR */ struct net_stats_eth eth_stats; #endif /* CONFIG_NET_STATISTICS_ETHERNET */ +#if defined(CONFIG_NRF70_STA_MODE) || defined(CONFIG_NRF70_RAW_DATA_TX) + bool authorized; +#endif #ifdef CONFIG_NRF70_STA_MODE unsigned int assoc_freq; enum nrf_wifi_fmac_if_carr_state if_carr_state; @@ -151,6 +154,8 @@ void configure_tx_pwr_settings(struct nrf_wifi_tx_pwr_ctrl_params *tx_pwr_ctrl_p void configure_board_dep_params(struct nrf_wifi_board_params *board_params); void set_tx_pwr_ceil_default(struct nrf_wifi_tx_pwr_ceil_params *pwr_ceil_params); const char *nrf_wifi_get_drv_version(void); +char *nrf_wifi_sprint_ll_addr_buf(const uint8_t *ll, uint8_t ll_len, + char *buf, int buflen); 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); struct nrf_wifi_vif_ctx_zep *nrf_wifi_get_vif_ctx(struct net_if *iface); diff --git a/drivers/wifi/nrf_wifi/src/fmac_main.c b/drivers/wifi/nrf_wifi/src/fmac_main.c index 9e8ae2aafb93..ed6e425e98fe 100644 --- a/drivers/wifi/nrf_wifi/src/fmac_main.c +++ b/drivers/wifi/nrf_wifi/src/fmac_main.c @@ -114,6 +114,61 @@ static const unsigned int rx3_buf_sz = 1000; struct nrf_wifi_drv_priv_zep rpu_drv_priv_zep; static K_MUTEX_DEFINE(reg_lock); +/** + * @brief Format a link layer address to a string buffer. + * + * @param ll Pointer to the link layer address bytes. + * @param ll_len Length of the link layer address (typically 6 for MAC). + * @param buf Buffer to store the formatted string. + * @param buflen Size of the buffer. + * + * @return Pointer to the buffer on success, NULL on failure. + */ +char *nrf_wifi_sprint_ll_addr_buf(const uint8_t *ll, uint8_t ll_len, + char *buf, int buflen) +{ + uint8_t i, len, blen; + char *ptr = buf; + + if (ll == NULL) { + return ""; + } + + switch (ll_len) { + case 8: + len = 8U; + break; + case 6: + len = 6U; + break; + case 2: + len = 2U; + break; + default: + len = 6U; + break; + } + + for (i = 0U, blen = buflen; i < len && blen > 0; i++) { + uint8_t high = (ll[i] >> 4) & 0x0f; + uint8_t low = ll[i] & 0x0f; + + *ptr++ = (high < 10) ? (char)(high + '0') : + (char)(high - 10 + 'A'); + *ptr++ = (low < 10) ? (char)(low + '0') : + (char)(low - 10 + 'A'); + *ptr++ = ':'; + blen -= 3U; + } + + if (!(ptr - buf)) { + return NULL; + } + + *(ptr - 1) = '\0'; + return buf; +} + const char *nrf_wifi_get_drv_version(void) { return NRF70_DRIVER_VERSION; diff --git a/drivers/wifi/nrf_wifi/src/net_if.c b/drivers/wifi/nrf_wifi/src/net_if.c index 1e85c2e77626..d4ce230ceeeb 100644 --- a/drivers/wifi/nrf_wifi/src/net_if.c +++ b/drivers/wifi/nrf_wifi/src/net_if.c @@ -31,9 +31,6 @@ LOG_MODULE_DECLARE(wifi_nrf, CONFIG_WIFI_NRF70_LOG_LEVEL); #include "wpa_supp_if.h" #include "net_if.h" -extern char *net_sprint_ll_addr_buf(const uint8_t *ll, uint8_t ll_len, - char *buf, int buflen); - #ifdef CONFIG_NRF70_STA_MODE static struct net_if_mcast_monitor mcast_monitor; #endif /* CONFIG_NRF70_STA_MODE */ @@ -391,6 +388,7 @@ int nrf_wifi_if_send(const struct device *dev, bool locked = false; unsigned char *ra = NULL; int peer_id = -1; + bool authorized; if (!dev || !pkt) { LOG_ERR("%s: vif_ctx_zep is NULL", __func__); @@ -443,13 +441,23 @@ int nrf_wifi_if_send(const struct device *dev, ra = nrf_wifi_util_get_ra(sys_dev_ctx->vif_ctx[vif_ctx_zep->vif_idx], nbuf); peer_id = nrf_wifi_fmac_peer_get_id(rpu_ctx_zep->rpu_ctx, ra); if (peer_id == -1) { - nrf_wifi_osal_log_dbg("%s: Invalid peer", - __func__); - goto out; + char ra_buf[18] = {0}; + + LOG_ERR("%s: Got packet for unknown PEER: %s", __func__, + nrf_wifi_sprint_ll_addr_buf(ra, 6, ra_buf, + sizeof(ra_buf))); + goto drop; + } + + /* VIF or per-peer depending on RA */ + if (peer_id == MAX_PEERS) { + authorized = vif_ctx_zep->authorized; + } else { + authorized = sys_dev_ctx->tx_config.peers[peer_id].authorized; } if ((vif_ctx_zep->if_carr_state != NRF_WIFI_FMAC_IF_CARR_STATE_ON) || - (!sys_dev_ctx->tx_config.peers[peer_id].authorized && !is_eapol(pkt))) { + (!authorized && !is_eapol(pkt))) { ret = -EPERM; goto drop; } @@ -495,7 +503,6 @@ static void ip_maddr_event_handler(struct net_if *iface, struct net_eth_addr mac_addr; struct nrf_wifi_umac_mcast_cfg *mcast_info = NULL; enum nrf_wifi_status status; - uint8_t mac_string_buf[sizeof("xx:xx:xx:xx:xx:xx")]; struct nrf_wifi_ctx_zep *rpu_ctx_zep = NULL; int ret; @@ -551,12 +558,15 @@ static void ip_maddr_event_handler(struct net_if *iface, vif_ctx_zep->vif_idx, mcast_info); if (status == NRF_WIFI_STATUS_FAIL) { + char mac_string_buf[sizeof("xx:xx:xx:xx:xx:xx")]; + LOG_ERR("%s: nrf_wifi_fmac_set_multicast failed for" " mac addr=%s", __func__, - net_sprint_ll_addr_buf(mac_addr.addr, - WIFI_MAC_ADDR_LEN, mac_string_buf, - sizeof(mac_string_buf))); + nrf_wifi_sprint_ll_addr_buf(mac_addr.addr, + WIFI_MAC_ADDR_LEN, + mac_string_buf, + sizeof(mac_string_buf))); } unlock: nrf_wifi_osal_mem_free(mcast_info); diff --git a/drivers/wifi/nrf_wifi/src/wifi_mgmt.c b/drivers/wifi/nrf_wifi/src/wifi_mgmt.c index 4c98ef0d8aa0..1fae3d2cf2a4 100644 --- a/drivers/wifi/nrf_wifi/src/wifi_mgmt.c +++ b/drivers/wifi/nrf_wifi/src/wifi_mgmt.c @@ -875,18 +875,6 @@ int nrf_wifi_channel(const struct device *dev, return ret; } - for (i = 0; i < MAX_PEERS; i++) { - peer = &sys_dev_ctx->tx_config.peers[i]; - if (peer->peer_id == -1) { - continue; - } - if (peer->authorized) { - LOG_ERR("%s: Cannot change channel when in station connected mode", - __func__); - return ret; - } - } - rpu_ctx_zep = vif_ctx_zep->rpu_ctx_zep; if (!rpu_ctx_zep) { LOG_ERR("%s: rpu_ctx_zep is NULL", __func__); @@ -902,6 +890,18 @@ int nrf_wifi_channel(const struct device *dev, fmac_dev_ctx = rpu_ctx_zep->rpu_ctx; sys_dev_ctx = wifi_dev_priv(fmac_dev_ctx); + for (i = 0; i < MAX_PEERS; i++) { + peer = &sys_dev_ctx->tx_config.peers[i]; + if (peer->peer_id == -1) { + continue; + } + if (peer->authorized) { + LOG_ERR("%s: Cannot change channel when in station connected mode", + __func__); + return ret; + } + } + if (channel->oper == WIFI_MGMT_SET) { /** * Send the driver vif_idx instead of upper layer sent if_index. diff --git a/drivers/wifi/nrf_wifi/src/wpa_supp_if.c b/drivers/wifi/nrf_wifi/src/wpa_supp_if.c index 26893f2214e2..5a69676e47a1 100644 --- a/drivers/wifi/nrf_wifi/src/wpa_supp_if.c +++ b/drivers/wifi/nrf_wifi/src/wpa_supp_if.c @@ -1108,9 +1108,8 @@ int nrf_wifi_wpa_set_supp_port(void *if_priv, int authorized, char *bssid) struct nrf_wifi_vif_ctx_zep *vif_ctx_zep = NULL; struct nrf_wifi_umac_chg_sta_info chg_sta_info; struct nrf_wifi_ctx_zep *rpu_ctx_zep = NULL; - struct nrf_wifi_sys_fmac_dev_ctx *sys_dev_ctx = NULL; + struct nrf_wifi_sys_fmac_dev_ctx *sys_dev_ctx; enum nrf_wifi_status status = NRF_WIFI_STATUS_FAIL; - int peer_id = -1; int ret = -1; if (!if_priv || !bssid) { @@ -1131,6 +1130,12 @@ int nrf_wifi_wpa_set_supp_port(void *if_priv, int authorized, char *bssid) goto out; } + sys_dev_ctx = wifi_dev_priv(rpu_ctx_zep->rpu_ctx); + if (!sys_dev_ctx) { + LOG_ERR("%s: sys_dev_ctx is NULL", __func__); + goto out; + } + if (vif_ctx_zep->if_op_state != NRF_WIFI_FMAC_IF_OP_STATE_UP) { LOG_DBG("%s: Interface not UP, ignoring", __func__); ret = 0; @@ -1141,6 +1146,7 @@ int nrf_wifi_wpa_set_supp_port(void *if_priv, int authorized, char *bssid) memcpy(chg_sta_info.mac_addr, bssid, ETH_ALEN); + vif_ctx_zep->authorized = authorized; if (authorized) { /* BIT(NL80211_STA_FLAG_AUTHORIZED) */ chg_sta_info.sta_flags2.nrf_wifi_mask = 1 << 1; @@ -1158,17 +1164,8 @@ int nrf_wifi_wpa_set_supp_port(void *if_priv, int authorized, char *bssid) goto out; } - sys_dev_ctx = wifi_dev_priv(rpu_ctx_zep->rpu_ctx); - - peer_id = nrf_wifi_fmac_peer_get_id(rpu_ctx_zep->rpu_ctx, chg_sta_info.mac_addr); - if (peer_id == -1) { - nrf_wifi_osal_log_err("%s: Invalid peer", - __func__); - goto out; - } - - if (chg_sta_info.sta_flags2.nrf_wifi_set & NRF_WIFI_STA_FLAG_AUTHORIZED) { - sys_dev_ctx->tx_config.peers[peer_id].authorized = true; + if (vif_ctx_zep->if_type == NRF_WIFI_IFTYPE_STATION) { + sys_dev_ctx->tx_config.peers[0].authorized = authorized; } ret = 0; @@ -3007,6 +3004,7 @@ int nrf_wifi_wpa_supp_sta_set_flags(void *if_priv, const u8 *addr, enum nrf_wifi_status status = NRF_WIFI_STATUS_FAIL; int peer_id = -1; int ret = -1; + char buf[18] = {0}; if (!if_priv || !addr) { LOG_ERR("%s: Invalid params", __func__); @@ -3028,13 +3026,36 @@ int nrf_wifi_wpa_supp_sta_set_flags(void *if_priv, const u8 *addr, memcpy(chg_sta.mac_addr, addr, sizeof(chg_sta.mac_addr)); + if (!net_eth_is_addr_valid((struct net_eth_addr *)&chg_sta.mac_addr)) { + LOG_ERR("%s: Invalid peer MAC address: %s", __func__, + nrf_wifi_sprint_ll_addr_buf(chg_sta.mac_addr, 6, buf, + sizeof(buf))); + goto out; + } + + peer_id = nrf_wifi_fmac_peer_get_id(rpu_ctx_zep->rpu_ctx, chg_sta.mac_addr); + if (peer_id == -1) { + LOG_ERR("%s: Unknown PEER: %s", __func__, + nrf_wifi_sprint_ll_addr_buf(chg_sta.mac_addr, 6, buf, + sizeof(buf))); + goto out; + } + + if (peer_id == MAX_PEERS) { + LOG_ERR("%s: Invalid PEER (group): %s", __func__, + nrf_wifi_sprint_ll_addr_buf(chg_sta.mac_addr, 6, buf, + sizeof(buf))); + goto out; + } + chg_sta.sta_flags2.nrf_wifi_mask = nrf_wifi_sta_flags_to_nrf(flags_or | ~flags_and); chg_sta.sta_flags2.nrf_wifi_set = nrf_wifi_sta_flags_to_nrf(flags_or); LOG_DBG("%s %x, %x", __func__, chg_sta.sta_flags2.nrf_wifi_set, chg_sta.sta_flags2.nrf_wifi_mask); - status = nrf_wifi_sys_fmac_chg_sta(rpu_ctx_zep->rpu_ctx, vif_ctx_zep->vif_idx, &chg_sta); + status = nrf_wifi_sys_fmac_chg_sta(rpu_ctx_zep->rpu_ctx, + vif_ctx_zep->vif_idx, &chg_sta); if (status != NRF_WIFI_STATUS_SUCCESS) { LOG_ERR("%s: nrf_wifi_sys_fmac_chg_sta failed", __func__); goto out; @@ -3042,16 +3063,8 @@ int nrf_wifi_wpa_supp_sta_set_flags(void *if_priv, const u8 *addr, sys_dev_ctx = wifi_dev_priv(rpu_ctx_zep->rpu_ctx); - peer_id = nrf_wifi_fmac_peer_get_id(rpu_ctx_zep->rpu_ctx, chg_sta.mac_addr); - if (peer_id == -1) { - nrf_wifi_osal_log_err("%s: Invalid peer", - __func__); - goto out; - } - - if (chg_sta.sta_flags2.nrf_wifi_set & NRF_WIFI_STA_FLAG_AUTHORIZED) { - sys_dev_ctx->tx_config.peers[peer_id].authorized = true; - } + sys_dev_ctx->tx_config.peers[peer_id].authorized = + !!(chg_sta.sta_flags2.nrf_wifi_set & NRF_WIFI_STA_FLAG_AUTHORIZED); ret = 0; diff --git a/modules/hostap/Kconfig b/modules/hostap/Kconfig index ec8263d85a6b..ff8327609d0b 100644 --- a/modules/hostap/Kconfig +++ b/modules/hostap/Kconfig @@ -60,7 +60,7 @@ config WIFI_NM_WPA_SUPPLICANT_THREAD_STACK_SIZE # overflow issues. Need to identify the cause for higher stack usage. default 8192 if WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE # This is needed to handle stack overflow issues on nRF Wi-Fi drivers. - default 5900 if WIFI_NM_WPA_SUPPLICANT_AP + default 6144 if WIFI_NM_WPA_SUPPLICANT_AP default 5800 config WIFI_NM_WPA_SUPPLICANT_WQ_STACK_SIZE diff --git a/west.yml b/west.yml index 154371f993dc..8cdefc0716a1 100644 --- a/west.yml +++ b/west.yml @@ -337,7 +337,7 @@ manifest: revision: 5eec7aca321735f5fc8e3e7c79e162f0e9810b16 path: modules/bsim_hw_models/nrf_hw_models - name: nrf_wifi - revision: f0b6706cac522371e651f589d53d3026cc6f97dd + revision: pull/91/head path: modules/lib/nrf_wifi - name: open-amp revision: c30a6d8b92fcebdb797fc1a7698e8729e250f637