xref: /wlan-driver/qcacld-3.0/components/denylist_mgr/core/src/wlan_dlm_main.c (revision 5113495b16420b49004c444715d2daae2066e7dc)
1 /*
2  * Copyright (c) 2019-2020 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for
6  * any purpose with or without fee is hereby granted, provided that the
7  * above copyright notice and this permission notice appear in all
8  * copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17  * PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 /**
21  * DOC: wlan_dlm_main.c
22  *
23  * WLAN Denylist Mgr related APIs
24  *
25  */
26 
27 /* Include files */
28 
29 #include "target_if_dlm.h"
30 #include <wlan_dlm_ucfg_api.h>
31 #include "cfg_ucfg_api.h"
32 #include <wlan_dlm_core.h>
33 
34 struct dlm_pdev_priv_obj *
dlm_get_pdev_obj(struct wlan_objmgr_pdev * pdev)35 dlm_get_pdev_obj(struct wlan_objmgr_pdev *pdev)
36 {
37 	struct dlm_pdev_priv_obj *dlm_pdev_obj;
38 
39 	dlm_pdev_obj = wlan_objmgr_pdev_get_comp_private_obj(pdev,
40 						  WLAN_UMAC_COMP_DENYLIST_MGR);
41 
42 	return dlm_pdev_obj;
43 }
44 
45 struct dlm_psoc_priv_obj *
dlm_get_psoc_obj(struct wlan_objmgr_psoc * psoc)46 dlm_get_psoc_obj(struct wlan_objmgr_psoc *psoc)
47 {
48 	struct dlm_psoc_priv_obj *dlm_psoc_obj;
49 
50 	dlm_psoc_obj = wlan_objmgr_psoc_get_comp_private_obj(psoc,
51 						  WLAN_UMAC_COMP_DENYLIST_MGR);
52 
53 	return dlm_psoc_obj;
54 }
55 
56 QDF_STATUS
dlm_pdev_object_created_notification(struct wlan_objmgr_pdev * pdev,void * arg)57 dlm_pdev_object_created_notification(struct wlan_objmgr_pdev *pdev,
58 				     void *arg)
59 {
60 	struct dlm_pdev_priv_obj *dlm_ctx;
61 	QDF_STATUS status;
62 
63 	dlm_ctx = qdf_mem_malloc(sizeof(*dlm_ctx));
64 
65 	if (!dlm_ctx)
66 		return QDF_STATUS_E_FAILURE;
67 
68 	status = qdf_mutex_create(&dlm_ctx->reject_ap_list_lock);
69 
70 	if (QDF_IS_STATUS_ERROR(status)) {
71 		dlm_err("Failed to create mutex");
72 		qdf_mem_free(dlm_ctx);
73 		return status;
74 	}
75 	qdf_list_create(&dlm_ctx->reject_ap_list, MAX_BAD_AP_LIST_SIZE);
76 
77 	target_if_dlm_register_tx_ops(&dlm_ctx->dlm_tx_ops);
78 	status = wlan_objmgr_pdev_component_obj_attach(pdev,
79 						   WLAN_UMAC_COMP_DENYLIST_MGR,
80 						   dlm_ctx,
81 						   QDF_STATUS_SUCCESS);
82 	if (QDF_IS_STATUS_ERROR(status)) {
83 		dlm_err("Failed to attach pdev_ctx with pdev");
84 		qdf_list_destroy(&dlm_ctx->reject_ap_list);
85 		qdf_mutex_destroy(&dlm_ctx->reject_ap_list_lock);
86 		qdf_mem_free(dlm_ctx);
87 	}
88 
89 	return status;
90 }
91 
92 QDF_STATUS
dlm_pdev_object_destroyed_notification(struct wlan_objmgr_pdev * pdev,void * arg)93 dlm_pdev_object_destroyed_notification(struct wlan_objmgr_pdev *pdev,
94 				       void *arg)
95 {
96 	struct dlm_pdev_priv_obj *dlm_ctx;
97 
98 	dlm_ctx = dlm_get_pdev_obj(pdev);
99 
100 	if (!dlm_ctx) {
101 		dlm_err("DLM Pdev obj is NULL");
102 		return QDF_STATUS_E_FAILURE;
103 	}
104 	/* Clear away the memory allocated for the bad BSSIDs */
105 	dlm_flush_reject_ap_list(dlm_ctx);
106 	qdf_list_destroy(&dlm_ctx->reject_ap_list);
107 	qdf_mutex_destroy(&dlm_ctx->reject_ap_list_lock);
108 
109 	wlan_objmgr_pdev_component_obj_detach(pdev,
110 					      WLAN_UMAC_COMP_DENYLIST_MGR,
111 					      dlm_ctx);
112 	qdf_mem_free(dlm_ctx);
113 
114 	return QDF_STATUS_SUCCESS;
115 }
116 
117 QDF_STATUS
dlm_psoc_object_created_notification(struct wlan_objmgr_psoc * psoc,void * arg)118 dlm_psoc_object_created_notification(struct wlan_objmgr_psoc *psoc,
119 				     void *arg)
120 {
121 	struct dlm_psoc_priv_obj *dlm_psoc_obj;
122 	QDF_STATUS status;
123 
124 	dlm_psoc_obj = qdf_mem_malloc(sizeof(*dlm_psoc_obj));
125 
126 	if (!dlm_psoc_obj)
127 		return QDF_STATUS_E_FAILURE;
128 
129 	status = wlan_objmgr_psoc_component_obj_attach(psoc,
130 						   WLAN_UMAC_COMP_DENYLIST_MGR,
131 						   dlm_psoc_obj,
132 						   QDF_STATUS_SUCCESS);
133 	if (QDF_IS_STATUS_ERROR(status)) {
134 		dlm_err("Failed to attach psoc_ctx with psoc");
135 		qdf_mem_free(dlm_psoc_obj);
136 	}
137 
138 	return status;
139 }
140 
141 QDF_STATUS
dlm_psoc_object_destroyed_notification(struct wlan_objmgr_psoc * psoc,void * arg)142 dlm_psoc_object_destroyed_notification(struct wlan_objmgr_psoc *psoc, void *arg)
143 {
144 	struct dlm_psoc_priv_obj *dlm_psoc_obj;
145 
146 	dlm_psoc_obj = dlm_get_psoc_obj(psoc);
147 
148 	if (!dlm_psoc_obj) {
149 		dlm_err("DLM psoc obj NULL");
150 		return QDF_STATUS_E_FAILURE;
151 	}
152 	wlan_objmgr_psoc_component_obj_detach(psoc,
153 					      WLAN_UMAC_COMP_DENYLIST_MGR,
154 					      dlm_psoc_obj);
155 	qdf_mem_free(dlm_psoc_obj);
156 
157 	return QDF_STATUS_SUCCESS;
158 }
159 
160 static void
dlm_init_cfg(struct wlan_objmgr_psoc * psoc,struct dlm_config * dlm_cfg)161 dlm_init_cfg(struct wlan_objmgr_psoc *psoc, struct dlm_config *dlm_cfg)
162 {
163 	dlm_cfg->avoid_list_exipry_time =
164 				cfg_get(psoc, CFG_AVOID_LIST_EXPIRY_TIME);
165 	dlm_cfg->deny_list_exipry_time =
166 				cfg_get(psoc, CFG_DENY_LIST_EXPIRY_TIME);
167 	dlm_cfg->bad_bssid_counter_reset_time =
168 				cfg_get(psoc, CFG_BAD_BSSID_RESET_TIME);
169 	dlm_cfg->bad_bssid_counter_thresh =
170 				cfg_get(psoc, CFG_BAD_BSSID_COUNTER_THRESHOLD);
171 	dlm_cfg->delta_rssi =
172 				cfg_get(psoc, CFG_DENYLIST_RSSI_THRESHOLD);
173 }
174 
175 QDF_STATUS
dlm_cfg_psoc_open(struct wlan_objmgr_psoc * psoc)176 dlm_cfg_psoc_open(struct wlan_objmgr_psoc *psoc)
177 {
178 	struct dlm_psoc_priv_obj *dlm_psoc_obj;
179 
180 	dlm_psoc_obj = dlm_get_psoc_obj(psoc);
181 
182 	if (!dlm_psoc_obj) {
183 		dlm_err("DLM psoc obj NULL");
184 		return QDF_STATUS_E_FAILURE;
185 	}
186 
187 	dlm_init_cfg(psoc, &dlm_psoc_obj->dlm_cfg);
188 
189 	return QDF_STATUS_SUCCESS;
190 }
191