1 /*
2  * Copyright (c) 2024 Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 /**
8  * @brief File containing promiscuous mode
9  * support functions for the FMAC IF Layer
10  * of the Wi-Fi driver.
11  */
12 
13 #include "osal_api.h"
14 #include "system/fmac_structs.h"
15 #include "system/fmac_promisc.h"
16 
nrf_wifi_util_check_filt_setting(struct nrf_wifi_fmac_vif_ctx * vif,unsigned short * frame_control)17 bool nrf_wifi_util_check_filt_setting(struct nrf_wifi_fmac_vif_ctx *vif,
18 				      unsigned short *frame_control)
19 {
20 	bool filter_check = false;
21 	struct nrf_wifi_fmac_frame_ctrl *frm_ctrl =
22 	(struct nrf_wifi_fmac_frame_ctrl *)frame_control;
23 
24 	switch (vif->packet_filter) {
25 		case FILTER_MGMT_ONLY:
26 			if (frm_ctrl->type == NRF_WIFI_MGMT_PKT_TYPE) {
27 				filter_check = true;
28 			}
29 			break;
30 		case FILTER_DATA_ONLY:
31 			if (frm_ctrl->type == NRF_WIFI_DATA_PKT_TYPE) {
32 				filter_check = true;
33 			}
34 			break;
35 		case FILTER_DATA_MGMT:
36 			if ((frm_ctrl->type == NRF_WIFI_DATA_PKT_TYPE) ||
37 			    (frm_ctrl->type == NRF_WIFI_MGMT_PKT_TYPE)) {
38 				filter_check = true;
39 			}
40 			break;
41 		case FILTER_CTRL_ONLY:
42 			if (frm_ctrl->type == NRF_WIFI_CTRL_PKT_TYPE) {
43 				filter_check = true;
44 			}
45 			break;
46 		case FILTER_CTRL_MGMT:
47 			if ((frm_ctrl->type == NRF_WIFI_CTRL_PKT_TYPE) ||
48 			    (frm_ctrl->type == NRF_WIFI_MGMT_PKT_TYPE)) {
49 				filter_check = true;
50 			}
51 			break;
52 		case FILTER_DATA_CTRL:
53 			if ((frm_ctrl->type == NRF_WIFI_DATA_PKT_TYPE) ||
54 			    (frm_ctrl->type == NRF_WIFI_CTRL_PKT_TYPE)) {
55 				filter_check = true;
56 			}
57 			break;
58 		/* all other packet_filter cases - bit 0 is set and hence all
59 		 * packet types are allowed or in the case of 0xE - all packet
60 		 * type bits are enabled */
61 		default:
62 			filter_check = true;
63 			break;
64 	}
65 	return filter_check;
66 }
67