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