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