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