Skip to content

Commit

Permalink
nrf_wifi: Bring in Promiscuous mode filtering support in driver
Browse files Browse the repository at this point in the history
This set of changes brings in promiscuous mode filtering support in
the driver. Since, firmware woulld be unable to filter packets in
the case of promiscuous mode as it would lead to connection issues,
filtering support is moved to the driver for promiscuous mode.

Signed-off-by: Vivekananda Uppunda <vivekananda.uppunda@nordicsemi.no>
  • Loading branch information
VivekUppunda committed Oct 7, 2024
1 parent af7b21c commit 20e5dd1
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 14 deletions.
8 changes: 4 additions & 4 deletions drivers/nrf_wifi/fw_if/umac_if/inc/default/fmac_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,10 @@ struct nrf_wifi_fmac_callbk_fns {
signed short signal);
#endif /* NRF70_STA_MODE */
#if defined(NRF70_RAW_DATA_RX) || defined(NRF70_PROMISC_DATA_RX)
void (*rx_sniffer_frm_callbk_fn)(void *os_vif_ctx,
void *frm,
struct raw_rx_pkt_header *,
bool pkt_free);
void (*sniffer_callbk_fn)(void *os_vif_ctx,
void *frm,
struct raw_rx_pkt_header *,
bool pkt_free);
#endif /* NRF70_RAW_DATA_RX || NRF70_PROMISC_DATA_RX */
void (*reg_change_callbk_fn)(void *os_vif_ctx,
struct nrf_wifi_event_regulatory_change *reg_change,
Expand Down
25 changes: 25 additions & 0 deletions drivers/nrf_wifi/fw_if/umac_if/inc/fmac_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,27 @@
#define NRF_WIFI_FMAC_IPV6_TOS_SHIFT 0x04 /* 4bit */
#define NRF_WIFI_FMAC_ETH_TYPE_MASK 0xFFFF

#if defined(NRF70_PROMISC_DATA_RX)
#define NRF_WIFI_MGMT_PKT_TYPE 0x0
#define NRF_WIFI_DATA_PKT_TYPE 0x2
#define NRF_WIFI_CTRL_PKT_TYPE 0x1

/* Frame Control structure */
struct nrf_wifi_fmac_frame_ctrl{
unsigned short protocolVersion : 2;
unsigned short type : 2;
unsigned short subtype : 4;
unsigned short toDS : 1;
unsigned short fromDS : 1;
unsigned short moreFragments : 1;
unsigned short retry : 1;
unsigned short powerManagement : 1;
unsigned short moreData : 1;
unsigned short protectedFrame : 1;
unsigned short order : 1;
} __NRF_WIFI_PKD;
#endif

struct nrf_wifi_fmac_ieee80211_hdr {
unsigned short fc;
unsigned short dur_id;
Expand Down Expand Up @@ -131,6 +152,10 @@ void nrf_wifi_util_rx_convert_amsdu_to_eth(struct nrf_wifi_fmac_dev_ctx *fmac_de
bool nrf_wifi_util_is_arr_zero(unsigned char *arr,
unsigned int arr_sz);

#if defined(NRF70_PROMISC_DATA_RX)
bool nrf_wifi_util_check_filt_setting(struct nrf_wifi_fmac_vif_ctx *vif,
unsigned short *frame_control);
#endif
#endif /* !NRF70_RADIO_TEST */

void *wifi_fmac_priv(struct nrf_wifi_fmac_priv *def);
Expand Down
68 changes: 68 additions & 0 deletions drivers/nrf_wifi/fw_if/umac_if/src/fmac_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "fmac_api_common.h"
#include "fmac_util.h"
#include "host_rpu_umac_if.h"
#include "host_rpu_sys_if.h"

bool nrf_wifi_util_is_multicast_addr(const unsigned char *addr)
{
Expand Down Expand Up @@ -368,6 +369,73 @@ bool nrf_wifi_util_is_arr_zero(unsigned char *arr,
return true;
}

#if defined(NRF70_PROMISC_DATA_RX)
bool nrf_wifi_util_check_filt_setting(struct nrf_wifi_fmac_vif_ctx *vif,
unsigned short *frame_control)
{
bool filter_check = false;
struct nrf_wifi_fmac_frame_ctrl *frm_ctrl =
(struct nrf_wifi_fmac_frame_ctrl *)frame_control;

/**
* The different filter settings for 802.11 packets within the driver
* is a bit map. The description of the different valid values for
* the case statements are as follows:
* 0x2 - Enable management packets only
* 0x4 - Enable data packets only
* 0x8 - Enable control packets only
* 0x6 - Enable data and management packets
* 0xa - Enable control and management packets
* 0xc - Enable data and control packets
* The bit map setting is checked against the packet type field and
* the relevant filtered packet is sent up the stack. if bit 0 is set
* in the driver bitmap, all packet types are allowed to be sent upstack.
**/
switch (vif->packet_filter) {
case 0x2:
if (frm_ctrl->type == NRF_WIFI_MGMT_PKT_TYPE) {
filter_check = true;
}
break;
case 0x4:
if (frm_ctrl->type == NRF_WIFI_DATA_PKT_TYPE) {
filter_check = true;
}
break;
case 0x6:
if ((frm_ctrl->type == NRF_WIFI_DATA_PKT_TYPE) ||
(frm_ctrl->type == NRF_WIFI_MGMT_PKT_TYPE)) {
filter_check = true;
}
break;
case 0x8:
if (frm_ctrl->type == NRF_WIFI_CTRL_PKT_TYPE) {
filter_check = true;
}
break;
case 0xa:
if ((frm_ctrl->type == NRF_WIFI_CTRL_PKT_TYPE) ||
(frm_ctrl->type == NRF_WIFI_MGMT_PKT_TYPE)) {
filter_check = true;
}
break;
case 0xc:
if ((frm_ctrl->type == NRF_WIFI_DATA_PKT_TYPE) ||
(frm_ctrl->type == NRF_WIFI_CTRL_PKT_TYPE)) {
filter_check = true;
}
break;
/* all other packet_filter cases - bit 0 is set and hence all
* packet types are allowed or in the case of 0xE - all packet
* type bits are enabled */
default:
filter_check = true;
break;
}
return filter_check;
}
#endif

void *wifi_fmac_priv(struct nrf_wifi_fmac_priv *def)
{
return &def->priv;
Expand Down
47 changes: 37 additions & 10 deletions drivers/nrf_wifi/fw_if/umac_if/src/rx.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ enum nrf_wifi_status nrf_wifi_fmac_rx_event_process(struct nrf_wifi_fmac_dev_ctx
struct nrf_wifi_fmac_rx_pool_map_info pool_info;
#if defined(NRF70_RAW_DATA_RX) || defined(NRF70_PROMISC_DATA_RX)
struct raw_rx_pkt_header raw_rx_hdr;
#if defined(NRF70_PROMISC_DATA_RX)
unsigned short frame_control;
#endif
#endif /* NRF70_RAW_DATA_RX || NRF70_PROMISC_DATA_RX */
void *nwb = NULL;
void *nwb_data = NULL;
Expand Down Expand Up @@ -282,18 +285,26 @@ enum nrf_wifi_status nrf_wifi_fmac_rx_event_process(struct nrf_wifi_fmac_dev_ctx
rx_buf_info->nwb = 0;
rx_buf_info->mapped = false;

#ifdef NRF70_PROMISC_DATA_RX
nrf_wifi_osal_mem_cpy(fmac_dev_ctx->fpriv->opriv,
&frame_control,
nwb_data,
sizeof(unsigned short));
#endif

if (config->rx_pkt_type == NRF_WIFI_RX_PKT_DATA) {
#ifdef NRF70_PROMISC_DATA_RX
if (vif_ctx->promisc_mode) {
raw_rx_hdr.frequency = config->frequency;
raw_rx_hdr.signal = config->signal;
raw_rx_hdr.rate_flags = config->rate_flags;
raw_rx_hdr.rate = config->rate;

def_priv->callbk_fns.rx_sniffer_frm_callbk_fn(vif_ctx->os_vif_ctx,
nwb,
&raw_rx_hdr,
false);
if (nrf_wifi_util_check_filt_setting(vif_ctx, &frame_control)) {
def_priv->callbk_fns.sniffer_callbk_fn(vif_ctx->os_vif_ctx,
nwb,
&raw_rx_hdr,
false);
}
}
#endif
#ifdef NRF70_STA_MODE
Expand Down Expand Up @@ -356,11 +367,27 @@ enum nrf_wifi_status nrf_wifi_fmac_rx_event_process(struct nrf_wifi_fmac_dev_ctx
raw_rx_hdr.signal = config->signal;
raw_rx_hdr.rate_flags = config->rate_flags;
raw_rx_hdr.rate = config->rate;

def_priv->callbk_fns.rx_sniffer_frm_callbk_fn(vif_ctx->os_vif_ctx,
nwb,
&raw_rx_hdr,
true);
#if defined(NRF70_PROMISC_DATA_RX)
if (nrf_wifi_util_check_filt_setting(vif_ctx, &frame_control))
#endif
{
def_priv->callbk_fns.sniffer_callbk_fn(vif_ctx->os_vif_ctx,
nwb,
&raw_rx_hdr,
true);
}
#if defined(NRF700X_PROMISC_DATA_RX)
/**
* In the case of Monitor mode, the sniffer callback function
* will free the packet. For promiscuous mode, if the packet
* is not meant to be sent up the stack, the packet needs
* to be freed here.
*/
else {
nrf_wifi_osal_nbuf_free(fmac_dev_ctx->fpriv->opriv,
nwb);
}
#endif
}
#endif /* NRF70_RAW_DATA_RX || NRF70_PROMISC_DATA_RX */
else {
Expand Down

0 comments on commit 20e5dd1

Please sign in to comment.