xref: /wlan-driver/qcacld-3.0/components/mlme/core/inc/wlan_mlme_twt_api.h (revision 5113495b16420b49004c444715d2daae2066e7dc)
1 /*
2  * Copyright (c) 2021, The Linux Foundation. All rights reserved.
3  * Copyright (c) 2022-2023 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: declare internal API related to the mlme TWT functionality
20  */
21 
22 #ifndef _WLAN_MLME_TWT_API_H_
23 #define _WLAN_MLME_TWT_API_H_
24 
25 #include <wlan_mlme_public_struct.h>
26 #include <wlan_mlme_twt_public_struct.h>
27 #include <wlan_objmgr_psoc_obj.h>
28 #include <wlan_objmgr_global_obj.h>
29 #include <wlan_cmn.h>
30 #include <wlan_objmgr_vdev_obj.h>
31 #include <wlan_objmgr_peer_obj.h>
32 #include "wlan_cm_roam_public_struct.h"
33 
34 #ifdef WLAN_SUPPORT_TWT
35 /**
36  * mlme_is_twt_setup_in_progress() - Get if TWT setup command is in progress
37  * for given dialog id
38  * @psoc: Pointer to global psoc object
39  * @peer_mac: Global peer mac address
40  * @dialog_id: Dialog ID
41  *
42  * Return: True if Setup is in progress
43  */
44 bool mlme_is_twt_setup_in_progress(struct wlan_objmgr_psoc *psoc,
45 				   struct qdf_mac_addr *peer_mac,
46 				   uint8_t dialog_id);
47 
48 /**
49  * mlme_add_twt_session()  - Add TWT session entry in the TWT context
50  * @psoc: Pointer to global psoc object
51  * @peer_mac: Global peer mac address
52  * @dialog_id: Dialog ID
53  *
54  * Return: None
55  */
56 void mlme_add_twt_session(struct wlan_objmgr_psoc *psoc,
57 			  struct qdf_mac_addr *peer_mac,
58 			  uint8_t dialog_id);
59 
60 /**
61  * mlme_set_twt_setup_done()  - Set TWT setup complete for given dialog ID
62  * @psoc: Pointer to psoc object
63  * @peer_mac: Pointer to peer mac address
64  * @dialog_id: Dialog id
65  * @is_set: Set or clear the setup done flag
66  *
67  * Return: None
68  */
69 void mlme_set_twt_setup_done(struct wlan_objmgr_psoc *psoc,
70 			     struct qdf_mac_addr *peer_mac,
71 			     uint8_t dialog_id, bool is_set);
72 
73 /**
74  * mlme_is_twt_setup_done()  - Get if TWT session is established for given
75  * dialog id.
76  * @psoc: Pointer to psoc object
77  * @peer_mac: Pointer to peer mac address
78  * @dialog_id: Dialog id
79  *
80  * Return: Return true if TWT session exists for given dialog ID.
81  */
82 bool mlme_is_twt_setup_done(struct wlan_objmgr_psoc *psoc,
83 			    struct qdf_mac_addr *peer_mac, uint8_t dialog_id);
84 
85 /**
86  * mlme_set_twt_session_state() - Set the TWT session state for the given dialog
87  * id in TWT context
88  * @psoc: Pointer to psoc object
89  * @peer_mac: Pointer to peer mac address
90  * @dialog_id: Dialog id
91  * @state: TWT session state
92  *
93  * Return: None
94  */
95 void mlme_set_twt_session_state(struct wlan_objmgr_psoc *psoc,
96 				struct qdf_mac_addr *peer_mac,
97 				uint8_t dialog_id,
98 				enum wlan_twt_session_state state);
99 
100 /**
101  * mlme_get_twt_session_state()  - Get TWT session state for given dialog id
102  * @psoc: Pointer to psoc object
103  * @peer_mac: Pointer to peer mac address
104  * @dialog_id: Dialog id
105  *
106  * Return:  TWT session state.
107  */
108 enum wlan_twt_session_state
109 mlme_get_twt_session_state(struct wlan_objmgr_psoc *psoc,
110 			   struct qdf_mac_addr *peer_mac, uint8_t dialog_id);
111 
112 /**
113  * mlme_get_twt_peer_capabilities  - Get TWT peer capabilities
114  * @psoc: Pointer to psoc object
115  * @peer_mac: Pointer to peer mac address
116  *
117  * Return: Peer TWT capabilities
118  */
119 uint8_t mlme_get_twt_peer_capabilities(struct wlan_objmgr_psoc *psoc,
120 				       struct qdf_mac_addr *peer_mac);
121 
122 /**
123  * mlme_set_twt_peer_capabilities() - Set the TWT peer capabilities in TWT
124  * context
125  * @psoc: Pointer to psoc object
126  * @peer_mac: Pointer to peer mac address
127  * @caps: Bitmap of enum wlan_twt_capabilities
128  */
129 void mlme_set_twt_peer_capabilities(struct wlan_objmgr_psoc *psoc,
130 				    struct qdf_mac_addr *peer_mac,
131 				    uint8_t caps);
132 
133 /**
134  * mlme_twt_any_peer_cmd_in_progress() - Iterate through the list of peers
135  * and check if the given command is in progress
136  * @psoc: Pointer to psoc object
137  * @vdev_id: Vdev id
138  * @dialog_id: Dialog id
139  * @cmd: command
140  *
141  * This API is used to check for the given @dialog_id if the
142  * @cmd command is in progress for any of the peers.
143  *
144  * Return: true if command is in progress, false otherwise
145  */
146 bool
147 mlme_twt_any_peer_cmd_in_progress(struct wlan_objmgr_psoc *psoc,
148 				  uint8_t vdev_id,
149 				  uint8_t dialog_id,
150 				  enum wlan_twt_commands cmd);
151 
152 /**
153  * mlme_sap_set_twt_all_peers_cmd_in_progress()  - Iterate through the list
154  * of peers and set the command in the TWT session entry in the TWT context
155  * @psoc: Pointer to global psoc object
156  * @vdev_id: Vdev id
157  * @dialog_id: Dialog ID
158  * @cmd: Command
159  *
160  * This API iterates through the list of peers and updates the active
161  * command to @cmd for the given dialog_id.
162  *
163  * Return: QDF_STATUS
164  */
165 QDF_STATUS
166 mlme_sap_set_twt_all_peers_cmd_in_progress(struct wlan_objmgr_psoc *psoc,
167 					   uint8_t vdev_id,
168 					   uint8_t dialog_id,
169 					   enum wlan_twt_commands cmd);
170 
171 /**
172  * mlme_init_all_peers_twt_context()  - Iterate through the list
173  * of peers and initialize the TWT context structure
174  * @psoc: Pointer to global psoc object
175  * @vdev_id: Vdev id
176  * @dialog_id: Dialog ID
177  *
178  * This API iterates through the list of peers and initializes
179  * the TWT context structure
180  *
181  * Return: QDF_STATUS
182  */
183 QDF_STATUS
184 mlme_init_all_peers_twt_context(struct wlan_objmgr_psoc *psoc,
185 				uint8_t vdev_id,
186 				uint8_t dialog_id);
187 /**
188  * mlme_init_twt_context() - Initialize TWT context structure
189  * @psoc: Pointer to psoc object
190  * @peer_mac: Pointer to peer mac address
191  * @dialog_id: Dialog id
192  *
193  * This API will be called on disconnection from AP.
194  *
195  * Return: QDF_STATUS
196  */
197 QDF_STATUS mlme_init_twt_context(struct wlan_objmgr_psoc *psoc,
198 				 struct qdf_mac_addr *peer_mac,
199 				 uint8_t dialog_id);
200 
201 /**
202  * mlme_twt_set_wait_for_notify()  - Set wait for notify flag.
203  * @psoc: Pointer to psoc object
204  * @vdev_id: VDEV identifier
205  * @is_set: Set or clear notify flag
206  *
207  * Return: None
208  */
209 void mlme_twt_set_wait_for_notify(struct wlan_objmgr_psoc *psoc,
210 				  uint32_t vdev_id, bool is_set);
211 
212 /**
213  * mlme_is_twt_notify_in_progress() - Get TWT notify in progress.
214  * @psoc: Pointer to psoc object
215  * @vdev_id: VDEV identifier
216  *
217  * Return: True if twt_notify is in progress.
218  */
219 bool mlme_is_twt_notify_in_progress(struct wlan_objmgr_psoc *psoc,
220 				    uint32_t vdev_id);
221 
222 #ifdef WLAN_FEATURE_11AX
223 /**
224  * mlme_is_flexible_twt_enabled() - Check if flexible TWT is enabled.
225  * @psoc: Pointer to psoc object
226  *
227  * Return: True if flexible TWT is supported
228  */
229 bool mlme_is_flexible_twt_enabled(struct wlan_objmgr_psoc *psoc);
230 #else
231 static inline
mlme_is_flexible_twt_enabled(struct wlan_objmgr_psoc * psoc)232 bool mlme_is_flexible_twt_enabled(struct wlan_objmgr_psoc *psoc)
233 {
234 	return false;
235 }
236 #endif /* WLAN_FEATURE_11AX */
237 
238 /**
239  * mlme_set_twt_command_in_progress() - Set TWT command is in progress.
240  * @psoc: Pointer to psoc object
241  * @peer_mac: Pointer to peer mac address
242  * @dialog_id: Dialog id
243  * @cmd: TWT command
244  *
245  * Return: QDF_STATUS
246  */
247 QDF_STATUS mlme_set_twt_command_in_progress(struct wlan_objmgr_psoc *psoc,
248 					    struct qdf_mac_addr *peer_mac,
249 					    uint8_t dialog_id,
250 					    enum wlan_twt_commands cmd);
251 
252 /**
253  * mlme_sap_twt_peer_is_cmd_in_progress() - For a given peer_mac check if
254  * the given command is in progress
255  * @psoc: Pointer to psoc object
256  * @peer_mac: Pointer to peer mac address
257  * @dialog_id: Dialog id
258  * @cmd: TWT command
259  *
260  * Return: True if given command is in progress.
261  */
262 bool mlme_sap_twt_peer_is_cmd_in_progress(struct wlan_objmgr_psoc *psoc,
263 					  struct qdf_mac_addr *peer_mac,
264 					  uint8_t dialog_id,
265 					  enum wlan_twt_commands cmd);
266 
267 
268 /**
269  * mlme_twt_is_command_in_progress() - Check if given command is in progress
270  * @psoc: Pointer to psoc object
271  * @peer_mac: Pointer to peer mac address
272  * @dialog_id: Dialog id
273  * @cmd: TWT command
274  * @active_cmd: Fill the active command in this output parameter
275  *
276  * Return: True if given command is in progress.
277  */
278 bool mlme_twt_is_command_in_progress(struct wlan_objmgr_psoc *psoc,
279 				     struct qdf_mac_addr *peer_mac,
280 				     uint8_t dialog_id,
281 				     enum wlan_twt_commands cmd,
282 				     enum wlan_twt_commands *active_cmd);
283 
284 /**
285  * mlme_is_max_twt_sessions_reached() - Check if the maximum number of
286  * TWT sessions reached or not excluding the given dialog_id
287  * @psoc: Pointer to global PSOC object
288  * @peer_mac: Global peer mac address
289  * @dialog_id: dialog id
290  *
291  * Check if the number of active TWT sessions is equal to the maximum number
292  * of TWT sessions supported. Only count the TWT session slot if it not
293  * TWT_ALL_SESSIONS_DIALOG_ID and dialog id is different from input dialog_id,
294  * because if same dialog_id already exists in the TWT sessions, we should
295  * return false since re-negotiation is supported on existing dialog_id.
296  *
297  * Return: True if slot is available for dialog_id, false otherwise
298  */
299 bool mlme_is_max_twt_sessions_reached(struct wlan_objmgr_psoc *psoc,
300 				      struct qdf_mac_addr *peer_mac,
301 				      uint8_t dialog_id);
302 
303 /**
304  * mlme_is_24ghz_twt_enabled() - Get if TWT is enabled on 2.4Ghz
305  * @psoc: Pointer to psoc object
306  *
307  * Return: True if TWT is allowed on 2.4Ghz connection.
308  */
309 bool mlme_is_24ghz_twt_enabled(struct wlan_objmgr_psoc *psoc);
310 
311 #ifdef WLAN_TWT_CONV_SUPPORTED
312 /**
313  * mlme_is_twt_disable_info_frame() - Get if TWT info frame enabled/disabled
314  * @psoc: Pointer to psoc object
315  *
316  * Return: True if TWT info frame is disabled.
317  */
318 bool mlme_is_twt_disable_info_frame(struct wlan_objmgr_psoc *psoc);
319 #else
320 static inline bool
mlme_is_twt_disable_info_frame(struct wlan_objmgr_psoc * psoc)321 mlme_is_twt_disable_info_frame(struct wlan_objmgr_psoc *psoc)
322 {
323 	return false;
324 }
325 
326 #endif
327 #else
328 static inline
mlme_set_twt_peer_capabilities(struct wlan_objmgr_psoc * psoc,struct qdf_mac_addr * peer_mac,uint8_t caps)329 void mlme_set_twt_peer_capabilities(struct wlan_objmgr_psoc *psoc,
330 				    struct qdf_mac_addr *peer_mac,
331 				    uint8_t caps)
332 {}
333 
334 static inline
mlme_init_twt_context(struct wlan_objmgr_psoc * psoc,struct qdf_mac_addr * peer_mac,uint8_t dialog_id)335 QDF_STATUS mlme_init_twt_context(struct wlan_objmgr_psoc *psoc,
336 				 struct qdf_mac_addr *peer_mac,
337 				 uint8_t dialog_id)
338 {
339 	return QDF_STATUS_E_NOSUPPORT;
340 }
341 
342 static inline
mlme_is_flexible_twt_enabled(struct wlan_objmgr_psoc * psoc)343 bool mlme_is_flexible_twt_enabled(struct wlan_objmgr_psoc *psoc)
344 {
345 	return false;
346 }
347 
348 static inline bool
mlme_is_24ghz_twt_enabled(struct wlan_objmgr_psoc * psoc)349 mlme_is_24ghz_twt_enabled(struct wlan_objmgr_psoc *psoc)
350 {
351 	return false;
352 }
353 
354 static inline bool
mlme_is_twt_disable_info_frame(struct wlan_objmgr_psoc * psoc)355 mlme_is_twt_disable_info_frame(struct wlan_objmgr_psoc *psoc)
356 {
357 	return false;
358 }
359 
360 #endif /* WLAN_SUPPORT_TWT */
361 #endif /* _WLAN_MLME_TWT_API_H_ */
362