1 /*
2  * Copyright (c) 2018-2021 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 any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17 
18 /**
19  * DOC: define UCFG APIs exposed for TWT by the mlme component
20  */
21 
22 #include "wlan_mlme_main.h"
23 #include "wlan_mlme_api.h"
24 #include "wlan_mlme_ucfg_api.h"
25 #include "cfg_mlme_twt.h"
26 #include "wlan_mlme_twt_ucfg_api.h"
27 
28 #if defined(WLAN_SUPPORT_TWT) && defined(WLAN_FEATURE_11AX) && \
29 	!defined(WLAN_TWT_CONV_SUPPORTED)
30 QDF_STATUS
ucfg_mlme_get_twt_requestor(struct wlan_objmgr_psoc * psoc,bool * val)31 ucfg_mlme_get_twt_requestor(struct wlan_objmgr_psoc *psoc,
32 			    bool *val)
33 {
34 	struct wlan_mlme_psoc_ext_obj *mlme_obj;
35 
36 	mlme_obj = mlme_get_psoc_ext_obj(psoc);
37 	if (!mlme_obj) {
38 		*val = cfg_default(CFG_TWT_REQUESTOR);
39 		return QDF_STATUS_E_INVAL;
40 	}
41 
42 	*val = mlme_obj->cfg.he_caps.dot11_he_cap.twt_request;
43 
44 	return QDF_STATUS_SUCCESS;
45 }
46 
47 QDF_STATUS
ucfg_mlme_set_twt_requestor(struct wlan_objmgr_psoc * psoc,bool val)48 ucfg_mlme_set_twt_requestor(struct wlan_objmgr_psoc *psoc,
49 			    bool val)
50 {
51 	struct wlan_mlme_psoc_ext_obj *mlme_obj;
52 
53 	mlme_obj = mlme_get_psoc_ext_obj(psoc);
54 	if (!mlme_obj)
55 		return QDF_STATUS_E_INVAL;
56 
57 	mlme_obj->cfg.he_caps.dot11_he_cap.twt_request = val;
58 
59 	return QDF_STATUS_SUCCESS;
60 }
61 
62 QDF_STATUS
ucfg_mlme_get_twt_responder(struct wlan_objmgr_psoc * psoc,bool * val)63 ucfg_mlme_get_twt_responder(struct wlan_objmgr_psoc *psoc,
64 			    bool *val)
65 {
66 	struct wlan_mlme_psoc_ext_obj *mlme_obj;
67 
68 	mlme_obj = mlme_get_psoc_ext_obj(psoc);
69 	if (!mlme_obj) {
70 		*val = cfg_default(CFG_TWT_RESPONDER);
71 		return QDF_STATUS_E_INVAL;
72 	}
73 
74 	*val = mlme_obj->cfg.he_caps.dot11_he_cap.twt_responder;
75 
76 	return QDF_STATUS_SUCCESS;
77 }
78 
79 QDF_STATUS
ucfg_mlme_set_twt_responder(struct wlan_objmgr_psoc * psoc,bool val)80 ucfg_mlme_set_twt_responder(struct wlan_objmgr_psoc *psoc,
81 			    bool val)
82 {
83 	struct wlan_mlme_psoc_ext_obj *mlme_obj;
84 
85 	mlme_obj = mlme_get_psoc_ext_obj(psoc);
86 	if (!mlme_obj)
87 		return QDF_STATUS_E_INVAL;
88 
89 	mlme_obj->cfg.he_caps.dot11_he_cap.twt_responder = val;
90 
91 	return QDF_STATUS_SUCCESS;
92 }
93 
94 QDF_STATUS
ucfg_mlme_set_twt_requestor_flag(struct wlan_objmgr_psoc * psoc,bool val)95 ucfg_mlme_set_twt_requestor_flag(struct wlan_objmgr_psoc *psoc, bool val)
96 {
97 	struct wlan_mlme_psoc_ext_obj *mlme_obj;
98 
99 	mlme_obj = mlme_get_psoc_ext_obj(psoc);
100 	if (!mlme_obj)
101 		return QDF_STATUS_E_INVAL;
102 
103 	mlme_obj->cfg.twt_cfg.req_flag = val;
104 
105 	return QDF_STATUS_SUCCESS;
106 }
107 
108 QDF_STATUS
ucfg_mlme_set_twt_responder_flag(struct wlan_objmgr_psoc * psoc,bool val)109 ucfg_mlme_set_twt_responder_flag(struct wlan_objmgr_psoc *psoc, bool val)
110 {
111 	struct wlan_mlme_psoc_ext_obj *mlme_obj;
112 
113 	mlme_obj = mlme_get_psoc_ext_obj(psoc);
114 	if (!mlme_obj)
115 		return QDF_STATUS_E_INVAL;
116 
117 	mlme_obj->cfg.twt_cfg.res_flag = val;
118 
119 	return QDF_STATUS_SUCCESS;
120 }
121 
122 QDF_STATUS
ucfg_mlme_reset_twt_active_cmd(struct wlan_objmgr_psoc * psoc,struct qdf_mac_addr * peer_macaddr,uint8_t dialog_id)123 ucfg_mlme_reset_twt_active_cmd(struct wlan_objmgr_psoc *psoc,
124 			       struct qdf_mac_addr *peer_macaddr,
125 			       uint8_t dialog_id)
126 {
127 	mlme_set_twt_command_in_progress(psoc, peer_macaddr, dialog_id,
128 					 WLAN_TWT_NONE);
129 
130 	return QDF_STATUS_SUCCESS;
131 }
132 
133 QDF_STATUS
ucfg_mlme_get_twt_congestion_timeout(struct wlan_objmgr_psoc * psoc,uint32_t * val)134 ucfg_mlme_get_twt_congestion_timeout(struct wlan_objmgr_psoc *psoc,
135 				     uint32_t *val)
136 {
137 	struct wlan_mlme_psoc_ext_obj *mlme_obj;
138 
139 	mlme_obj = mlme_get_psoc_ext_obj(psoc);
140 	if (!mlme_obj) {
141 		*val = cfg_default(CFG_TWT_CONGESTION_TIMEOUT);
142 		return QDF_STATUS_E_INVAL;
143 	}
144 
145 	*val = mlme_obj->cfg.twt_cfg.twt_congestion_timeout;
146 
147 	return QDF_STATUS_SUCCESS;
148 }
149 
150 QDF_STATUS
ucfg_mlme_set_twt_congestion_timeout(struct wlan_objmgr_psoc * psoc,uint32_t val)151 ucfg_mlme_set_twt_congestion_timeout(struct wlan_objmgr_psoc *psoc,
152 				     uint32_t val)
153 {
154 	struct wlan_mlme_psoc_ext_obj *mlme_obj;
155 
156 	mlme_obj = mlme_get_psoc_ext_obj(psoc);
157 	if (!mlme_obj)
158 		return QDF_STATUS_E_INVAL;
159 
160 	mlme_obj->cfg.twt_cfg.twt_congestion_timeout = val;
161 
162 	return QDF_STATUS_SUCCESS;
163 }
164 
165 QDF_STATUS
ucfg_mlme_set_enable_twt(struct wlan_objmgr_psoc * psoc,bool val)166 ucfg_mlme_set_enable_twt(struct wlan_objmgr_psoc *psoc,
167 			 bool val)
168 {
169 	struct wlan_mlme_psoc_ext_obj *mlme_obj;
170 
171 	mlme_obj = mlme_get_psoc_ext_obj(psoc);
172 	if (!mlme_obj)
173 		return QDF_STATUS_E_INVAL;
174 
175 	mlme_obj->cfg.twt_cfg.is_twt_enabled = val;
176 
177 	return QDF_STATUS_SUCCESS;
178 }
179 
180 QDF_STATUS
ucfg_mlme_get_twt_bcast_requestor(struct wlan_objmgr_psoc * psoc,bool * val)181 ucfg_mlme_get_twt_bcast_requestor(struct wlan_objmgr_psoc *psoc,
182 				  bool *val)
183 {
184 	struct wlan_mlme_psoc_ext_obj *mlme_obj;
185 
186 	mlme_obj = mlme_get_psoc_ext_obj(psoc);
187 	if (!mlme_obj) {
188 		uint32_t b_req_res;
189 
190 		b_req_res = cfg_default(CFG_BCAST_TWT_REQ_RESP);
191 		*val = CFG_TWT_GET_BCAST_REQ(b_req_res);
192 		return QDF_STATUS_E_INVAL;
193 	}
194 
195 	*val = mlme_obj->cfg.twt_cfg.is_bcast_requestor_enabled;
196 
197 	return QDF_STATUS_SUCCESS;
198 }
199 
200 QDF_STATUS
ucfg_mlme_get_twt_bcast_responder(struct wlan_objmgr_psoc * psoc,bool * val)201 ucfg_mlme_get_twt_bcast_responder(struct wlan_objmgr_psoc *psoc,
202 				  bool *val)
203 {
204 	struct wlan_mlme_psoc_ext_obj *mlme_obj;
205 
206 	mlme_obj = mlme_get_psoc_ext_obj(psoc);
207 	if (!mlme_obj) {
208 		uint32_t b_req_res;
209 
210 		b_req_res = cfg_default(CFG_BCAST_TWT_REQ_RESP);
211 		*val = CFG_TWT_GET_BCAST_RES(b_req_res);
212 		return QDF_STATUS_E_INVAL;
213 	}
214 
215 	*val = mlme_obj->cfg.twt_cfg.is_bcast_responder_enabled;
216 
217 	return QDF_STATUS_SUCCESS;
218 }
219 
220 QDF_STATUS
ucfg_mlme_set_twt_bcast_requestor(struct wlan_objmgr_psoc * psoc,bool val)221 ucfg_mlme_set_twt_bcast_requestor(struct wlan_objmgr_psoc *psoc,
222 				  bool val)
223 {
224 	struct wlan_mlme_psoc_ext_obj *mlme_obj;
225 
226 	mlme_obj = mlme_get_psoc_ext_obj(psoc);
227 	if (!mlme_obj)
228 		return QDF_STATUS_E_INVAL;
229 
230 	mlme_obj->cfg.twt_cfg.is_bcast_requestor_enabled = val;
231 
232 	return QDF_STATUS_SUCCESS;
233 }
234 
235 QDF_STATUS
ucfg_mlme_set_twt_bcast_responder(struct wlan_objmgr_psoc * psoc,bool val)236 ucfg_mlme_set_twt_bcast_responder(struct wlan_objmgr_psoc *psoc,
237 				  bool val)
238 {
239 	struct wlan_mlme_psoc_ext_obj *mlme_obj;
240 
241 	mlme_obj = mlme_get_psoc_ext_obj(psoc);
242 	if (!mlme_obj)
243 		return QDF_STATUS_E_INVAL;
244 
245 	mlme_obj->cfg.twt_cfg.is_bcast_responder_enabled = val;
246 
247 	return QDF_STATUS_SUCCESS;
248 }
249 
250 QDF_STATUS
ucfg_mlme_set_twt_nudge_tgt_cap(struct wlan_objmgr_psoc * psoc,bool val)251 ucfg_mlme_set_twt_nudge_tgt_cap(struct wlan_objmgr_psoc *psoc, bool val)
252 {
253 	struct wlan_mlme_psoc_ext_obj *mlme_obj;
254 
255 	mlme_obj = mlme_get_psoc_ext_obj(psoc);
256 	if (!mlme_obj)
257 		return QDF_STATUS_E_INVAL;
258 
259 	mlme_obj->cfg.twt_cfg.is_twt_nudge_tgt_cap_enabled = val;
260 
261 	return QDF_STATUS_SUCCESS;
262 }
263 
ucfg_mlme_get_twt_peer_bcast_capabilities(struct wlan_objmgr_psoc * psoc,struct qdf_mac_addr * peer_mac)264 bool ucfg_mlme_get_twt_peer_bcast_capabilities(struct wlan_objmgr_psoc *psoc,
265 					       struct qdf_mac_addr *peer_mac)
266 {
267 	uint8_t peer_cap;
268 
269 	peer_cap = mlme_get_twt_peer_capabilities(psoc, peer_mac);
270 
271 	if (peer_cap & WLAN_TWT_CAPA_BROADCAST)
272 		return true;
273 
274 	return false;
275 }
276 
ucfg_mlme_get_twt_peer_responder_capabilities(struct wlan_objmgr_psoc * psoc,struct qdf_mac_addr * peer_mac)277 bool ucfg_mlme_get_twt_peer_responder_capabilities(
278 					struct wlan_objmgr_psoc *psoc,
279 					struct qdf_mac_addr *peer_mac)
280 {
281 	uint8_t peer_cap;
282 
283 	peer_cap = mlme_get_twt_peer_capabilities(psoc, peer_mac);
284 
285 	if (peer_cap & WLAN_TWT_CAPA_RESPONDER)
286 		return true;
287 
288 	return false;
289 }
290 
291 QDF_STATUS
ucfg_mlme_get_twt_nudge_tgt_cap(struct wlan_objmgr_psoc * psoc,bool * val)292 ucfg_mlme_get_twt_nudge_tgt_cap(struct wlan_objmgr_psoc *psoc, bool *val)
293 {
294 	struct wlan_mlme_psoc_ext_obj *mlme_obj;
295 
296 	mlme_obj = mlme_get_psoc_ext_obj(psoc);
297 	if (!mlme_obj)
298 		return QDF_STATUS_E_INVAL;
299 
300 	*val = mlme_obj->cfg.twt_cfg.is_twt_nudge_tgt_cap_enabled;
301 
302 	return QDF_STATUS_SUCCESS;
303 }
304 
305 QDF_STATUS
ucfg_mlme_set_twt_all_twt_tgt_cap(struct wlan_objmgr_psoc * psoc,bool val)306 ucfg_mlme_set_twt_all_twt_tgt_cap(struct wlan_objmgr_psoc *psoc, bool val)
307 {
308 	struct wlan_mlme_psoc_ext_obj *mlme_obj;
309 
310 	mlme_obj = mlme_get_psoc_ext_obj(psoc);
311 	if (!mlme_obj)
312 		return QDF_STATUS_E_INVAL;
313 
314 	mlme_obj->cfg.twt_cfg.is_all_twt_tgt_cap_enabled = val;
315 
316 	return QDF_STATUS_SUCCESS;
317 }
318 
319 QDF_STATUS
ucfg_mlme_get_twt_all_twt_tgt_cap(struct wlan_objmgr_psoc * psoc,bool * val)320 ucfg_mlme_get_twt_all_twt_tgt_cap(struct wlan_objmgr_psoc *psoc, bool *val)
321 {
322 	struct wlan_mlme_psoc_ext_obj *mlme_obj;
323 
324 	mlme_obj = mlme_get_psoc_ext_obj(psoc);
325 	if (!mlme_obj)
326 		return QDF_STATUS_E_INVAL;
327 
328 	*val = mlme_obj->cfg.twt_cfg.is_all_twt_tgt_cap_enabled;
329 
330 	return QDF_STATUS_SUCCESS;
331 }
332 
333 QDF_STATUS
ucfg_mlme_set_twt_statistics_tgt_cap(struct wlan_objmgr_psoc * psoc,bool val)334 ucfg_mlme_set_twt_statistics_tgt_cap(struct wlan_objmgr_psoc *psoc, bool val)
335 {
336 	struct wlan_mlme_psoc_ext_obj *mlme_obj;
337 
338 	mlme_obj = mlme_get_psoc_ext_obj(psoc);
339 	if (!mlme_obj)
340 		return QDF_STATUS_E_INVAL;
341 
342 	mlme_obj->cfg.twt_cfg.is_twt_statistics_tgt_cap_enabled = val;
343 
344 	return QDF_STATUS_SUCCESS;
345 }
346 
347 QDF_STATUS
ucfg_mlme_get_twt_statistics_tgt_cap(struct wlan_objmgr_psoc * psoc,bool * val)348 ucfg_mlme_get_twt_statistics_tgt_cap(struct wlan_objmgr_psoc *psoc, bool *val)
349 {
350 	struct wlan_mlme_psoc_ext_obj *mlme_obj;
351 
352 	mlme_obj = mlme_get_psoc_ext_obj(psoc);
353 	if (!mlme_obj)
354 		return QDF_STATUS_E_INVAL;
355 
356 	*val = mlme_obj->cfg.twt_cfg.is_twt_statistics_tgt_cap_enabled;
357 
358 	return QDF_STATUS_SUCCESS;
359 }
360 
361 QDF_STATUS
ucfg_mlme_set_twt_res_service_cap(struct wlan_objmgr_psoc * psoc,bool val)362 ucfg_mlme_set_twt_res_service_cap(struct wlan_objmgr_psoc *psoc, bool val)
363 {
364 	struct wlan_mlme_psoc_ext_obj *mlme_obj;
365 
366 	mlme_obj = mlme_get_psoc_ext_obj(psoc);
367 	if (!mlme_obj)
368 		return QDF_STATUS_E_INVAL;
369 
370 	mlme_obj->cfg.twt_cfg.twt_res_svc_cap = val;
371 
372 	return QDF_STATUS_SUCCESS;
373 }
374 
375 QDF_STATUS
ucfg_mlme_get_twt_res_service_cap(struct wlan_objmgr_psoc * psoc,bool * val)376 ucfg_mlme_get_twt_res_service_cap(struct wlan_objmgr_psoc *psoc, bool *val)
377 {
378 	struct wlan_mlme_psoc_ext_obj *mlme_obj;
379 
380 	mlme_obj = mlme_get_psoc_ext_obj(psoc);
381 	if (!mlme_obj)
382 		return QDF_STATUS_E_INVAL;
383 
384 	*val = mlme_obj->cfg.twt_cfg.twt_res_svc_cap;
385 
386 	return QDF_STATUS_SUCCESS;
387 }
388 
389 #endif
390