Skip to content

Commit b5a81a9

Browse files
committed
nrf_wifi: Fix filter setting for promiscuous mode
The filter setting for promiscuous mode needs to be handled in the driver. If the packet filtering is handled in the lower layers, it might affect station connectivity. This commit introduces code to add minimal filtering mechanism in driver Addresses [SHEL-2852] Signed-off-by: Vivekananda Uppunda <vivekananda.uppunda@nordicsemi.no>
1 parent 37e2ac2 commit b5a81a9

File tree

4 files changed

+112
-12
lines changed

4 files changed

+112
-12
lines changed

nrf_wifi/fw_if/umac_if/inc/default/fmac_structs.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,10 @@ struct nrf_wifi_fmac_callbk_fns {
270270
signed short signal);
271271
#endif /* CONFIG_NRF700X_STA_MODE */
272272
#if defined(CONFIG_NRF700X_RAW_DATA_RX) || defined(CONFIG_NRF700X_PROMISC_DATA_RX)
273-
void (*rx_sniffer_frm_callbk_fn)(void *os_vif_ctx,
274-
void *frm,
275-
struct raw_rx_pkt_header *,
276-
bool pkt_free);
273+
void (*sniffer_callbk_fn)(void *os_vif_ctx,
274+
void *frm,
275+
struct raw_rx_pkt_header *,
276+
bool pkt_free);
277277
#endif /* CONFIG_NRF700X_RAW_DATA_RX || CONFIG_NRF700X_PROMISC_DATA_RX */
278278
void (*reg_change_callbk_fn)(void *os_vif_ctx,
279279
struct nrf_wifi_event_regulatory_change *reg_change,

nrf_wifi/fw_if/umac_if/inc/fmac_util.h

+26
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,27 @@
6666
#define NRF_WIFI_FMAC_IPV6_TOS_SHIFT 0x04 /* 4bit */
6767
#define NRF_WIFI_FMAC_ETH_TYPE_MASK 0xFFFF
6868

69+
#if defined(CONFIG_NRF700X_PROMISC_DATA_RX)
70+
#define NRF_WIFI_MGMT_PKT_TYPE 0x00
71+
#define NRF_WIFI_DATA_PKT_TYPE 0x10
72+
#define NRF_WIFI_CTRL_PKT_TYPE 0x01
73+
74+
/* Frame Control structure */
75+
struct nrf_wifi_fmac_frame_ctrl{
76+
unsigned short protocolVersion : 2;
77+
unsigned short type : 2;
78+
unsigned short subtype : 4;
79+
unsigned short toDS : 1;
80+
unsigned short fromDS : 1;
81+
unsigned short moreFragments : 1;
82+
unsigned short retry : 1;
83+
unsigned short powerManagement : 1;
84+
unsigned short moreData : 1;
85+
unsigned short protectedFrame : 1;
86+
unsigned short order : 1;
87+
} __NRF_WIFI_PKD;
88+
#endif
89+
6990
struct nrf_wifi_fmac_ieee80211_hdr {
7091
unsigned short fc;
7192
unsigned short dur_id;
@@ -131,6 +152,11 @@ void nrf_wifi_util_rx_convert_amsdu_to_eth(struct nrf_wifi_fmac_dev_ctx *fmac_de
131152
bool nrf_wifi_util_is_arr_zero(unsigned char *arr,
132153
unsigned int arr_sz);
133154

155+
#if defined(CONFIG_NRF700X_PROMISC_DATA_RX)
156+
bool nrf_wifi_util_check_filt_setting(struct nrf_wifi_fmac_vif_ctx *vif,
157+
unsigned short *frame_control);
158+
#endif
159+
134160
#endif /* !CONFIG_NRF700X_RADIO_TEST */
135161

136162
void *wifi_fmac_priv(struct nrf_wifi_fmac_priv *def);

nrf_wifi/fw_if/umac_if/src/fmac_util.c

+63
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "fmac_api_common.h"
1414
#include "fmac_util.h"
1515
#include "host_rpu_umac_if.h"
16+
#include "host_rpu_sys_if.h"
1617

1718
bool nrf_wifi_util_is_multicast_addr(const unsigned char *addr)
1819
{
@@ -366,6 +367,68 @@ enum nrf_wifi_status nrf_wifi_check_mode_validity(unsigned char mode)
366367
return NRF_WIFI_STATUS_FAIL;
367368
}
368369

370+
#if defined(CONFIG_NRF700X_PROMISC_DATA_RX)
371+
bool nrf_wifi_util_check_filt_setting(struct nrf_wifi_fmac_vif_ctx *vif,
372+
unsigned short *frame_control)
373+
{
374+
bool filter_check = false;
375+
struct nrf_wifi_fmac_frame_ctrl *frm_ctrl =
376+
(struct nrf_wifi_fmac_frame_ctrl *)frame_control;
377+
/**
378+
* The different filter settings for 802.11 packets are a bit map
379+
* and the description of the different valid values for the case
380+
* statements are as follows:
381+
* 0x2 - Enable management packets only
382+
* 0x4 - Enable data packets only
383+
* 0x8 - Enable control packets only
384+
* 0x6 - Enable data and management packets
385+
* 0xa - Enable control and management packets
386+
* 0xb - Enable data and control packets
387+
* if bit 0 is set, all packet types are allowed to be sent upstack
388+
**/
389+
switch (vif->packet_filter) {
390+
case 0x2:
391+
if (frm_ctrl->type == NRF_WIFI_MGMT_PKT_TYPE) {
392+
filter_check = true;
393+
}
394+
break;
395+
case 0x4:
396+
if (frm_ctrl->type == NRF_WIFI_DATA_PKT_TYPE) {
397+
filter_check = true;
398+
}
399+
break;
400+
case 0x6:
401+
if ((frm_ctrl->type == NRF_WIFI_DATA_PKT_TYPE) ||
402+
(frm_ctrl->type == NRF_WIFI_MGMT_PKT_TYPE)) {
403+
filter_check = true;
404+
}
405+
break;
406+
case 0x8:
407+
if (frm_ctrl->type == NRF_WIFI_CTRL_PKT_TYPE)
408+
filter_check = true;
409+
break;
410+
case 0xa:
411+
if ((frm_ctrl->type == NRF_WIFI_CTRL_PKT_TYPE) ||
412+
(frm_ctrl->type == NRF_WIFI_MGMT_PKT_TYPE)) {
413+
filter_check = true;
414+
}
415+
break;
416+
case 0xb:
417+
if ((frm_ctrl->type == NRF_WIFI_DATA_PKT_TYPE) ||
418+
(frm_ctrl->type == NRF_WIFI_CTRL_PKT_TYPE)) {
419+
filter_check = true;
420+
}
421+
/* all other packet_filter cases - bit 0 is set and hence all
422+
* packet types are allowed or in the case of 0xE - all packet
423+
* type bits are enabled */
424+
default:
425+
filter_check = true;
426+
break;
427+
}
428+
return filter_check;
429+
}
430+
#endif
431+
369432
#ifdef CONFIG_NRF700X_RAW_DATA_TX
370433
bool nrf_wifi_util_is_rawpktmode_enabled(struct nrf_wifi_fmac_vif_ctx *vif)
371434
{

nrf_wifi/fw_if/umac_if/src/rx.c

+19-8
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ enum nrf_wifi_status nrf_wifi_fmac_rx_event_process(struct nrf_wifi_fmac_dev_ctx
226226
struct nrf_wifi_fmac_rx_pool_map_info pool_info;
227227
#if defined(CONFIG_NRF700X_RAW_DATA_RX) || defined(CONFIG_NRF700X_PROMISC_DATA_RX)
228228
struct raw_rx_pkt_header raw_rx_hdr;
229+
unsigned short frame_control;
229230
#endif /* CONFIG_NRF700X_RAW_DATA_RX || CONFIG_NRF700X_PROMISC_DATA_RX */
230231
void *nwb = NULL;
231232
void *nwb_data = NULL;
@@ -311,10 +312,20 @@ enum nrf_wifi_status nrf_wifi_fmac_rx_event_process(struct nrf_wifi_fmac_dev_ctx
311312
raw_rx_hdr.rate_flags = config->rate_flags;
312313
raw_rx_hdr.rate = config->rate;
313314

314-
def_priv->callbk_fns.rx_sniffer_frm_callbk_fn(vif_ctx->os_vif_ctx,
315-
nwb,
316-
&raw_rx_hdr,
317-
false);
315+
nrf_wifi_osal_mem_cpy(fmac_dev_ctx->fpriv->opriv,
316+
&frame_control,
317+
nwb_data,
318+
sizeof(unsigned short));
319+
320+
nrf_wifi_osal_log_err(fmac_dev_ctx->fpriv->opriv,
321+
"%s: frame_control is %d",
322+
__func__, frame_control);
323+
if (nrf_wifi_util_check_filt_setting(vif_ctx, &frame_control)) {
324+
def_priv->callbk_fns.sniffer_callbk_fn(vif_ctx->os_vif_ctx,
325+
nwb,
326+
&raw_rx_hdr,
327+
false);
328+
}
318329
}
319330
#endif
320331
#ifdef CONFIG_NRF700X_STA_MODE
@@ -383,10 +394,10 @@ enum nrf_wifi_status nrf_wifi_fmac_rx_event_process(struct nrf_wifi_fmac_dev_ctx
383394
raw_rx_hdr.rate_flags = config->rate_flags;
384395
raw_rx_hdr.rate = config->rate;
385396

386-
def_priv->callbk_fns.rx_sniffer_frm_callbk_fn(vif_ctx->os_vif_ctx,
387-
nwb,
388-
&raw_rx_hdr,
389-
true);
397+
def_priv->callbk_fns.sniffer_callbk_fn(vif_ctx->os_vif_ctx,
398+
nwb,
399+
&raw_rx_hdr,
400+
true);
390401
}
391402
#endif /* CONFIG_NRF700X_RAW_DATA_RX || CONFIG_NRF700X_PROMISC_DATA_RX */
392403
else {

0 commit comments

Comments
 (0)