xref: /wlan-driver/qcacld-3.0/components/pmo/core/src/wlan_pmo_pkt_filter.c (revision 5113495b16420b49004c444715d2daae2066e7dc)
1 /*
2  * Copyright (c) 2017-2018 The Linux Foundation. All rights reserved.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for
5  * any purpose with or without fee is hereby granted, provided that the
6  * above copyright notice and this permission notice appear in all
7  * copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16  * PERFORMANCE OF THIS SOFTWARE.
17  */
18 /**
19  * DOC: Implements Packet filter feature API's
20  */
21 
22 #include "wlan_pmo_pkt_filter.h"
23 #include "wlan_pmo_tgt_api.h"
24 #include "wlan_pmo_main.h"
25 #include "wlan_pmo_obj_mgmt_public_struct.h"
26 
27 #define PMO_PKT_FILTERS_DEFAULT 12
28 #define PMO_PKT_FILTERS_DISABLED 0xffffffff
29 
pmo_get_num_packet_filters(struct wlan_objmgr_psoc * psoc)30 uint32_t pmo_get_num_packet_filters(struct wlan_objmgr_psoc *psoc)
31 {
32 	struct pmo_psoc_priv_obj *psoc_ctx;
33 	bool pkt_filter = false;
34 
35 	pmo_psoc_with_ctx(psoc, psoc_ctx) {
36 		pkt_filter = pmo_intersect_packet_filter(psoc_ctx);
37 	}
38 
39 	return pkt_filter ? PMO_PKT_FILTERS_DEFAULT : PMO_PKT_FILTERS_DISABLED;
40 }
41 
pmo_core_set_pkt_filter(struct wlan_objmgr_psoc * psoc,struct pmo_rcv_pkt_fltr_cfg * pmo_set_pkt_fltr_req,uint8_t vdev_id)42 QDF_STATUS pmo_core_set_pkt_filter(struct wlan_objmgr_psoc *psoc,
43 			struct pmo_rcv_pkt_fltr_cfg *pmo_set_pkt_fltr_req,
44 			uint8_t vdev_id)
45 {
46 	struct wlan_objmgr_vdev *vdev;
47 	QDF_STATUS status;
48 
49 	pmo_enter();
50 
51 	if (!psoc) {
52 		pmo_err("psoc is null");
53 		status = QDF_STATUS_E_NULL_VALUE;
54 		goto out;
55 	}
56 
57 	vdev = wlan_objmgr_get_vdev_by_id_from_psoc(psoc, vdev_id, WLAN_PMO_ID);
58 	if (!vdev) {
59 		pmo_err("vdev is NULL");
60 		status = QDF_STATUS_E_NULL_VALUE;
61 		goto out;
62 	}
63 
64 	status = pmo_tgt_set_pkt_filter(vdev, pmo_set_pkt_fltr_req, vdev_id);
65 	if (status != QDF_STATUS_SUCCESS)
66 		goto dec_ref;
67 
68 dec_ref:
69 	wlan_objmgr_vdev_release_ref(vdev, WLAN_PMO_ID);
70 out:
71 	pmo_exit();
72 
73 	return status;
74 
75 }
76 
pmo_core_clear_pkt_filter(struct wlan_objmgr_psoc * psoc,struct pmo_rcv_pkt_fltr_clear_param * pmo_clr_pkt_fltr_param,uint8_t vdev_id)77 QDF_STATUS pmo_core_clear_pkt_filter(struct wlan_objmgr_psoc *psoc,
78 		struct pmo_rcv_pkt_fltr_clear_param *pmo_clr_pkt_fltr_param,
79 		uint8_t vdev_id)
80 {
81 	struct wlan_objmgr_vdev *vdev;
82 	QDF_STATUS status;
83 
84 	pmo_enter();
85 
86 	if (!psoc) {
87 		pmo_err("psoc is null");
88 		status = QDF_STATUS_E_NULL_VALUE;
89 		goto out;
90 	}
91 
92 	vdev = wlan_objmgr_get_vdev_by_id_from_psoc(psoc, vdev_id, WLAN_PMO_ID);
93 	if (!vdev) {
94 		pmo_err("vdev is NULL");
95 		status = QDF_STATUS_E_NULL_VALUE;
96 		goto out;
97 	}
98 
99 	status = pmo_tgt_clear_pkt_filter(vdev, pmo_clr_pkt_fltr_param,
100 								vdev_id);
101 	if (status != QDF_STATUS_SUCCESS)
102 		goto dec_ref;
103 
104 dec_ref:
105 	wlan_objmgr_vdev_release_ref(vdev, WLAN_PMO_ID);
106 out:
107 	pmo_exit();
108 
109 	return status;
110 
111 }
112