1 /* 2 * Copyright (c) 2012-2015, 2020-2021, The Linux Foundation. All rights reserved. 3 * Copyright (c) 2022-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_main.h 20 * 21 * This header file maintain structures required for connection mgr core 22 */ 23 24 #ifndef __WLAN_CM_MAIN_H__ 25 #define __WLAN_CM_MAIN_H__ 26 27 #include "include/wlan_vdev_mlme.h" 28 #include <qdf_event.h> 29 #include <wlan_cm_public_struct.h> 30 31 /* Max candidate/attempts to be tried to connect */ 32 #define CM_MAX_CONNECT_ATTEMPTS 5 33 /* 34 * Default connect timeout to consider 3 sec join timeout + 5 sec auth timeout + 35 * 2 sec assoc timeout + 5 sec buffer for vdev related timeouts. 36 */ 37 #define CM_MAX_PER_CANDIDATE_CONNECT_TIMEOUT 15000 38 39 /* 40 * Default max retry attempts to be tried for a candidate. 41 * In SAE connection this value will be overwritten from the sae_connect_retries 42 * INI 43 */ 44 #define CM_MAX_CANDIDATE_RETRIES 1 45 /* Max time to wait for scan for SSID */ 46 #define CM_SCAN_MAX_TIME 5000 47 /* Max connect/disconnect/roam req that can be queued at a time */ 48 #define CM_MAX_REQ 5 49 50 /** 51 * enum wlan_cm_sm_state - Connection manager states 52 * @WLAN_CM_S_INIT: Default state, IDLE state 53 * @WLAN_CM_S_CONNECTING: State when connect request comes 54 * @WLAN_CM_S_CONNECTED: State when connect is complete 55 * @WLAN_CM_S_DISCONNECTING: State when disconnect request comes 56 * @WLAN_CM_S_ROAMING: State when roaming is in progress 57 * @WLAN_CM_S_MAX: Max State 58 * @WLAN_CM_SS_IDLE: Idle state (no substate) 59 * @WLAN_CM_SS_JOIN_PENDING: Connect request not serialized 60 * @WLAN_CM_SS_SCAN: Scan for SSID state 61 * @WLAN_CM_SS_JOIN_ACTIVE: Connect request activated 62 * @WLAN_CM_SS_PREAUTH: Roam substate of preauth stage 63 * @WLAN_CM_SS_REASSOC: Roam substate for reassoc state 64 * @WLAN_CM_SS_ROAM_STARTED: Roaming in progress (LFR 3.0) 65 * @WLAN_CM_SS_ROAM_SYNC: Roam sync indication from FW 66 * @WLAN_CM_SS_MAX: Max Substate 67 */ 68 enum wlan_cm_sm_state { 69 WLAN_CM_S_INIT = 0, 70 WLAN_CM_S_CONNECTING = 1, 71 WLAN_CM_S_CONNECTED = 2, 72 WLAN_CM_S_DISCONNECTING = 3, 73 WLAN_CM_S_ROAMING = 4, 74 WLAN_CM_S_MAX = 5, 75 WLAN_CM_SS_IDLE = 6, 76 WLAN_CM_SS_JOIN_PENDING = 7, 77 WLAN_CM_SS_SCAN = 8, 78 WLAN_CM_SS_JOIN_ACTIVE = 9, 79 WLAN_CM_SS_PREAUTH = 10, 80 WLAN_CM_SS_REASSOC = 11, 81 WLAN_CM_SS_ROAM_STARTED = 12, 82 WLAN_CM_SS_ROAM_SYNC = 13, 83 WLAN_CM_SS_MAX = 14, 84 }; 85 86 /** 87 * struct cm_state_sm - connection manager sm 88 * @cm_sm_lock: sm lock 89 * @sm_hdl: sm handlers 90 * @cm_state: current state 91 * @cm_substate: current substate 92 */ 93 struct cm_state_sm { 94 #ifdef WLAN_CM_USE_SPINLOCK 95 qdf_spinlock_t cm_sm_lock; 96 #else 97 qdf_mutex_t cm_sm_lock; 98 #endif 99 struct wlan_sm *sm_hdl; 100 enum wlan_cm_sm_state cm_state; 101 enum wlan_cm_sm_state cm_substate; 102 }; 103 104 /** 105 * struct cm_connect_req - connect req stored in connect manager 106 * @cm_id: Connect manager id 107 * @scan_id: scan id for scan for ssid 108 * @req: connect req from osif 109 * @candidate_list: candidate list 110 * @cur_candidate: current candidate 111 * @cur_candidate_retries: attempts for current candidate 112 * @connect_attempts: number of connect attempts tried 113 * @connect_active_time: timestamp when connect became active 114 * @first_candidate_rsp: connect response for first candidate 115 */ 116 struct cm_connect_req { 117 wlan_cm_id cm_id; 118 wlan_scan_id scan_id; 119 struct wlan_cm_connect_req req; 120 qdf_list_t *candidate_list; 121 struct scan_cache_node *cur_candidate; 122 uint8_t cur_candidate_retries; 123 uint8_t connect_attempts; 124 qdf_time_t connect_active_time; 125 #ifdef CONN_MGR_ADV_FEATURE 126 struct wlan_cm_connect_resp *first_candidate_rsp; 127 #endif 128 }; 129 130 /** 131 * struct cm_roam_req - roam req stored in connect manager 132 * @cm_id: Connect manager id 133 * @req: roam req from osif 134 * @candidate_list: candidate list 135 * @cur_candidate: current candidate 136 * @num_preauth_retry: retry times for the same candidate 137 */ 138 struct cm_roam_req { 139 wlan_cm_id cm_id; 140 struct wlan_cm_roam_req req; 141 qdf_list_t *candidate_list; 142 struct scan_cache_node *cur_candidate; 143 #ifdef WLAN_FEATURE_PREAUTH_ENABLE 144 uint8_t num_preauth_retry; 145 #endif 146 }; 147 148 /** 149 * struct cm_disconnect_req - disconnect req 150 * @cm_id: Connect manager id 151 * @req: disconnect connect req from osif 152 */ 153 struct cm_disconnect_req { 154 wlan_cm_id cm_id; 155 struct wlan_cm_disconnect_req req; 156 }; 157 158 /** 159 * struct cm_req - connect manager req 160 * @node: connection manager req node 161 * @cm_id: cm id 162 * @failed_req: set if req failed before serialization, 163 * with a commands pending before it, ie this is the latest command which failed 164 * but still some operation(req) is pending. 165 * @connect_req: connect req 166 * @discon_req: disconnect req 167 * @roam_req: roam req 168 */ 169 struct cm_req { 170 qdf_list_node_t node; 171 wlan_cm_id cm_id; 172 bool failed_req; 173 union { 174 struct cm_connect_req connect_req; 175 struct cm_disconnect_req discon_req; 176 struct cm_roam_req roam_req; 177 }; 178 }; 179 180 /** 181 * enum cm_req_del_type - Context in which a request is removed from 182 * connection manager request list 183 * @CM_REQ_DEL_ACTIVE: Remove request from active queue 184 * @CM_REQ_DEL_PENDING: Remove request from pending queue 185 * @CM_REQ_DEL_FLUSH: Request removed due to request list flush 186 */ 187 enum cm_req_del_type { 188 CM_REQ_DEL_ACTIVE, 189 CM_REQ_DEL_PENDING, 190 CM_REQ_DEL_FLUSH, 191 CM_REQ_DEL_MAX, 192 }; 193 194 #ifdef SM_ENG_HIST_ENABLE 195 196 #define CM_REQ_HISTORY_SIZE 30 197 198 /** 199 * struct cm_req_history_info - History element structure 200 * @cm_id: Request id 201 * @add_time: Timestamp when the request was added to the list 202 * @del_time: Timestamp when the request was removed from list 203 * @add_cm_state: Conn_SM state when req was added 204 * @del_cm_state: Conn_SM state when req was deleted 205 * @del_type: Context in which delete was triggered. i.e active removal, 206 * pending removal or flush from queue. 207 */ 208 struct cm_req_history_info { 209 wlan_cm_id cm_id; 210 uint64_t add_time; 211 uint64_t del_time; 212 enum wlan_cm_sm_state add_cm_state; 213 enum wlan_cm_sm_state del_cm_state; 214 enum cm_req_del_type del_type; 215 }; 216 217 /** 218 * struct cm_req_history - Connection manager history 219 * @cm_req_hist_lock: CM request history lock 220 * @index: Index of next entry that will be updated 221 * @data: Array of history element 222 */ 223 struct cm_req_history { 224 qdf_spinlock_t cm_req_hist_lock; 225 uint8_t index; 226 struct cm_req_history_info data[CM_REQ_HISTORY_SIZE]; 227 }; 228 #endif 229 230 /** 231 * struct cnx_mgr - connect manager req 232 * @vdev: vdev back pointer 233 * @sm: state machine 234 * @active_cm_id: cm_id of the active command, if any active command present 235 * @preauth_in_progress: is roaming in preauth state, set during preauth state, 236 * this is used to get which command to flush from serialization during 237 * host roaming. 238 * @req_list: connect/disconnect req list 239 * @cm_req_lock: lock to manipulate/read the cm req list 240 * @disconnect_count: disconnect count 241 * @connect_count: connect count 242 * @force_rsne_override: if QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE is set by 243 * framework 244 * @global_cmd_id: global cmd id for getting cm id for connect/disconnect req 245 * @max_connect_attempts: Max attempts to be tried for a connect req 246 * @connect_timeout: Connect timeout value in milliseconds 247 * @scan_requester_id: scan requester id. 248 * @disconnect_complete: disconnect completion wait event 249 * @ext_cm_ptr: connection manager ext pointer 250 * @history: Holds the connection manager history 251 */ 252 struct cnx_mgr { 253 struct wlan_objmgr_vdev *vdev; 254 struct cm_state_sm sm; 255 wlan_cm_id active_cm_id; 256 bool preauth_in_progress; 257 qdf_list_t req_list; 258 #ifdef WLAN_CM_USE_SPINLOCK 259 qdf_spinlock_t cm_req_lock; 260 #else 261 qdf_mutex_t cm_req_lock; 262 #endif 263 uint8_t disconnect_count; 264 uint8_t connect_count; 265 bool force_rsne_override; 266 qdf_atomic_t global_cmd_id; 267 uint8_t max_connect_attempts; 268 uint32_t connect_timeout; 269 wlan_scan_requester scan_requester_id; 270 qdf_event_t disconnect_complete; 271 cm_ext_t *ext_cm_ptr; 272 #ifdef SM_ENG_HIST_ENABLE 273 struct cm_req_history req_history; 274 #endif 275 #ifndef CONN_MGR_ADV_FEATURE 276 void (*cm_candidate_advance_filter)(struct wlan_objmgr_vdev *vdev, 277 struct scan_filter *filter); 278 void (*cm_candidate_list_custom_sort)(struct wlan_objmgr_vdev *vdev, 279 qdf_list_t *list); 280 #endif 281 }; 282 283 /** 284 * struct vdev_op_search_arg - vdev op search arguments 285 * @current_vdev_id: current vdev id 286 * @sap_go_vdev_id: sap/go vdev id 287 * @sta_cli_vdev_id: sta/p2p client vdev id 288 */ 289 struct vdev_op_search_arg { 290 uint8_t current_vdev_id; 291 uint8_t sap_go_vdev_id; 292 uint8_t sta_cli_vdev_id; 293 }; 294 295 /** 296 * wlan_cm_init() - Invoke connection manager init 297 * @vdev_mlme_obj: VDEV MLME comp object 298 * 299 * API allocates CM and init 300 * 301 * Return: SUCCESS on successful allocation 302 * FAILURE, if registration fails 303 */ 304 QDF_STATUS wlan_cm_init(struct vdev_mlme_obj *vdev_mlme); 305 306 /** 307 * wlan_cm_deinit() - Invoke connection manager deinit 308 * @vdev_mlme_obj: VDEV MLME comp object 309 * 310 * API destroys CM 311 * 312 * Return: SUCCESS on successful deletion 313 * FAILURE, if deletion fails 314 */ 315 QDF_STATUS wlan_cm_deinit(struct vdev_mlme_obj *vdev_mlme); 316 #endif /* __WLAN_CM_MAIN_H__ */ 317