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