xref: /wlan-dirver/qca-wifi-host-cmn/umac/mlme/connection_mgr/core/src/wlan_cm_main.h (revision 901120c066e139c7f8a2c8e4820561fdd83c67ef)
1 /*
2  * Copyright (c) 2012-2015, 2020-2021, The Linux Foundation. All rights reserved.
3  * Copyright (c) 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: 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 5
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_MAX:                     Max Substate
67  */
68 enum wlan_cm_sm_state {
69 	WLAN_CM_S_INIT = 0,
70 	WLAN_CM_S_CONNECTING = 1,
71 	WLAN_CM_S_CONNECTED = 2,
72 	WLAN_CM_S_DISCONNECTING = 3,
73 	WLAN_CM_S_ROAMING = 4,
74 	WLAN_CM_S_MAX = 5,
75 	WLAN_CM_SS_IDLE = 6,
76 	WLAN_CM_SS_JOIN_PENDING = 7,
77 	WLAN_CM_SS_SCAN = 8,
78 	WLAN_CM_SS_JOIN_ACTIVE = 9,
79 	WLAN_CM_SS_PREAUTH = 10,
80 	WLAN_CM_SS_REASSOC = 11,
81 	WLAN_CM_SS_ROAM_STARTED = 12,
82 	WLAN_CM_SS_ROAM_SYNC = 13,
83 	WLAN_CM_SS_MAX = 14,
84 };
85 
86 /**
87  * struct cm_state_sm - connection manager sm
88  * @cm_sm_lock: sm lock
89  * @sm_hdl: sm handlers
90  * @cm_state: current state
91  * @cm_substate: current substate
92  */
93 struct cm_state_sm {
94 #ifdef WLAN_CM_USE_SPINLOCK
95 	qdf_spinlock_t cm_sm_lock;
96 #else
97 	qdf_mutex_t cm_sm_lock;
98 #endif
99 	struct wlan_sm *sm_hdl;
100 	enum wlan_cm_sm_state cm_state;
101 	enum wlan_cm_sm_state cm_substate;
102 };
103 
104 /**
105  * struct cm_connect_req - connect req stored in connect manager
106  * @cm_id: Connect manager id
107  * @scan_id: scan id for scan for ssid
108  * @req: connect req from osif
109  * @candidate_list: candidate list
110  * @cur_candidate: current candidate
111  * @cur_candidate_retries: attempts for current candidate
112  * @connect_attempts: number of connect attempts tried
113  * @connect_active_time: timestamp when connect became active
114  */
115 struct cm_connect_req {
116 	wlan_cm_id cm_id;
117 	wlan_scan_id scan_id;
118 	struct wlan_cm_connect_req req;
119 	qdf_list_t *candidate_list;
120 	struct scan_cache_node *cur_candidate;
121 	uint8_t cur_candidate_retries;
122 	uint8_t connect_attempts;
123 	qdf_time_t connect_active_time;
124 };
125 
126 /**
127  * struct cm_roam_req - roam req stored in connect manager
128  * @cm_id: Connect manager id
129  * @req: roam req from osif
130  * @candidate_list: candidate list
131  * @cur_candidate: current candidate
132  * @num_preauth_retry: retry times for the same candidate
133  */
134 struct cm_roam_req {
135 	wlan_cm_id cm_id;
136 	struct wlan_cm_roam_req req;
137 	qdf_list_t *candidate_list;
138 	struct scan_cache_node *cur_candidate;
139 #ifdef WLAN_FEATURE_PREAUTH_ENABLE
140 	uint8_t num_preauth_retry;
141 #endif
142 };
143 
144 /**
145  * struct cm_disconnect_req - disconnect req
146  * @cm_id: Connect manager id
147  * @req: disconnect connect req from osif
148  */
149 struct cm_disconnect_req {
150 	wlan_cm_id cm_id;
151 	struct wlan_cm_disconnect_req req;
152 };
153 
154 /**
155  * struct cm_req - connect manager req
156  * @node: connection manager req node
157  * @cm_id: cm id
158  * @failed_req: set if req failed before serialization,
159  * with a commands pending before it, ie this is the latest command which failed
160  * but still some operation(req) is pending.
161  * @connect_req: connect req
162  * @discon_req: disconnect req
163  * @roam_req: roam req
164  */
165 struct cm_req {
166 	qdf_list_node_t node;
167 	wlan_cm_id cm_id;
168 	bool failed_req;
169 	union {
170 		struct cm_connect_req connect_req;
171 		struct cm_disconnect_req discon_req;
172 		struct cm_roam_req roam_req;
173 	};
174 };
175 
176 /**
177  * enum cm_req_del_type - Context in which a request is removed from
178  * connection manager request list
179  * @CM_REQ_DEL_ACTIVE: Remove request from active queue
180  * @CM_REQ_DEL_PENDING: Remove request from pending queue
181  * @CM_REQ_DEL_FLUSH: Request removed due to request list flush
182  */
183 enum cm_req_del_type {
184 	CM_REQ_DEL_ACTIVE,
185 	CM_REQ_DEL_PENDING,
186 	CM_REQ_DEL_FLUSH,
187 	CM_REQ_DEL_MAX,
188 };
189 
190 #ifdef SM_ENG_HIST_ENABLE
191 
192 #define CM_REQ_HISTORY_SIZE 30
193 
194 /**
195  * struct cm_req_history_info - History element structure
196  * @cm_id: Request id
197  * @add_time: Timestamp when the request was added to the list
198  * @del_time: Timestamp when the request was removed from list
199  * @add_cm_state: Conn_SM state when req was added
200  * @del_cm_state: Conn_SM state when req was deleted
201  * @del_type: Context in which delete was triggered. i.e active removal,
202  * pending removal or flush from queue.
203  */
204 struct cm_req_history_info {
205 	wlan_cm_id cm_id;
206 	uint64_t add_time;
207 	uint64_t del_time;
208 	enum wlan_cm_sm_state add_cm_state;
209 	enum wlan_cm_sm_state del_cm_state;
210 	enum cm_req_del_type del_type;
211 };
212 
213 /**
214  * struct cm_req_history - Connection manager history
215  * @cm_req_hist_lock: CM request history lock
216  * @index: Index of next entry that will be updated
217  * @data: Array of history element
218  */
219 struct cm_req_history {
220 	qdf_spinlock_t cm_req_hist_lock;
221 	uint8_t index;
222 	struct cm_req_history_info data[CM_REQ_HISTORY_SIZE];
223 };
224 #endif
225 
226 /**
227  * struct cnx_mgr - connect manager req
228  * @vdev: vdev back pointer
229  * @sm: state machine
230  * @active_cm_id: cm_id of the active command, if any active command present
231  * @preauth_in_progress: is roaming in preauth state, set during preauth state,
232  * this is used to get which command to flush from serialization during
233  * host roaming.
234  * @req_list: connect/disconnect req list
235  * @cm_req_lock: lock to manipulate/read the cm req list
236  * @disconnect_count: disconnect count
237  * @connect_count: connect count
238  * @force_rsne_override: if QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE is set by
239  * framework
240  * @global_cmd_id: global cmd id for getting cm id for connect/disconnect req
241  * @max_connect_attempts: Max attempts to be tried for a connect req
242  * @connect_timeout: Connect timeout value in milliseconds
243  * @scan_requester_id: scan requester id.
244  * @disconnect_complete: disconnect completion wait event
245  * @ext_cm_ptr: connection manager ext pointer
246  * @history: Holds the connection manager history
247  */
248 struct cnx_mgr {
249 	struct wlan_objmgr_vdev *vdev;
250 	struct cm_state_sm sm;
251 	wlan_cm_id active_cm_id;
252 	bool preauth_in_progress;
253 	qdf_list_t req_list;
254 #ifdef WLAN_CM_USE_SPINLOCK
255 	qdf_spinlock_t cm_req_lock;
256 #else
257 	qdf_mutex_t cm_req_lock;
258 #endif
259 	uint8_t disconnect_count;
260 	uint8_t connect_count;
261 	bool force_rsne_override;
262 	qdf_atomic_t global_cmd_id;
263 	uint8_t max_connect_attempts;
264 	uint32_t connect_timeout;
265 	wlan_scan_requester scan_requester_id;
266 	qdf_event_t disconnect_complete;
267 	cm_ext_t *ext_cm_ptr;
268 #ifdef SM_ENG_HIST_ENABLE
269 	struct cm_req_history req_history;
270 #endif
271 #ifndef CONN_MGR_ADV_FEATURE
272 	void (*cm_candidate_advance_filter)(struct wlan_objmgr_vdev *vdev,
273 					    struct scan_filter *filter);
274 	void (*cm_candidate_list_custom_sort)(struct wlan_objmgr_vdev *vdev,
275 					      qdf_list_t *list);
276 #endif
277 };
278 
279 /**
280  * wlan_cm_init() - Invoke connection manager init
281  * @vdev_mlme_obj:  VDEV MLME comp object
282  *
283  * API allocates CM and init
284  *
285  * Return: SUCCESS on successful allocation
286  *         FAILURE, if registration fails
287  */
288 QDF_STATUS wlan_cm_init(struct vdev_mlme_obj *vdev_mlme);
289 
290 /**
291  * wlan_cm_deinit() - Invoke connection manager deinit
292  * @vdev_mlme_obj:  VDEV MLME comp object
293  *
294  * API destroys CM
295  *
296  * Return: SUCCESS on successful deletion
297  *         FAILURE, if deletion fails
298  */
299 QDF_STATUS wlan_cm_deinit(struct vdev_mlme_obj *vdev_mlme);
300 #endif /* __WLAN_CM_MAIN_H__ */
301