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 * @CM_REQ_DEL_MAX: Maximum enumeration 187 */ 188 enum cm_req_del_type { 189 CM_REQ_DEL_ACTIVE, 190 CM_REQ_DEL_PENDING, 191 CM_REQ_DEL_FLUSH, 192 CM_REQ_DEL_MAX, 193 }; 194 195 #ifdef SM_ENG_HIST_ENABLE 196 197 #define CM_REQ_HISTORY_SIZE 30 198 199 /** 200 * struct cm_req_history_info - History element structure 201 * @cm_id: Request id 202 * @add_time: Timestamp when the request was added to the list 203 * @del_time: Timestamp when the request was removed from list 204 * @add_cm_state: Conn_SM state when req was added 205 * @del_cm_state: Conn_SM state when req was deleted 206 * @del_type: Context in which delete was triggered. i.e active removal, 207 * pending removal or flush from queue. 208 */ 209 struct cm_req_history_info { 210 wlan_cm_id cm_id; 211 uint64_t add_time; 212 uint64_t del_time; 213 enum wlan_cm_sm_state add_cm_state; 214 enum wlan_cm_sm_state del_cm_state; 215 enum cm_req_del_type del_type; 216 }; 217 218 /** 219 * struct cm_req_history - Connection manager history 220 * @cm_req_hist_lock: CM request history lock 221 * @index: Index of next entry that will be updated 222 * @data: Array of history element 223 */ 224 struct cm_req_history { 225 qdf_spinlock_t cm_req_hist_lock; 226 uint8_t index; 227 struct cm_req_history_info data[CM_REQ_HISTORY_SIZE]; 228 }; 229 #endif 230 231 /** 232 * struct cnx_mgr - connect manager req 233 * @vdev: vdev back pointer 234 * @sm: state machine 235 * @active_cm_id: cm_id of the active command, if any active command present 236 * @preauth_in_progress: is roaming in preauth state, set during preauth state, 237 * this is used to get which command to flush from serialization during 238 * host roaming. 239 * @req_list: connect/disconnect req list 240 * @cm_req_lock: lock to manipulate/read the cm req list 241 * @disconnect_count: disconnect count 242 * @connect_count: connect count 243 * @force_rsne_override: if QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE is set by 244 * framework 245 * @global_cmd_id: global cmd id for getting cm id for connect/disconnect req 246 * @max_connect_attempts: Max attempts to be tried for a connect req 247 * @connect_timeout: Connect timeout value in milliseconds 248 * @scan_requester_id: scan requester id. 249 * @disconnect_complete: disconnect completion wait event 250 * @ext_cm_ptr: connection manager ext pointer 251 * @req_history: Holds the connection manager history 252 * @cm_candidate_advance_filter: 253 * @cm_candidate_list_custom_sort: 254 */ 255 struct cnx_mgr { 256 struct wlan_objmgr_vdev *vdev; 257 struct cm_state_sm sm; 258 wlan_cm_id active_cm_id; 259 bool preauth_in_progress; 260 qdf_list_t req_list; 261 #ifdef WLAN_CM_USE_SPINLOCK 262 qdf_spinlock_t cm_req_lock; 263 #else 264 qdf_mutex_t cm_req_lock; 265 #endif 266 uint8_t disconnect_count; 267 uint8_t connect_count; 268 bool force_rsne_override; 269 qdf_atomic_t global_cmd_id; 270 uint8_t max_connect_attempts; 271 uint32_t connect_timeout; 272 wlan_scan_requester scan_requester_id; 273 qdf_event_t disconnect_complete; 274 cm_ext_t *ext_cm_ptr; 275 #ifdef SM_ENG_HIST_ENABLE 276 struct cm_req_history req_history; 277 #endif 278 #ifndef CONN_MGR_ADV_FEATURE 279 void (*cm_candidate_advance_filter)(struct wlan_objmgr_vdev *vdev, 280 struct scan_filter *filter); 281 void (*cm_candidate_list_custom_sort)(struct wlan_objmgr_vdev *vdev, 282 qdf_list_t *list); 283 #endif 284 }; 285 286 /** 287 * struct vdev_op_search_arg - vdev op search arguments 288 * @current_vdev_id: current vdev id 289 * @sap_go_vdev_id: sap/go vdev id 290 * @sta_cli_vdev_id: sta/p2p client vdev id 291 */ 292 struct vdev_op_search_arg { 293 uint8_t current_vdev_id; 294 uint8_t sap_go_vdev_id; 295 uint8_t sta_cli_vdev_id; 296 }; 297 298 /** 299 * wlan_cm_init() - Invoke connection manager init 300 * @vdev_mlme: VDEV MLME comp object 301 * 302 * API allocates CM and init 303 * 304 * Return: SUCCESS on successful allocation 305 * FAILURE, if registration fails 306 */ 307 QDF_STATUS wlan_cm_init(struct vdev_mlme_obj *vdev_mlme); 308 309 /** 310 * wlan_cm_deinit() - Invoke connection manager deinit 311 * @vdev_mlme: VDEV MLME comp object 312 * 313 * API destroys CM 314 * 315 * Return: SUCCESS on successful deletion 316 * FAILURE, if deletion fails 317 */ 318 QDF_STATUS wlan_cm_deinit(struct vdev_mlme_obj *vdev_mlme); 319 #endif /* __WLAN_CM_MAIN_H__ */ 320