xref: /wlan-dirver/qca-wifi-host-cmn/umac/mlme/connection_mgr/core/src/wlan_cm_sm.h (revision 8cfe6b10058a04cafb17eed051f2ddf11bee8931)
1 /*
2  * Copyright (c) 2012-2015,2020-2021 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2021-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_sm.h
20  *
21  * This header file maintain structures required for connection mgr sm infra
22  */
23 
24 #ifndef __WLAN_CM_SM_H__
25 #define __WLAN_CM_SM_H__
26 
27 #include <wlan_sm_engine.h>
28 
29 /**
30  * enum wlan_cm_sm_evt - connection manager related events
31  * Note: make sure to update cm_sm_event_names on updating this enum
32  * @WLAN_CM_SM_EV_CONNECT_REQ:            Connect request event from requester
33  * @WLAN_CM_SM_EV_SCAN:                   Event to start connect scan
34  * @WLAN_CM_SM_EV_SCAN_SUCCESS:           Connect scan success event
35  * @WLAN_CM_SM_EV_SCAN_FAILURE:           Connect scan fail event
36  * @WLAN_CM_SM_EV_HW_MODE_SUCCESS:        Hw mode change is success
37  * @WLAN_CM_SM_EV_HW_MODE_FAILURE:        Hw mode change is failure
38  * @WLAN_CM_SM_EV_CONNECT_START:          Connect start process initiate
39  * @WLAN_CM_SM_EV_CONNECT_ACTIVE:         Connect request is activated
40  * @WLAN_CM_SM_EV_CONNECT_SUCCESS:        Connect success
41  * @WLAN_CM_SM_EV_BSS_SELECT_IND_SUCCESS: Mlme resp for BSS select indication
42  * @WLAN_CM_SM_EV_BSS_CREATE_PEER_SUCCESS: BSS peer create success
43  * @WLAN_CM_SM_EV_CONNECT_GET_NEXT_CANDIDATE: Get next candidate for connection
44  * @WLAN_CM_SM_EV_CONNECT_FAILURE:        Connect failed for all candidate
45  * @WLAN_CM_SM_EV_DISCONNECT_REQ:         Disconnect request event from
46  * requester
47  * @WLAN_CM_SM_EV_DISCONNECT_START:       Start disconnect sequence
48  * @WLAN_CM_SM_EV_DISCONNECT_ACTIVE:      Process disconnect after in active cmd
49  * @WLAN_CM_SM_EV_DISCONNECT_DONE:        Disconnect done event
50  * @WLAN_CM_SM_EV_ROAM_START:             Roam start event for LFR2 and LFR3
51  * @WLAN_CM_SM_EV_ROAM_SYNC:              Roam sync event for LFR3
52  * @WLAN_CM_SM_EV_ROAM_INVOKE_FAIL:       Roam invoke fail event
53  * @WLAN_CM_SM_EV_ROAM_HO_FAIL:           Hands off failed event
54  * @WLAN_CM_SM_EV_PREAUTH_DONE:           Preauth is completed
55  * @WLAN_CM_SM_EV_GET_NEXT_PREAUTH_AP:    Get next candidate as preauth failed
56  * @WLAN_CM_SM_EV_PREAUTH_FAIL:           Preauth failed for all candidate
57  * @WLAN_CM_SM_EV_START_REASSOC:          Start reassoc after preauth done
58  * @WLAN_CM_SM_EV_REASSOC_ACTIVE:         Reassoc request activated
59  * @WLAN_CM_SM_EV_REASSOC_DONE:           Reassoc completed
60  * @WLAN_CM_SM_EV_REASSOC_FAILURE:        Reassoc failed
61  * @WLAN_CM_SM_EV_ROAM_COMPLETE:          Roaming completed
62  * @WLAN_CM_SM_EV_ROAM_REQ:               LFR3/FW roam - Roam req from connect
63  *                                        LFR2/Host roam - Roam req from host/FW
64  * @WLAN_CM_SM_EV_ROAM_INVOKE:            Host initiated LFR3/FW roam req
65  * @WLAN_CM_SM_EV_ROAM_ABORT:             Roam abort
66  * @WLAN_CM_SM_EV_ROAM_DONE:              Roam done
67  * @WLAN_CM_SM_EV_PREAUTH_ACTIVE:         Preauth active
68  * @WLAN_CM_SM_EV_PREAUTH_RESP:           Preauth response
69  * @WLAN_CM_SM_EV_REASSOC_TIMER:          Reassoc timer expired
70  * @WLAN_CM_SM_EV_HO_ROAM_DISCONNECT_DONE: Disconnect done for hands off/roaming
71  * @WLAN_CM_SM_EV_RSO_STOP_RSP:           Event to continue disconnect after
72  *                                        RSO stop response is received
73  * @WLAN_CM_SM_EV_MAX:                    Max event
74  */
75 enum wlan_cm_sm_evt {
76 	WLAN_CM_SM_EV_CONNECT_REQ = 0,
77 	WLAN_CM_SM_EV_SCAN = 1,
78 	WLAN_CM_SM_EV_SCAN_SUCCESS = 2,
79 	WLAN_CM_SM_EV_SCAN_FAILURE = 3,
80 	WLAN_CM_SM_EV_HW_MODE_SUCCESS = 4,
81 	WLAN_CM_SM_EV_HW_MODE_FAILURE = 5,
82 	WLAN_CM_SM_EV_CONNECT_START = 6,
83 	WLAN_CM_SM_EV_CONNECT_ACTIVE = 7,
84 	WLAN_CM_SM_EV_CONNECT_SUCCESS = 8,
85 	WLAN_CM_SM_EV_BSS_SELECT_IND_SUCCESS = 9,
86 	WLAN_CM_SM_EV_BSS_CREATE_PEER_SUCCESS = 10,
87 	WLAN_CM_SM_EV_CONNECT_GET_NEXT_CANDIDATE = 11,
88 	WLAN_CM_SM_EV_CONNECT_FAILURE = 12,
89 	WLAN_CM_SM_EV_DISCONNECT_REQ = 13,
90 	WLAN_CM_SM_EV_DISCONNECT_START = 14,
91 	WLAN_CM_SM_EV_DISCONNECT_ACTIVE = 15,
92 	WLAN_CM_SM_EV_DISCONNECT_DONE = 16,
93 	WLAN_CM_SM_EV_ROAM_START = 17,
94 	WLAN_CM_SM_EV_ROAM_SYNC = 18,
95 	WLAN_CM_SM_EV_ROAM_INVOKE_FAIL = 19,
96 	WLAN_CM_SM_EV_ROAM_HO_FAIL = 20,
97 	WLAN_CM_SM_EV_PREAUTH_DONE = 21,
98 	WLAN_CM_SM_EV_GET_NEXT_PREAUTH_AP = 22,
99 	WLAN_CM_SM_EV_PREAUTH_FAIL = 23,
100 	WLAN_CM_SM_EV_START_REASSOC = 24,
101 	WLAN_CM_SM_EV_REASSOC_ACTIVE = 25,
102 	WLAN_CM_SM_EV_REASSOC_DONE = 26,
103 	WLAN_CM_SM_EV_REASSOC_FAILURE = 27,
104 	WLAN_CM_SM_EV_ROAM_COMPLETE = 28,
105 	WLAN_CM_SM_EV_ROAM_REQ = 29,
106 	WLAN_CM_SM_EV_ROAM_INVOKE = 30,
107 	WLAN_CM_SM_EV_ROAM_ABORT = 31,
108 	WLAN_CM_SM_EV_ROAM_DONE = 32,
109 	WLAN_CM_SM_EV_PREAUTH_ACTIVE = 33,
110 	WLAN_CM_SM_EV_PREAUTH_RESP = 34,
111 	WLAN_CM_SM_EV_REASSOC_TIMER = 35,
112 	WLAN_CM_SM_EV_HO_ROAM_DISCONNECT_DONE = 36,
113 	WLAN_CM_SM_EV_RSO_STOP_RSP = 37,
114 	WLAN_CM_SM_EV_MAX,
115 };
116 
117 /**
118  * cm_sm_create() - Invoke SM creation for connection manager
119  * @cm_ctx:  connection manager ctx
120  *
121  * API allocates CM MLME SM and initializes SM lock
122  *
123  * Return: SUCCESS on successful allocation
124  *         FAILURE, if registration fails
125  */
126 QDF_STATUS cm_sm_create(struct cnx_mgr *cm_ctx);
127 
128 /**
129  * cm_sm_destroy() - Invoke SM deletion for connection manager
130  * @cm_ctx:  connection manager ctx
131  *
132  * API destroys CM MLME SM and SM lock
133  *
134  * Return: SUCCESS on successful deletion
135  *         FAILURE, if deletion fails
136  */
137 QDF_STATUS cm_sm_destroy(struct cnx_mgr *cm_ctx);
138 
139 /**
140  * cm_sm_history_print() - Prints SM history
141  * @vdev:  vdev object
142  *
143  * API to print CM SM history
144  *
145  * Return: void
146  */
147 #ifdef SM_ENG_HIST_ENABLE
148 void cm_sm_history_print(struct wlan_objmgr_vdev *vdev);
149 #else
150 static inline
151 void cm_sm_history_print(struct wlan_objmgr_vdev *vdev)
152 { }
153 #endif
154 
155 #ifdef WLAN_CM_USE_SPINLOCK
156 /**
157  * cm_lock_create() - Create CM SM mutex/spinlock
158  * @cm_ctx:  connection manager ctx
159  *
160  * Creates CM SM mutex/spinlock
161  *
162  * Return: void
163  */
164 static inline void
165 cm_lock_create(struct cnx_mgr *cm_ctx)
166 {
167 	qdf_spinlock_create(&cm_ctx->sm.cm_sm_lock);
168 }
169 
170 /**
171  * cm_lock_destroy() - Destroy CM SM mutex/spinlock
172  * @cm_ctx:  connection manager ctx
173  *
174  * Destroy CM SM mutex/spinlock
175  *
176  * Return: void
177  */
178 static inline void
179 cm_lock_destroy(struct cnx_mgr *cm_ctx)
180 {
181 	qdf_spinlock_destroy(&cm_ctx->sm.cm_sm_lock);
182 }
183 
184 /**
185  * cm_lock_acquire() - acquire CM SM mutex/spinlock
186  * @cm_ctx:  connection manager ctx
187  *
188  * acquire CM SM mutex/spinlock
189  *
190  * return: void
191  */
192 static inline void cm_lock_acquire(struct cnx_mgr *cm_ctx)
193 {
194 	qdf_spin_lock_bh(&cm_ctx->sm.cm_sm_lock);
195 }
196 
197 /**
198  * cm_lock_release() - release CM SM mutex/spinlock
199  * @cm_ctx:  connection manager ctx
200  *
201  * release CM SM mutex/spinlock
202  *
203  * return: void
204  */
205 static inline void cm_lock_release(struct cnx_mgr *cm_ctx)
206 {
207 	qdf_spin_unlock_bh(&cm_ctx->sm.cm_sm_lock);
208 }
209 #else
210 static inline void
211 cm_lock_create(struct cnx_mgr *cm_ctx)
212 {
213 	qdf_mutex_create(&cm_ctx->sm.cm_sm_lock);
214 }
215 
216 static inline void
217 cm_lock_destroy(struct cnx_mgr *cm_ctx)
218 {
219 	qdf_mutex_destroy(&cm_ctx->sm.cm_sm_lock);
220 }
221 
222 static inline void cm_lock_acquire(struct cnx_mgr *cm_ctx)
223 {
224 	qdf_mutex_acquire(&cm_ctx->sm.cm_sm_lock);
225 }
226 
227 static inline void cm_lock_release(struct cnx_mgr *cm_ctx)
228 {
229 	qdf_mutex_release(&cm_ctx->sm.cm_sm_lock);
230 }
231 #endif /* WLAN_CM_USE_SPINLOCK */
232 
233 /**
234  * cm_sm_transition_to() - invokes state transition
235  * @cm_ctx:  connection manager ctx
236  * @state: new cm state
237  *
238  * API to invoke SM API to move to new state
239  *
240  * Return: void
241  */
242 static inline void cm_sm_transition_to(struct cnx_mgr *cm_ctx,
243 				       enum wlan_cm_sm_state state)
244 {
245 	wlan_sm_transition_to(cm_ctx->sm.sm_hdl, state);
246 }
247 
248 /**
249  * cm_get_state() - get mlme state
250  * @cm_ctx: connection manager SM ctx
251  *
252  * API to get cm state
253  *
254  * Return: state of cm
255  */
256 enum wlan_cm_sm_state cm_get_state(struct cnx_mgr *cm_ctx);
257 
258 /**
259  * cm_get_sub_state() - get mlme substate
260  * @cm_ctx: connection manager SM ctx
261  *
262  * API to get cm substate
263  *
264  * Return: substate of cm
265  */
266 enum wlan_cm_sm_state cm_get_sub_state(struct cnx_mgr *cm_ctx);
267 
268 /**
269  * cm_set_state() - set cm mlme state
270  * @cm_ctx: connection manager SM ctx
271  * @state: cm state
272  *
273  * API to set cm state
274  *
275  * Return: void
276  */
277 void cm_set_state(struct cnx_mgr *cm_ctx, enum wlan_cm_sm_state state);
278 
279 /**
280  * cm_set_substate() - set cm mlme sub state
281  * @cm_ctx: connection manager SM ctx
282  * @substate: cm sub state
283  *
284  * API to set cm sub state
285  *
286  * Return: void
287  */
288 void cm_set_substate(struct cnx_mgr *cm_ctx,
289 		     enum wlan_cm_sm_state substate);
290 
291 /**
292  * cm_sm_state_update() - set cm mlme state and sub state
293  * @cm_ctx: connection manager SM ctx
294  * @state: cm state
295  * @substate: cm sub state
296  *
297  * API to invoke util APIs to set state and MLME sub state
298  *
299  * Return: void
300  */
301 void cm_sm_state_update(struct cnx_mgr *cm_ctx,
302 			enum wlan_cm_sm_state state,
303 			enum wlan_cm_sm_state substate);
304 
305 /**
306  * cm_sm_deliver_event_sync() - Delivers event to connection manager SM while
307  * holding lock
308  * @cm_ctx: cm ctx
309  * @event: CM event
310  * @data_len: data size
311  * @data: event data
312  *
313  * API to dispatch event to VDEV MLME SM without lock, in case lock is already
314  * held.
315  *
316  * Context: Can be called from any context, This should be called in case
317  * SM lock is already taken. If lock is not taken use cm_sm_deliver_event API
318  * instead.
319  *
320  * Return: SUCCESS: on handling event
321  *         FAILURE: If event not handled
322  */
323 static inline
324 QDF_STATUS cm_sm_deliver_event_sync(struct cnx_mgr *cm_ctx,
325 				    enum wlan_cm_sm_evt event,
326 				    uint16_t data_len, void *data)
327 {
328 	return wlan_sm_dispatch(cm_ctx->sm.sm_hdl, event, data_len, data);
329 }
330 
331 /**
332  * cm_sm_deliver_event() - Delivers event to connection manager SM
333  * @vdev: Object manager VDEV object
334  * @event: CM event
335  * @data_len: data size
336  * @data: event data
337  *
338  * API to dispatch event to VDEV MLME SM with lock. To be used while posting
339  * events from API called from public API. i.e. indication/response/request
340  * from any other module or NB/SB req/resp.
341  *
342  * Context: Can be called from any context, This should be called in case
343  * SM lock is not taken, the API will take the lock before posting to SM.
344  * If lock is already taken use cm_sm_deliver_event_sync API instead.
345  *
346  * Return: SUCCESS: on handling event
347  *         FAILURE: If event not handled
348  */
349 QDF_STATUS  cm_sm_deliver_event(struct wlan_objmgr_vdev *vdev,
350 				enum wlan_cm_sm_evt event,
351 				uint16_t data_len, void *data);
352 
353 /**
354  * cm_fill_vdev_crypto_params() - Update the vdev crypto params
355  * from the connect req structure
356  * @cm_ctx: connection manager SM ctx
357  * @req: connect request structure
358  *
359  * Return: void
360  */
361 void cm_fill_vdev_crypto_params(struct cnx_mgr *cm_ctx,
362 				struct wlan_cm_connect_req *req);
363 #endif /* __WLAN_CM_SM_H__ */
364