1 /* 2 * Copyright (c) 2012-2015,2020-2021 The Linux Foundation. All rights reserved. 3 * Copyright (c) 2021 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_MAX: Max event 72 */ 73 enum wlan_cm_sm_evt { 74 WLAN_CM_SM_EV_CONNECT_REQ = 0, 75 WLAN_CM_SM_EV_SCAN = 1, 76 WLAN_CM_SM_EV_SCAN_SUCCESS = 2, 77 WLAN_CM_SM_EV_SCAN_FAILURE = 3, 78 WLAN_CM_SM_EV_HW_MODE_SUCCESS = 4, 79 WLAN_CM_SM_EV_HW_MODE_FAILURE = 5, 80 WLAN_CM_SM_EV_CONNECT_START = 6, 81 WLAN_CM_SM_EV_CONNECT_ACTIVE = 7, 82 WLAN_CM_SM_EV_CONNECT_SUCCESS = 8, 83 WLAN_CM_SM_EV_BSS_SELECT_IND_SUCCESS = 9, 84 WLAN_CM_SM_EV_BSS_CREATE_PEER_SUCCESS = 10, 85 WLAN_CM_SM_EV_CONNECT_GET_NEXT_CANDIDATE = 11, 86 WLAN_CM_SM_EV_CONNECT_FAILURE = 12, 87 WLAN_CM_SM_EV_DISCONNECT_REQ = 13, 88 WLAN_CM_SM_EV_DISCONNECT_START = 14, 89 WLAN_CM_SM_EV_DISCONNECT_ACTIVE = 15, 90 WLAN_CM_SM_EV_DISCONNECT_DONE = 16, 91 WLAN_CM_SM_EV_ROAM_START = 17, 92 WLAN_CM_SM_EV_ROAM_SYNC = 18, 93 WLAN_CM_SM_EV_ROAM_INVOKE_FAIL = 19, 94 WLAN_CM_SM_EV_ROAM_HO_FAIL = 20, 95 WLAN_CM_SM_EV_PREAUTH_DONE = 21, 96 WLAN_CM_SM_EV_GET_NEXT_PREAUTH_AP = 22, 97 WLAN_CM_SM_EV_PREAUTH_FAIL = 23, 98 WLAN_CM_SM_EV_START_REASSOC = 24, 99 WLAN_CM_SM_EV_REASSOC_ACTIVE = 25, 100 WLAN_CM_SM_EV_REASSOC_DONE = 26, 101 WLAN_CM_SM_EV_REASSOC_FAILURE = 27, 102 WLAN_CM_SM_EV_ROAM_COMPLETE = 28, 103 WLAN_CM_SM_EV_ROAM_REQ = 29, 104 WLAN_CM_SM_EV_ROAM_INVOKE = 30, 105 WLAN_CM_SM_EV_ROAM_ABORT = 31, 106 WLAN_CM_SM_EV_ROAM_DONE = 32, 107 WLAN_CM_SM_EV_PREAUTH_ACTIVE = 33, 108 WLAN_CM_SM_EV_PREAUTH_RESP = 34, 109 WLAN_CM_SM_EV_REASSOC_TIMER = 35, 110 WLAN_CM_SM_EV_HO_ROAM_DISCONNECT_DONE = 36, 111 WLAN_CM_SM_EV_MAX, 112 }; 113 114 /** 115 * cm_sm_create() - Invoke SM creation for connection manager 116 * @cm_ctx: connection manager ctx 117 * 118 * API allocates CM MLME SM and initializes SM lock 119 * 120 * Return: SUCCESS on successful allocation 121 * FAILURE, if registration fails 122 */ 123 QDF_STATUS cm_sm_create(struct cnx_mgr *cm_ctx); 124 125 /** 126 * cm_sm_destroy() - Invoke SM deletion for connection manager 127 * @cm_ctx: connection manager ctx 128 * 129 * API destroys CM MLME SM and SM lock 130 * 131 * Return: SUCCESS on successful deletion 132 * FAILURE, if deletion fails 133 */ 134 QDF_STATUS cm_sm_destroy(struct cnx_mgr *cm_ctx); 135 136 /** 137 * cm_sm_history_print() - Prints SM history 138 * @cm_ctx: connection manager ctx 139 * 140 * API to print CM SM history 141 * 142 * Return: void 143 */ 144 #ifdef SM_ENG_HIST_ENABLE 145 void cm_sm_history_print(struct wlan_objmgr_vdev *vdev); 146 #else 147 static inline 148 void cm_sm_history_print(struct wlan_objmgr_vdev *vdev) 149 { } 150 #endif 151 152 #ifdef WLAN_CM_USE_SPINLOCK 153 /** 154 * cm_lock_create - Create CM SM mutex/spinlock 155 * @cm_ctx: connection manager ctx 156 * 157 * Creates CM SM mutex/spinlock 158 * 159 * Return: void 160 */ 161 static inline void 162 cm_lock_create(struct cnx_mgr *cm_ctx) 163 { 164 qdf_spinlock_create(&cm_ctx->sm.cm_sm_lock); 165 } 166 167 /** 168 * cm_lock_destroy - Destroy CM SM mutex/spinlock 169 * @cm_ctx: connection manager ctx 170 * 171 * Destroy CM SM mutex/spinlock 172 * 173 * Return: void 174 */ 175 static inline void 176 cm_lock_destroy(struct cnx_mgr *cm_ctx) 177 { 178 qdf_spinlock_destroy(&cm_ctx->sm.cm_sm_lock); 179 } 180 181 /** 182 * cm_lock_acquire - acquire CM SM mutex/spinlock 183 * @cm_ctx: connection manager ctx 184 * 185 * acquire CM SM mutex/spinlock 186 * 187 * return: void 188 */ 189 static inline void cm_lock_acquire(struct cnx_mgr *cm_ctx) 190 { 191 qdf_spin_lock_bh(&cm_ctx->sm.cm_sm_lock); 192 } 193 194 /** 195 * cm_lock_release - release CM SM mutex/spinlock 196 * @cm_ctx: connection manager ctx 197 * 198 * release CM SM mutex/spinlock 199 * 200 * return: void 201 */ 202 static inline void cm_lock_release(struct cnx_mgr *cm_ctx) 203 { 204 qdf_spin_unlock_bh(&cm_ctx->sm.cm_sm_lock); 205 } 206 #else 207 static inline void 208 cm_lock_create(struct cnx_mgr *cm_ctx) 209 { 210 qdf_mutex_create(&cm_ctx->sm.cm_sm_lock); 211 } 212 213 static inline void 214 cm_lock_destroy(struct cnx_mgr *cm_ctx) 215 { 216 qdf_mutex_destroy(&cm_ctx->sm.cm_sm_lock); 217 } 218 219 static inline void cm_lock_acquire(struct cnx_mgr *cm_ctx) 220 { 221 qdf_mutex_acquire(&cm_ctx->sm.cm_sm_lock); 222 } 223 224 static inline void cm_lock_release(struct cnx_mgr *cm_ctx) 225 { 226 qdf_mutex_release(&cm_ctx->sm.cm_sm_lock); 227 } 228 #endif /* WLAN_CM_USE_SPINLOCK */ 229 230 /** 231 * cm_sm_transition_to() - invokes state transition 232 * @cm_ctx: connection manager ctx 233 * @state: new cm state 234 * 235 * API to invoke SM API to move to new state 236 * 237 * Return: void 238 */ 239 static inline void cm_sm_transition_to(struct cnx_mgr *cm_ctx, 240 enum wlan_cm_sm_state state) 241 { 242 wlan_sm_transition_to(cm_ctx->sm.sm_hdl, state); 243 } 244 245 /** 246 * cm_get_state() - get mlme state 247 * @cm_ctx: connection manager SM ctx 248 * 249 * API to get cm state 250 * 251 * Return: state of cm 252 */ 253 enum wlan_cm_sm_state cm_get_state(struct cnx_mgr *cm_ctx); 254 255 /** 256 * cm_get_sub_state() - get mlme substate 257 * @cm_ctx: connection manager SM ctx 258 * 259 * API to get cm substate 260 * 261 * Return: substate of cm 262 */ 263 enum wlan_cm_sm_state cm_get_sub_state(struct cnx_mgr *cm_ctx); 264 265 /** 266 * cm_set_state() - set cm mlme state 267 * @cm_ctx: connection manager SM ctx 268 * @state: cm state 269 * 270 * API to set cm state 271 * 272 * Return: void 273 */ 274 void cm_set_state(struct cnx_mgr *cm_ctx, enum wlan_cm_sm_state state); 275 /** 276 * cm_set_substate() - set cm mlme sub state 277 * @cm_ctx: connection manager SM ctx 278 * @substate: cm sub state 279 * 280 * API to set cm sub state 281 * 282 * Return: void 283 */ 284 void cm_set_substate(struct cnx_mgr *cm_ctx, 285 enum wlan_cm_sm_state substate); 286 287 /** 288 * cm_sm_state_update() - set cm mlme state and sub state 289 * @cm_ctx: connection manager SM ctx 290 * @state: cm state 291 * @substate: cm sub state 292 * 293 * API to invoke util APIs to set state and MLME sub state 294 * 295 * Return: void 296 */ 297 void cm_sm_state_update(struct cnx_mgr *cm_ctx, 298 enum wlan_cm_sm_state state, 299 enum wlan_cm_sm_state substate); 300 301 /** 302 * cm_sm_deliver_event_sync() - Delivers event to connection manager SM while 303 * holding lock 304 * @cm_ctx: cm ctx 305 * @event: CM event 306 * @data_len: data size 307 * @data: event data 308 * 309 * API to dispatch event to VDEV MLME SM without lock, in case lock is already 310 * held. 311 * 312 * Context: Can be called from any context, This should be called in case 313 * SM lock is already taken. If lock is not taken use cm_sm_deliver_event API 314 * instead. 315 * 316 * Return: SUCCESS: on handling event 317 * FAILURE: If event not handled 318 */ 319 static inline 320 QDF_STATUS cm_sm_deliver_event_sync(struct cnx_mgr *cm_ctx, 321 enum wlan_cm_sm_evt event, 322 uint16_t data_len, void *data) 323 { 324 return wlan_sm_dispatch(cm_ctx->sm.sm_hdl, event, data_len, data); 325 } 326 327 /** 328 * cm_sm_deliver_event() - Delivers event to connection manager SM 329 * @vdev: Object manager VDEV object 330 * @event: CM event 331 * @data_len: data size 332 * @data: event data 333 * 334 * API to dispatch event to VDEV MLME SM with lock. To be used while paosting 335 * events from API called from publick API. i.e. indication/response/request 336 * from any other moudle or NB/SB. 337 * 338 * Context: Can be called from any context, This should be called in case 339 * SM lock is not taken, the API will take the lock before posting to SM. 340 * If lock is already taken use cm_sm_deliver_event_sync API instead. 341 * 342 * Return: SUCCESS: on handling event 343 * FAILURE: If event not handled 344 */ 345 QDF_STATUS cm_sm_deliver_event(struct wlan_objmgr_vdev *vdev, 346 enum wlan_cm_sm_evt event, 347 uint16_t data_len, void *data); 348 349 /** 350 * cm_fill_vdev_crypto_params() - Update the vdev crypto params 351 * from the connect req structure 352 * @cm_ctx: connection manager SM ctx 353 * @req: connect request structure 354 * 355 * Return: void 356 */ 357 void cm_fill_vdev_crypto_params(struct cnx_mgr *cm_ctx, 358 struct wlan_cm_connect_req *req); 359 #endif /* __WLAN_CM_SM_H__ */ 360