xref: /wlan-driver/qca-wifi-host-cmn/umac/mlme/connection_mgr/core/src/wlan_cm_main.h (revision 5113495b16420b49004c444715d2daae2066e7dc) !
1 /*
2  * Copyright (c) 2012-2015, 2020-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: wlan_cm_main.h
20  *
21  * This header file maintain structures required for connection mgr core
22  */
23 
24 #ifndef __WLAN_CM_MAIN_H__
25 #define __WLAN_CM_MAIN_H__
26 
27 #include "include/wlan_vdev_mlme.h"
28 #include <qdf_event.h>
29 #include <wlan_cm_public_struct.h>
30 
31 /* Max candidate/attempts to be tried to connect */
32 #define CM_MAX_CONNECT_ATTEMPTS 10
33 /*
34  * Default connect timeout to consider 3 sec join timeout + 5 sec auth timeout +
35  * 2 sec assoc timeout + 5 sec buffer for vdev related timeouts.
36  */
37 #define CM_MAX_PER_CANDIDATE_CONNECT_TIMEOUT 15000
38 
39 /*
40  * Default max retry attempts to be tried for a candidate.
41  * In SAE connection this value will be overwritten from the sae_connect_retries
42  * INI
43  */
44 #define CM_MAX_CANDIDATE_RETRIES 1
45 /* Max time to wait for scan for SSID */
46 #define CM_SCAN_MAX_TIME 5000
47 /* Max connect/disconnect/roam req that can be queued at a time */
48 #define CM_MAX_REQ 5
49 
50 /**
51  * enum wlan_cm_sm_state - Connection manager states
52  * @WLAN_CM_S_INIT:                     Default state, IDLE state
53  * @WLAN_CM_S_CONNECTING:               State when connect request comes
54  * @WLAN_CM_S_CONNECTED:                State when connect is complete
55  * @WLAN_CM_S_DISCONNECTING:            State when disconnect request comes
56  * @WLAN_CM_S_ROAMING:                  State when roaming is in progress
57  * @WLAN_CM_S_MAX:                      Max State
58  * @WLAN_CM_SS_IDLE:                    Idle state (no substate)
59  * @WLAN_CM_SS_JOIN_PENDING:            Connect request not serialized
60  * @WLAN_CM_SS_SCAN:                    Scan for SSID state
61  * @WLAN_CM_SS_JOIN_ACTIVE:             Connect request activated
62  * @WLAN_CM_SS_PREAUTH:                 Roam substate of preauth stage
63  * @WLAN_CM_SS_REASSOC:                 Roam substate for reassoc state
64  * @WLAN_CM_SS_ROAM_STARTED:            Roaming in progress (LFR 3.0)
65  * @WLAN_CM_SS_ROAM_SYNC:               Roam sync indication from FW
66  * @WLAN_CM_SS_IDLE_DUE_TO_LINK_SWITCH: Substate when VDEV moves to INIT state
67  *                                      due to link switch.
68  * @WLAN_CM_SS_MAX:                     Max Substate
69  */
70 enum wlan_cm_sm_state {
71 	WLAN_CM_S_INIT = 0,
72 	WLAN_CM_S_CONNECTING = 1,
73 	WLAN_CM_S_CONNECTED = 2,
74 	WLAN_CM_S_DISCONNECTING = 3,
75 	WLAN_CM_S_ROAMING = 4,
76 	WLAN_CM_S_MAX = 5,
77 	WLAN_CM_SS_IDLE = 6,
78 	WLAN_CM_SS_JOIN_PENDING = 7,
79 	WLAN_CM_SS_SCAN = 8,
80 	WLAN_CM_SS_JOIN_ACTIVE = 9,
81 	WLAN_CM_SS_PREAUTH = 10,
82 	WLAN_CM_SS_REASSOC = 11,
83 	WLAN_CM_SS_ROAM_STARTED = 12,
84 	WLAN_CM_SS_ROAM_SYNC = 13,
85 	WLAN_CM_SS_IDLE_DUE_TO_LINK_SWITCH = 14,
86 	WLAN_CM_SS_MAX = 15,
87 };
88 
89 /**
90  * struct cm_state_sm - connection manager sm
91  * @cm_sm_lock: sm lock
92  * @sm_hdl: sm handlers
93  * @cm_state: current state
94  * @cm_substate: current substate
95  */
96 struct cm_state_sm {
97 #ifdef WLAN_CM_USE_SPINLOCK
98 	qdf_spinlock_t cm_sm_lock;
99 #else
100 	qdf_mutex_t cm_sm_lock;
101 #endif
102 	struct wlan_sm *sm_hdl;
103 	enum wlan_cm_sm_state cm_state;
104 	enum wlan_cm_sm_state cm_substate;
105 };
106 
107 /**
108  * struct cm_connect_req - connect req stored in connect manager
109  * @cm_id: Connect manager id
110  * @scan_id: scan id for scan for ssid
111  * @req: connect req from osif
112  * @candidate_list: candidate list
113  * @cur_candidate: current candidate
114  * @cur_candidate_retries: attempts for current candidate
115  * @connect_attempts: number of connect attempts tried
116  * @connect_active_time: timestamp when connect became active
117  * @first_candidate_rsp: connect response for first candidate
118  */
119 struct cm_connect_req {
120 	wlan_cm_id cm_id;
121 	wlan_scan_id scan_id;
122 	struct wlan_cm_connect_req req;
123 	qdf_list_t *candidate_list;
124 	struct scan_cache_node *cur_candidate;
125 	uint8_t cur_candidate_retries;
126 	uint8_t connect_attempts;
127 	qdf_time_t connect_active_time;
128 #ifdef CONN_MGR_ADV_FEATURE
129 	struct wlan_cm_connect_resp *first_candidate_rsp;
130 #endif
131 };
132 
133 /**
134  * struct cm_roam_req - roam req stored in connect manager
135  * @cm_id: Connect manager id
136  * @req: roam req from osif
137  * @candidate_list: candidate list
138  * @cur_candidate: current candidate
139  * @num_preauth_retry: retry times for the same candidate
140  */
141 struct cm_roam_req {
142 	wlan_cm_id cm_id;
143 	struct wlan_cm_roam_req req;
144 	qdf_list_t *candidate_list;
145 	struct scan_cache_node *cur_candidate;
146 #ifdef WLAN_FEATURE_PREAUTH_ENABLE
147 	uint8_t num_preauth_retry;
148 #endif
149 };
150 
151 /**
152  * struct cm_disconnect_req - disconnect req
153  * @cm_id: Connect manager id
154  * @req: disconnect connect req from osif
155  */
156 struct cm_disconnect_req {
157 	wlan_cm_id cm_id;
158 	struct wlan_cm_disconnect_req req;
159 };
160 
161 /**
162  * struct cm_req - connect manager req
163  * @node: connection manager req node
164  * @cm_id: cm id
165  * @failed_req: set if req failed before serialization,
166  * with a commands pending before it, ie this is the latest command which failed
167  * but still some operation(req) is pending.
168  * @connect_req: connect req
169  * @discon_req: disconnect req
170  * @roam_req: roam req
171  */
172 struct cm_req {
173 	qdf_list_node_t node;
174 	wlan_cm_id cm_id;
175 	bool failed_req;
176 	union {
177 		struct cm_connect_req connect_req;
178 		struct cm_disconnect_req discon_req;
179 		struct cm_roam_req roam_req;
180 	};
181 };
182 
183 /**
184  * enum cm_req_del_type - Context in which a request is removed from
185  * connection manager request list
186  * @CM_REQ_DEL_ACTIVE: Remove request from active queue
187  * @CM_REQ_DEL_PENDING: Remove request from pending queue
188  * @CM_REQ_DEL_FLUSH: Request removed due to request list flush
189  * @CM_REQ_DEL_MAX: Maximum enumeration
190  */
191 enum cm_req_del_type {
192 	CM_REQ_DEL_ACTIVE,
193 	CM_REQ_DEL_PENDING,
194 	CM_REQ_DEL_FLUSH,
195 	CM_REQ_DEL_MAX,
196 };
197 
198 #ifdef SM_ENG_HIST_ENABLE
199 
200 #define CM_REQ_HISTORY_SIZE 30
201 
202 /**
203  * struct cm_req_history_info - History element structure
204  * @cm_id: Request id
205  * @add_time: Timestamp when the request was added to the list
206  * @del_time: Timestamp when the request was removed from list
207  * @add_cm_state: Conn_SM state when req was added
208  * @del_cm_state: Conn_SM state when req was deleted
209  * @del_type: Context in which delete was triggered. i.e active removal,
210  * pending removal or flush from queue.
211  */
212 struct cm_req_history_info {
213 	wlan_cm_id cm_id;
214 	uint64_t add_time;
215 	uint64_t del_time;
216 	enum wlan_cm_sm_state add_cm_state;
217 	enum wlan_cm_sm_state del_cm_state;
218 	enum cm_req_del_type del_type;
219 };
220 
221 /**
222  * struct cm_req_history - Connection manager history
223  * @cm_req_hist_lock: CM request history lock
224  * @index: Index of next entry that will be updated
225  * @data: Array of history element
226  */
227 struct cm_req_history {
228 	qdf_spinlock_t cm_req_hist_lock;
229 	uint8_t index;
230 	struct cm_req_history_info data[CM_REQ_HISTORY_SIZE];
231 };
232 #endif
233 
234 /**
235  * struct cnx_mgr - connect manager req
236  * @vdev: vdev back pointer
237  * @sm: state machine
238  * @active_cm_id: cm_id of the active command, if any active command present
239  * @preauth_in_progress: is roaming in preauth state, set during preauth state,
240  * this is used to get which command to flush from serialization during
241  * host roaming.
242  * @req_list: connect/disconnect req list
243  * @cm_req_lock: lock to manipulate/read the cm req list
244  * @disconnect_count: disconnect count
245  * @connect_count: connect count
246  * @force_rsne_override: if QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE is set by
247  * framework
248  * @global_cmd_id: global cmd id for getting cm id for connect/disconnect req
249  * @max_connect_attempts: Max attempts to be tried for a connect req
250  * @connect_timeout: Connect timeout value in milliseconds
251  * @scan_requester_id: scan requester id.
252  * @disconnect_complete: disconnect completion wait event
253  * @ext_cm_ptr: connection manager ext pointer
254  * @req_history: Holds the connection manager history
255  * @cm_candidate_advance_filter:
256  * @cm_candidate_list_custom_sort:
257  */
258 struct cnx_mgr {
259 	struct wlan_objmgr_vdev *vdev;
260 	struct cm_state_sm sm;
261 	wlan_cm_id active_cm_id;
262 	bool preauth_in_progress;
263 	qdf_list_t req_list;
264 #ifdef WLAN_CM_USE_SPINLOCK
265 	qdf_spinlock_t cm_req_lock;
266 #else
267 	qdf_mutex_t cm_req_lock;
268 #endif
269 	uint8_t disconnect_count;
270 	uint8_t connect_count;
271 	bool force_rsne_override;
272 	qdf_atomic_t global_cmd_id;
273 	uint8_t max_connect_attempts;
274 	uint32_t connect_timeout;
275 	wlan_scan_requester scan_requester_id;
276 	qdf_event_t disconnect_complete;
277 	cm_ext_t *ext_cm_ptr;
278 #ifdef SM_ENG_HIST_ENABLE
279 	struct cm_req_history req_history;
280 #endif
281 #ifndef CONN_MGR_ADV_FEATURE
282 	void (*cm_candidate_advance_filter)(struct wlan_objmgr_vdev *vdev,
283 					    struct scan_filter *filter);
284 	void (*cm_candidate_list_custom_sort)(struct wlan_objmgr_vdev *vdev,
285 					      qdf_list_t *list);
286 #endif
287 };
288 
289 /**
290  * struct vdev_op_search_arg - vdev op search arguments
291  * @current_vdev_id: current vdev id
292  * @sap_go_vdev_id: sap/go vdev id
293  * @sta_cli_vdev_id: sta/p2p client vdev id
294  */
295 struct vdev_op_search_arg {
296 	uint8_t current_vdev_id;
297 	uint8_t sap_go_vdev_id;
298 	uint8_t sta_cli_vdev_id;
299 };
300 
301 /**
302  * wlan_cm_init() - Invoke connection manager init
303  * @vdev_mlme:  VDEV MLME comp object
304  *
305  * API allocates CM and init
306  *
307  * Return: SUCCESS on successful allocation
308  *         FAILURE, if registration fails
309  */
310 QDF_STATUS wlan_cm_init(struct vdev_mlme_obj *vdev_mlme);
311 
312 /**
313  * wlan_cm_deinit() - Invoke connection manager deinit
314  * @vdev_mlme:  VDEV MLME comp object
315  *
316  * API destroys CM
317  *
318  * Return: SUCCESS on successful deletion
319  *         FAILURE, if deletion fails
320  */
321 QDF_STATUS wlan_cm_deinit(struct vdev_mlme_obj *vdev_mlme);
322 #endif /* __WLAN_CM_MAIN_H__ */
323