Skip to content

Commit e17587a

Browse files
rado17krish2718
authored andcommitted
[nrf fromlist] drivers: wifi: nrf_wifi: Add per-peer authorized flag
Add per-peer authorized parameter. Port authorization command from supplicant will set this flag and will be used by driver to allow or nor allow data traffic. Upstream PR #: 97183 Signed-off-by: Ravi Dondaputi <[email protected]> (cherry picked from commit 82fdbd1)
1 parent 627afb3 commit e17587a

File tree

5 files changed

+157
-19
lines changed

5 files changed

+157
-19
lines changed

drivers/wifi/nrf_wifi/inc/fmac_main.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ struct nrf_wifi_vif_ctx_zep {
7575
#endif /* CONFIG_NET_STATISTICS_ETHERNET_VENDOR */
7676
struct net_stats_eth eth_stats;
7777
#endif /* CONFIG_NET_STATISTICS_ETHERNET */
78-
#if defined(CONFIG_NRF70_STA_MODE) || defined(CONFIG_NRF70_RAW_DATA_RX)
78+
#if defined(CONFIG_NRF70_STA_MODE) || defined(CONFIG_NRF70_RAW_DATA_TX)
7979
bool authorized;
8080
#endif
8181
#ifdef CONFIG_NRF70_STA_MODE
@@ -154,6 +154,8 @@ void configure_tx_pwr_settings(struct nrf_wifi_tx_pwr_ctrl_params *tx_pwr_ctrl_p
154154
void configure_board_dep_params(struct nrf_wifi_board_params *board_params);
155155
void set_tx_pwr_ceil_default(struct nrf_wifi_tx_pwr_ceil_params *pwr_ceil_params);
156156
const char *nrf_wifi_get_drv_version(void);
157+
char *nrf_wifi_sprint_ll_addr_buf(const uint8_t *ll, uint8_t ll_len,
158+
char *buf, int buflen);
157159
enum nrf_wifi_status nrf_wifi_fmac_dev_add_zep(struct nrf_wifi_drv_priv_zep *drv_priv_zep);
158160
enum nrf_wifi_status nrf_wifi_fmac_dev_rem_zep(struct nrf_wifi_drv_priv_zep *drv_priv_zep);
159161
struct nrf_wifi_vif_ctx_zep *nrf_wifi_get_vif_ctx(struct net_if *iface);

drivers/wifi/nrf_wifi/src/fmac_main.c

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,61 @@ static const unsigned int rx3_buf_sz = 1000;
114114
struct nrf_wifi_drv_priv_zep rpu_drv_priv_zep;
115115
static K_MUTEX_DEFINE(reg_lock);
116116

117+
/**
118+
* @brief Format a link layer address to a string buffer.
119+
*
120+
* @param ll Pointer to the link layer address bytes.
121+
* @param ll_len Length of the link layer address (typically 6 for MAC).
122+
* @param buf Buffer to store the formatted string.
123+
* @param buflen Size of the buffer.
124+
*
125+
* @return Pointer to the buffer on success, NULL on failure.
126+
*/
127+
char *nrf_wifi_sprint_ll_addr_buf(const uint8_t *ll, uint8_t ll_len,
128+
char *buf, int buflen)
129+
{
130+
uint8_t i, len, blen;
131+
char *ptr = buf;
132+
133+
if (ll == NULL) {
134+
return "<unknown>";
135+
}
136+
137+
switch (ll_len) {
138+
case 8:
139+
len = 8U;
140+
break;
141+
case 6:
142+
len = 6U;
143+
break;
144+
case 2:
145+
len = 2U;
146+
break;
147+
default:
148+
len = 6U;
149+
break;
150+
}
151+
152+
for (i = 0U, blen = buflen; i < len && blen > 0; i++) {
153+
uint8_t high = (ll[i] >> 4) & 0x0f;
154+
uint8_t low = ll[i] & 0x0f;
155+
156+
*ptr++ = (high < 10) ? (char)(high + '0') :
157+
(char)(high - 10 + 'A');
158+
*ptr++ = (low < 10) ? (char)(low + '0') :
159+
(char)(low - 10 + 'A');
160+
*ptr++ = ':';
161+
blen -= 3U;
162+
}
163+
164+
if (!(ptr - buf)) {
165+
return NULL;
166+
}
167+
168+
*(ptr - 1) = '\0';
169+
return buf;
170+
}
171+
117172
const char *nrf_wifi_get_drv_version(void)
118173
{
119174
return NRF70_DRIVER_VERSION;

drivers/wifi/nrf_wifi/src/net_if.c

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,12 @@ LOG_MODULE_DECLARE(wifi_nrf, CONFIG_WIFI_NRF70_LOG_LEVEL);
2525

2626
#include "util.h"
2727
#include "common/fmac_util.h"
28+
#include "system/fmac_peer.h"
2829
#include "shim.h"
2930
#include "fmac_main.h"
3031
#include "wpa_supp_if.h"
3132
#include "net_if.h"
3233

33-
extern char *net_sprint_ll_addr_buf(const uint8_t *ll, uint8_t ll_len,
34-
char *buf, int buflen);
35-
3634
#ifdef CONFIG_NRF70_STA_MODE
3735
static struct net_if_mcast_monitor mcast_monitor;
3836
#endif /* CONFIG_NRF70_STA_MODE */
@@ -388,6 +386,9 @@ int nrf_wifi_if_send(const struct device *dev,
388386
struct rpu_host_stats *host_stats = NULL;
389387
void *nbuf = NULL;
390388
bool locked = false;
389+
unsigned char *ra = NULL;
390+
int peer_id = -1;
391+
bool authorized;
391392

392393
if (!dev || !pkt) {
393394
LOG_ERR("%s: vif_ctx_zep is NULL", __func__);
@@ -436,12 +437,30 @@ int nrf_wifi_if_send(const struct device *dev,
436437
nbuf);
437438
} else {
438439
#endif /* CONFIG_NRF70_RAW_DATA_TX */
440+
441+
ra = nrf_wifi_util_get_ra(sys_dev_ctx->vif_ctx[vif_ctx_zep->vif_idx], nbuf);
442+
peer_id = nrf_wifi_fmac_peer_get_id(rpu_ctx_zep->rpu_ctx, ra);
443+
if (peer_id == -1) {
444+
char ra_buf[18] = {0};
445+
446+
LOG_ERR("%s: Got packet for unknown PEER: %s", __func__,
447+
nrf_wifi_sprint_ll_addr_buf(ra, 6, ra_buf,
448+
sizeof(ra_buf)));
449+
goto drop;
450+
}
451+
452+
/* VIF or per-peer depending on RA */
453+
if (peer_id == MAX_PEERS) {
454+
authorized = vif_ctx_zep->authorized;
455+
} else {
456+
authorized = sys_dev_ctx->tx_config.peers[peer_id].authorized;
457+
}
458+
439459
if ((vif_ctx_zep->if_carr_state != NRF_WIFI_FMAC_IF_CARR_STATE_ON) ||
440-
(!vif_ctx_zep->authorized && !is_eapol(pkt))) {
460+
(!authorized && !is_eapol(pkt))) {
441461
ret = -EPERM;
442462
goto drop;
443463
}
444-
445464
ret = nrf_wifi_fmac_start_xmit(rpu_ctx_zep->rpu_ctx,
446465
vif_ctx_zep->vif_idx,
447466
nbuf);
@@ -484,7 +503,6 @@ static void ip_maddr_event_handler(struct net_if *iface,
484503
struct net_eth_addr mac_addr;
485504
struct nrf_wifi_umac_mcast_cfg *mcast_info = NULL;
486505
enum nrf_wifi_status status;
487-
uint8_t mac_string_buf[sizeof("xx:xx:xx:xx:xx:xx")];
488506
struct nrf_wifi_ctx_zep *rpu_ctx_zep = NULL;
489507
int ret;
490508

@@ -540,12 +558,15 @@ static void ip_maddr_event_handler(struct net_if *iface,
540558
vif_ctx_zep->vif_idx,
541559
mcast_info);
542560
if (status == NRF_WIFI_STATUS_FAIL) {
561+
char mac_string_buf[sizeof("xx:xx:xx:xx:xx:xx")];
562+
543563
LOG_ERR("%s: nrf_wifi_fmac_set_multicast failed for"
544564
" mac addr=%s",
545565
__func__,
546-
net_sprint_ll_addr_buf(mac_addr.addr,
547-
WIFI_MAC_ADDR_LEN, mac_string_buf,
548-
sizeof(mac_string_buf)));
566+
nrf_wifi_sprint_ll_addr_buf(mac_addr.addr,
567+
WIFI_MAC_ADDR_LEN,
568+
mac_string_buf,
569+
sizeof(mac_string_buf)));
549570
}
550571
unlock:
551572
nrf_wifi_osal_mem_free(mcast_info);

drivers/wifi/nrf_wifi/src/wifi_mgmt.c

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "system/fmac_api.h"
1919
#include "system/fmac_tx.h"
2020
#include "common/fmac_util.h"
21+
#include "common/fmac_structs_common.h"
2122
#include "fmac_main.h"
2223
#include "wifi_mgmt.h"
2324

@@ -757,6 +758,8 @@ int nrf_wifi_mode(const struct device *dev,
757758
struct nrf_wifi_vif_ctx_zep *vif_ctx_zep = NULL;
758759
struct nrf_wifi_fmac_dev_ctx *fmac_dev_ctx = NULL;
759760
struct nrf_wifi_sys_fmac_dev_ctx *sys_dev_ctx = NULL;
761+
struct peers_info *peer = NULL;
762+
int i = 0;
760763
int ret = -1;
761764

762765
if (!dev || !mode) {
@@ -798,10 +801,16 @@ int nrf_wifi_mode(const struct device *dev,
798801
goto out;
799802
}
800803

801-
if (vif_ctx_zep->authorized && (mode->mode == NRF_WIFI_MONITOR_MODE)) {
802-
LOG_ERR("%s: Cannot set monitor mode when station is connected",
803-
__func__);
804-
goto out;
804+
for (i = 0; i < MAX_PEERS; i++) {
805+
peer = &sys_dev_ctx->tx_config.peers[i];
806+
if (peer->peer_id == -1) {
807+
continue;
808+
}
809+
if (peer->authorized && (mode->mode == NRF_WIFI_MONITOR_MODE)) {
810+
LOG_ERR("%s: Cannot set monitor mode when station is connected",
811+
__func__);
812+
goto out;
813+
}
805814
}
806815

807816
/**
@@ -851,6 +860,8 @@ int nrf_wifi_channel(const struct device *dev,
851860
struct nrf_wifi_vif_ctx_zep *vif_ctx_zep = NULL;
852861
struct nrf_wifi_sys_fmac_dev_ctx *sys_dev_ctx = NULL;
853862
struct nrf_wifi_fmac_dev_ctx *fmac_dev_ctx = NULL;
863+
struct peers_info *peer = NULL;
864+
int i = 0;
854865
int ret = -1;
855866

856867
if (!dev || !channel) {
@@ -864,9 +875,16 @@ int nrf_wifi_channel(const struct device *dev,
864875
return ret;
865876
}
866877

867-
if (vif_ctx_zep->authorized) {
868-
LOG_ERR("%s: Cannot change channel when in station connected mode", __func__);
869-
return ret;
878+
for (i = 0; i < MAX_PEERS; i++) {
879+
peer = &sys_dev_ctx->tx_config.peers[i];
880+
if (peer->peer_id == -1) {
881+
continue;
882+
}
883+
if (peer->authorized) {
884+
LOG_ERR("%s: Cannot change channel when in station connected mode",
885+
__func__);
886+
return ret;
887+
}
870888
}
871889

872890
rpu_ctx_zep = vif_ctx_zep->rpu_ctx_zep;

drivers/wifi/nrf_wifi/src/wpa_supp_if.c

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "common/fmac_util.h"
1818
#include "wifi_mgmt.h"
1919
#include "wpa_supp_if.h"
20+
#include <system/fmac_peer.h>
2021

2122
LOG_MODULE_DECLARE(wifi_nrf, CONFIG_WIFI_NRF70_LOG_LEVEL);
2223

@@ -1107,6 +1108,7 @@ int nrf_wifi_wpa_set_supp_port(void *if_priv, int authorized, char *bssid)
11071108
struct nrf_wifi_vif_ctx_zep *vif_ctx_zep = NULL;
11081109
struct nrf_wifi_umac_chg_sta_info chg_sta_info;
11091110
struct nrf_wifi_ctx_zep *rpu_ctx_zep = NULL;
1111+
struct nrf_wifi_sys_fmac_dev_ctx *sys_dev_ctx;
11101112
enum nrf_wifi_status status = NRF_WIFI_STATUS_FAIL;
11111113
int ret = -1;
11121114

@@ -1128,6 +1130,12 @@ int nrf_wifi_wpa_set_supp_port(void *if_priv, int authorized, char *bssid)
11281130
goto out;
11291131
}
11301132

1133+
sys_dev_ctx = wifi_dev_priv(rpu_ctx_zep->rpu_ctx);
1134+
if (!sys_dev_ctx) {
1135+
LOG_ERR("%s: sys_dev_ctx is NULL", __func__);
1136+
goto out;
1137+
}
1138+
11311139
if (vif_ctx_zep->if_op_state != NRF_WIFI_FMAC_IF_OP_STATE_UP) {
11321140
LOG_DBG("%s: Interface not UP, ignoring", __func__);
11331141
ret = 0;
@@ -1139,7 +1147,6 @@ int nrf_wifi_wpa_set_supp_port(void *if_priv, int authorized, char *bssid)
11391147
memcpy(chg_sta_info.mac_addr, bssid, ETH_ALEN);
11401148

11411149
vif_ctx_zep->authorized = authorized;
1142-
11431150
if (authorized) {
11441151
/* BIT(NL80211_STA_FLAG_AUTHORIZED) */
11451152
chg_sta_info.sta_flags2.nrf_wifi_mask = 1 << 1;
@@ -1157,6 +1164,10 @@ int nrf_wifi_wpa_set_supp_port(void *if_priv, int authorized, char *bssid)
11571164
goto out;
11581165
}
11591166

1167+
if (vif_ctx_zep->if_type == NRF_WIFI_IFTYPE_STATION) {
1168+
sys_dev_ctx->tx_config.peers[0].authorized = authorized;
1169+
}
1170+
11601171
ret = 0;
11611172
out:
11621173
k_mutex_unlock(&vif_ctx_zep->vif_lock);
@@ -2989,8 +3000,11 @@ int nrf_wifi_wpa_supp_sta_set_flags(void *if_priv, const u8 *addr,
29893000
struct nrf_wifi_vif_ctx_zep *vif_ctx_zep = NULL;
29903001
struct nrf_wifi_umac_chg_sta_info chg_sta = {0};
29913002
struct nrf_wifi_ctx_zep *rpu_ctx_zep = NULL;
3003+
struct nrf_wifi_sys_fmac_dev_ctx *sys_dev_ctx = NULL;
29923004
enum nrf_wifi_status status = NRF_WIFI_STATUS_FAIL;
3005+
int peer_id = -1;
29933006
int ret = -1;
3007+
char buf[18] = {0};
29943008

29953009
if (!if_priv || !addr) {
29963010
LOG_ERR("%s: Invalid params", __func__);
@@ -3012,18 +3026,46 @@ int nrf_wifi_wpa_supp_sta_set_flags(void *if_priv, const u8 *addr,
30123026

30133027
memcpy(chg_sta.mac_addr, addr, sizeof(chg_sta.mac_addr));
30143028

3029+
if (!net_eth_is_addr_valid((struct net_eth_addr *)&chg_sta.mac_addr)) {
3030+
LOG_ERR("%s: Invalid peer MAC address: %s", __func__,
3031+
nrf_wifi_sprint_ll_addr_buf(chg_sta.mac_addr, 6, buf,
3032+
sizeof(buf)));
3033+
goto out;
3034+
}
3035+
3036+
peer_id = nrf_wifi_fmac_peer_get_id(rpu_ctx_zep->rpu_ctx, chg_sta.mac_addr);
3037+
if (peer_id == -1) {
3038+
LOG_ERR("%s: Unknown PEER: %s", __func__,
3039+
nrf_wifi_sprint_ll_addr_buf(chg_sta.mac_addr, 6, buf,
3040+
sizeof(buf)));
3041+
goto out;
3042+
}
3043+
3044+
if (peer_id == MAX_PEERS) {
3045+
LOG_ERR("%s: Invalid PEER (group): %s", __func__,
3046+
nrf_wifi_sprint_ll_addr_buf(chg_sta.mac_addr, 6, buf,
3047+
sizeof(buf)));
3048+
goto out;
3049+
}
3050+
30153051
chg_sta.sta_flags2.nrf_wifi_mask = nrf_wifi_sta_flags_to_nrf(flags_or | ~flags_and);
30163052
chg_sta.sta_flags2.nrf_wifi_set = nrf_wifi_sta_flags_to_nrf(flags_or);
30173053

30183054
LOG_DBG("%s %x, %x", __func__,
30193055
chg_sta.sta_flags2.nrf_wifi_set, chg_sta.sta_flags2.nrf_wifi_mask);
30203056

3021-
status = nrf_wifi_sys_fmac_chg_sta(rpu_ctx_zep->rpu_ctx, vif_ctx_zep->vif_idx, &chg_sta);
3057+
status = nrf_wifi_sys_fmac_chg_sta(rpu_ctx_zep->rpu_ctx,
3058+
vif_ctx_zep->vif_idx, &chg_sta);
30223059
if (status != NRF_WIFI_STATUS_SUCCESS) {
30233060
LOG_ERR("%s: nrf_wifi_sys_fmac_chg_sta failed", __func__);
30243061
goto out;
30253062
}
30263063

3064+
sys_dev_ctx = wifi_dev_priv(rpu_ctx_zep->rpu_ctx);
3065+
3066+
sys_dev_ctx->tx_config.peers[peer_id].authorized =
3067+
!!(chg_sta.sta_flags2.nrf_wifi_set & NRF_WIFI_STA_FLAG_AUTHORIZED);
3068+
30273069
ret = 0;
30283070

30293071
out:

0 commit comments

Comments
 (0)