xref: /wlan-dirver/qcacld-3.0/core/sap/src/sap_internal.h (revision d1eb296939c4184ce7e8a921bf6ffe874f574400)
1 /*
2  * Copyright (c) 2012-2021 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for
6  * any purpose with or without fee is hereby granted, provided that the
7  * above copyright notice and this permission notice appear in all
8  * copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17  * PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #ifndef WLAN_QCT_WLANSAP_INTERNAL_H
21 #define WLAN_QCT_WLANSAP_INTERNAL_H
22 
23 /*
24  * This file contains the internal API exposed by the wlan SAP PAL layer
25  * module.
26  */
27 
28 #include "cds_api.h"
29 #include "cds_packet.h"
30 
31 /* Pick up the CSR API definitions */
32 #include "csr_api.h"
33 #include "sap_api.h"
34 #include "sap_fsm_ext.h"
35 #include "sap_ch_select.h"
36 #include <wlan_scan_public_structs.h>
37 #include <wlan_objmgr_pdev_obj.h>
38 #include "wlan_vdev_mlme_main.h"
39 #include "wlan_vdev_mlme_api.h"
40 
41 /* DFS Non Occupancy Period =30 minutes, in microseconds */
42 #define SAP_DFS_NON_OCCUPANCY_PERIOD      (30 * 60 * 1000 * 1000)
43 
44 #define SAP_DEBUG
45 
46 #define IS_ETSI_WEATHER_FREQ(_freq)   ((_freq >= 5600) && (_freq <= 5650))
47 #define IS_CH_BONDING_WITH_WEATHER_CH(_ch)   (_ch == 116)
48 #define IS_CHAN_JAPAN_INDOOR(_ch) ((_ch >= 36)  && (_ch <= 64))
49 #define IS_CHAN_JAPAN_OUTDOOR(_ch)((_ch >= 100) && (_ch <= 140))
50 #define DEFAULT_CAC_TIMEOUT (60 * 1000) /* msecs - 1 min */
51 #define ETSI_WEATHER_CH_CAC_TIMEOUT (10 * 60 * 1000)    /* msecs - 10 min */
52 #define SAP_CHAN_PREFERRED_INDOOR  1
53 #define SAP_CHAN_PREFERRED_OUTDOOR 2
54 
55 /*SAP Specific logging*/
56 
57 #define sap_alert(params...) QDF_TRACE_FATAL(QDF_MODULE_ID_SAP, params)
58 #define sap_err(params...) QDF_TRACE_ERROR(QDF_MODULE_ID_SAP, params)
59 #define sap_warn(params...) QDF_TRACE_WARN(QDF_MODULE_ID_SAP, params)
60 #define sap_info(params...) QDF_TRACE_INFO(QDF_MODULE_ID_SAP, params)
61 #define sap_debug(params...) QDF_TRACE_DEBUG(QDF_MODULE_ID_SAP, params)
62 
63 #define sap_nofl_alert(params...) \
64 	QDF_TRACE_FATAL_NO_FL(QDF_MODULE_ID_SAP, params)
65 #define sap_nofl_err(params...) \
66 	QDF_TRACE_ERROR_NO_FL(QDF_MODULE_ID_SAP, params)
67 #define sap_nofl_warn(params...) \
68 	QDF_TRACE_WARN_NO_FL(QDF_MODULE_ID_SAP, params)
69 #define sap_nofl_info(params...) \
70 	QDF_TRACE_INFO_NO_FL(QDF_MODULE_ID_SAP, params)
71 #define sap_nofl_debug(params...) \
72 	QDF_TRACE_DEBUG_NO_FL(QDF_MODULE_ID_SAP, params)
73 
74 #define sap_alert_rl(params...) QDF_TRACE_FATAL_RL(QDF_MODULE_ID_SAP, params)
75 #define sap_err_rl(params...) QDF_TRACE_ERROR_RL(QDF_MODULE_ID_SAP, params)
76 #define sap_warn_rl(params...) QDF_TRACE_WARN_RL(QDF_MODULE_ID_SAP, params)
77 #define sap_info_rl(params...) QDF_TRACE_INFO_RL(QDF_MODULE_ID_SAP, params)
78 #define sap_debug_rl(params...) QDF_TRACE_DEBUG_RL(QDF_MODULE_ID_SAP, params)
79 
80 /*----------------------------------------------------------------------------
81  *  Typedefs
82  * -------------------------------------------------------------------------*/
83 /*----------------------------------------------------------------------------
84  *  Type Declarations - For internal SAP context information
85  * -------------------------------------------------------------------------*/
86 /*----------------------------------------------------------------------------
87  *  Opaque SAP context Type Declaration
88  * -------------------------------------------------------------------------*/
89 /* We were only using this syntax, when this was truly opaque. */
90 /* (I.E., it was defined in a different file.) */
91 
92 /**
93  * enum sap_fsm_state - SAP FSM states for Access Point role
94  * @SAP_INIT: init state
95  * @SAP_STARTING: starting phase
96  * @SAP_STARTED: up and running
97  * @SAP_STOPPING: about to stop and transitions to init
98  */
99 enum sap_fsm_state {
100 	SAP_INIT,
101 	SAP_STARTING,
102 	SAP_STARTED,
103 	SAP_STOPPING
104 };
105 
106 #ifdef FEATURE_AP_MCC_CH_AVOIDANCE
107 /*
108  * In a setup having two MDM both operating in AP+AP MCC scenario
109  * if both the AP decides to use same or close channel set, CTS to
110  * self, mechanism is causing issues with connectivity. For this, its
111  * proposed that 2nd MDM devices which comes up later should detect
112  * presence of first MDM device via special Q2Q IE present in becon
113  * and avoid those channels mentioned in IE.
114  *
115  * Following struct will keep this info in sapCtx struct, and will be used
116  * to avoid such channels in Random Channel Select in case of radar ind.
117  */
118 struct sap_avoid_channels_info {
119 	bool       present;
120 	uint8_t    channels[CFG_VALID_CHANNEL_LIST_LEN];
121 };
122 #endif /* FEATURE_AP_MCC_CH_AVOIDANCE */
123 
124 struct sap_context {
125 
126 	/* Include the current channel frequency of AP */
127 	uint32_t chan_freq;
128 	uint32_t sec_ch_freq;
129 
130 #ifdef DCS_INTERFERENCE_DETECTION
131 	qdf_freq_t dcs_ch_freq;
132 #endif
133 
134 	/* Include the SME(CSR) sessionId here */
135 	uint8_t sessionId;
136 
137 	/* vdev object corresponding to sessionId */
138 	struct wlan_objmgr_vdev *vdev;
139 
140 	/* Include the associations MAC addresses */
141 	uint8_t self_mac_addr[CDS_MAC_ADDRESS_LEN];
142 	struct start_bss_config sap_bss_cfg;
143 
144 	/* SAP event Callback to hdd */
145 	sap_event_cb sap_event_cb;
146 
147 	/*
148 	 * Include the state machine structure here, state var that keeps
149 	 * track of state machine
150 	 */
151 	enum sap_fsm_state fsm_state;
152 	enum sap_csa_reason_code csa_reason;
153 
154 	/* Actual storage for AP and self (STA) SSID */
155 	tCsrSSIDInfo SSIDList[2];
156 
157 	/* Actual storage for AP bssid */
158 	struct qdf_mac_addr bssid;
159 
160 	/* Mac filtering settings */
161 	eSapMacAddrACL eSapMacAddrAclMode;
162 	struct qdf_mac_addr acceptMacList[MAX_ACL_MAC_ADDRESS];
163 	uint16_t nAcceptMac;
164 	struct qdf_mac_addr denyMacList[MAX_ACL_MAC_ADDRESS];
165 	uint16_t nDenyMac;
166 
167 	void *user_context;
168 
169 	uint32_t nStaWPARSnReqIeLength;
170 	uint8_t pStaWpaRsnReqIE[MAX_ASSOC_IND_IE_LEN];
171 
172 	eCsrPhyMode phyMode;
173 	uint32_t *freq_list;
174 	uint8_t num_of_channel;
175 	uint16_t ch_width_orig;
176 	struct ch_params ch_params;
177 	uint32_t chan_freq_before_switch_band;
178 	enum phy_ch_width chan_width_before_switch_band;
179 	uint32_t auto_channel_select_weight;
180 	bool enableOverLapCh;
181 	struct sap_acs_cfg *acs_cfg;
182 
183 	qdf_time_t acs_req_timestamp;
184 
185 #ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
186 	uint8_t cc_switch_mode;
187 #endif
188 
189 #if defined(FEATURE_WLAN_STA_AP_MODE_DFS_DISABLE)
190 	bool dfs_ch_disable;
191 #endif
192 	bool isCacEndNotified;
193 	bool isCacStartNotified;
194 	bool is_sap_ready_for_chnl_chng;
195 #ifdef FEATURE_RADAR_HISTORY
196 	struct prev_cac_result cac_result;
197 #endif
198 #ifdef FEATURE_AP_MCC_CH_AVOIDANCE
199 	/*
200 	 * In a setup having two MDM both operating in AP+AP MCC scenario
201 	 * if both the AP decides to use same or close channel set, CTS to
202 	 * self, mechanism is causing issues with connectivity. For this, its
203 	 * proposed that 2nd MDM devices which comes up later should detect
204 	 * presence of first MDM device via special Q2Q IE present in becon
205 	 * and avoid those channels mentioned in IE.
206 	 *
207 	 * this struct contains the list of channels on which another MDM AP
208 	 * in MCC mode were detected.
209 	 */
210 	struct sap_avoid_channels_info sap_detected_avoid_ch_ie;
211 #endif /* FEATURE_AP_MCC_CH_AVOIDANCE */
212 	/*
213 	 * sap_state, sap_status are created
214 	 * to inform upper layers about ACS scan status.
215 	 * Don't use these members for any other purposes.
216 	 */
217 	eSapHddEvent sap_state;
218 	eSapStatus sap_status;
219 	uint32_t roc_ind_scan_id;
220 	bool vendor_acs_dfs_lte_enabled;
221 	uint8_t dfs_vendor_channel;
222 	uint8_t dfs_vendor_chan_bw;
223 	uint16_t beacon_tx_rate;
224 	enum sap_acs_dfs_mode dfs_mode;
225 	wlan_scan_requester req_id;
226 	uint8_t sap_sta_id;
227 	bool dfs_cac_offload;
228 	bool is_chan_change_inprogress;
229 	/* Disabled mcs13 by sap or not */
230 	bool disabled_mcs13;
231 	qdf_list_t owe_pending_assoc_ind_list;
232 	uint32_t freq_before_ch_switch;
233 #ifdef WLAN_FEATURE_P2P_P2P_STA
234 /*
235  *This param is used for GO+GO force scc logic where after
236  *setkey first GO will move to latest GO's channel
237  */
238 	bool is_forcescc_restart_required;
239 #endif
240 	qdf_freq_t candidate_freq;
241 #ifdef FEATURE_WLAN_CH_AVOID_EXT
242 	uint32_t restriction_mask;
243 #endif
244 	bool require_h2e;
245 	bool partial_acs_scan;
246 	bool optimize_acs_chan_selected;
247 };
248 
249 /*----------------------------------------------------------------------------
250  *  External declarations for global context
251  * -------------------------------------------------------------------------*/
252 
253 /**
254  * struct sap_sm_event - SAP state machine event definition
255  * @params: A VOID pointer type for all possible inputs
256  * @event: State machine input event message
257  * @u1: Introduced to handle csr_roam_complete_cb roamStatus
258  * @u2: Introduced to handle csr_roam_complete_cb roamResult
259  */
260 struct sap_sm_event {
261 	void *params;
262 	uint32_t event;
263 	uint32_t u1;
264 	uint32_t u2;
265 };
266 
267 /*----------------------------------------------------------------------------
268  * Function Declarations and Documentation
269  * -------------------------------------------------------------------------*/
270 
271 /**
272  * sap_get_mac_context() - Get a pointer to the global MAC context
273  *
274  * Return: pointer to the global MAC context, or NULL if the MAC
275  *         context is no longer registered
276  */
277 static inline struct mac_context *sap_get_mac_context(void)
278 {
279 	return cds_get_context(QDF_MODULE_ID_PE);
280 }
281 
282 QDF_STATUS wlansap_context_get(struct sap_context *ctx);
283 void wlansap_context_put(struct sap_context *ctx);
284 
285 /**
286  * wlansap_pre_start_bss_acs_scan_callback() - callback for scan results
287  * @mac_handle:    the mac_handle passed in with the scan request
288  * @sap_ctx:       the SAP context pointer.
289  * @scanid:        scan id passed
290  * @sessionid:     session identifier
291  * @scan_status:        status of scan -success, failure or abort
292  *
293  * Api for scan callback. This function is invoked as a result of scan
294  * completion and reports the scan results.
295  *
296  * Return: The QDF_STATUS code associated with performing the operation
297  */
298 QDF_STATUS wlansap_pre_start_bss_acs_scan_callback(mac_handle_t mac_handle,
299 						   struct sap_context *sap_ctx,
300 						   uint8_t sessionid,
301 						   uint32_t scanid,
302 						   eCsrScanStatus scan_status);
303 
304 /**
305  * sap_select_channel() - select SAP channel
306  * @mac_handle: Opaque handle to the global MAC context
307  * @sap_ctx: Sap context
308  * @scan_list: scan entry list
309  *
310  * Runs a algorithm to select the best channel to operate in based on BSS
311  * rssi and bss count on each channel
312  *
313  * Returns: channel frequency if success, 0 otherwise
314  */
315 uint32_t sap_select_channel(mac_handle_t mac_handle, struct sap_context *sap_ctx,
316 			   qdf_list_t *scan_list);
317 
318 QDF_STATUS
319 sap_signal_hdd_event(struct sap_context *sap_ctx,
320 		  struct csr_roam_info *pCsrRoamInfo,
321 		  eSapHddEvent sapHddevent, void *);
322 
323 QDF_STATUS sap_fsm(struct sap_context *sap_ctx, struct sap_sm_event *sap_event);
324 
325 QDF_STATUS
326 sap_is_peer_mac_allowed(struct sap_context *sap_ctx, uint8_t *peerMac);
327 
328 void
329 sap_sort_mac_list(struct qdf_mac_addr *macList, uint16_t size);
330 
331 void
332 sap_add_mac_to_acl(struct qdf_mac_addr *macList, uint16_t *size,
333 		   uint8_t *peerMac);
334 
335 void
336 sap_remove_mac_from_acl(struct qdf_mac_addr *macList, uint16_t *size,
337 			uint16_t index);
338 
339 void
340 sap_print_acl(struct qdf_mac_addr *macList, uint16_t size);
341 
342 bool
343 sap_search_mac_list(struct qdf_mac_addr *macList, uint16_t num_mac,
344 		    uint8_t *peerMac, uint16_t *index);
345 
346 QDF_STATUS sap_init_dfs_channel_nol_list(struct sap_context *sap_ctx);
347 
348 bool sap_dfs_is_channel_in_nol_list(struct sap_context *sap_ctx,
349 				    qdf_freq_t chan_freq,
350 				    ePhyChanBondState chanBondState);
351 void sap_dfs_cac_timer_callback(void *data);
352 
353 /**
354  * sap_cac_reset_notify() - BSS cleanup notification handler
355  * @mac_handle: Opaque handle to the global MAC context
356  *
357  * This function should be called upon stop bss indication to clean up
358  * DFS global structure.
359  */
360 void sap_cac_reset_notify(mac_handle_t mac_handle);
361 
362 bool is_concurrent_sap_ready_for_channel_change(mac_handle_t mac_handle,
363 						struct sap_context *sap_ctx);
364 
365 bool sap_is_conc_sap_doing_scc_dfs(mac_handle_t mac_handle,
366 				   struct sap_context *given_sapctx);
367 
368 uint8_t sap_get_total_number_sap_intf(mac_handle_t mac_handle);
369 
370 /**
371  * sap_channel_sel - Function for initiating scan request for ACS
372  * @sap_context: Sap Context value.
373  *
374  * Initiates Scan for ACS to pick a channel.
375  *
376  * Return: The QDF_STATUS code associated with performing the operation.
377  */
378 QDF_STATUS sap_channel_sel(struct sap_context *sap_ctx);
379 
380 /**
381  * sap_validate_chan - Function validate the channel and forces SCC
382  * @sap_context: Sap Context value.
383  * @pre_start_bss: if its called pre start BSS with valid channel.
384  * @check_for_connection_update: true, check and wait for connection update
385  *				 false, do not perform connection update
386  *
387  * validate and update the channel in case of force SCC.
388  *
389  * Return: The QDF_STATUS code associated with performing the operation.
390  */
391 QDF_STATUS
392 sap_validate_chan(struct sap_context *sap_context,
393 		  bool pre_start_bss,
394 		  bool check_for_connection_update);
395 
396 /**
397  * sap_check_in_avoid_ch_list() - checks if given channel present is channel
398  * avoidance list
399  * avoid_channels_info struct
400  * @sap_ctx:        sap context.
401  * @channel:        channel to be checked in sap_ctx's avoid ch list
402  *
403  * sap_ctx contains sap_avoid_ch_info strcut containing the list of channels on
404  * which MDM device's AP with MCC was detected. This function checks if given
405  * channel is present in that list.
406  *
407  * Return: true, if channel was present, false othersie.
408  */
409 bool
410 sap_check_in_avoid_ch_list(struct sap_context *sap_ctx, uint8_t channel);
411 
412 /**
413  * sap_set_session_param() - set sap related param to sap context and global var
414  * @mac_handle: Opaque handle to the global MAC context
415  * @sapctx: pointer to sapctx
416  * @session_id: session id for sap
417  *
418  * This API will set appropriate softap parameters to sap context
419  *
420  * Return: QDF_STATUS
421  */
422 QDF_STATUS sap_set_session_param(mac_handle_t mac_handle,
423 				 struct sap_context *sapctx,
424 				 uint32_t session_id);
425 
426 /**
427  * sap_clear_session_param() - clear sap related param from sap context
428  * @mac_handle: Opaque handle to the global MAC context
429  * @sapctx: pointer to sapctx
430  * @session_id: session id for sap
431  *
432  * This API will clear appropriate softap parameters from sap context
433  *
434  * Return: QDF_STATUS
435  */
436 QDF_STATUS sap_clear_session_param(mac_handle_t mac_handle,
437 				   struct sap_context *sapctx,
438 				   uint32_t session_id);
439 
440 void sap_scan_event_callback(struct wlan_objmgr_vdev *vdev,
441 			struct scan_event *event, void *arg);
442 
443 #ifdef DFS_COMPONENT_ENABLE
444 /**
445  * sap_indicate_radar() - Process radar indication
446  * @sap_ctx: pointer to sap context
447  *
448  * process radar indication.
449  *
450  * Return: frequency to which sap wishes to switch.
451  */
452 qdf_freq_t sap_indicate_radar(struct sap_context *sap_ctx);
453 #else
454 static inline qdf_freq_t sap_indicate_radar(struct sap_context *sap_ctx)
455 {
456 	return 0;
457 }
458 #endif
459 
460 /**
461  * sap_select_default_oper_chan() - Select AP mode default operating channel
462  * @mac_ctx: mac context
463  * @acs_cfg: pointer to ACS config info
464  *
465  * Select AP mode default operating channel based on ACS hw mode and channel
466  * range configuration when ACS scan fails due to some reasons, such as scan
467  * timeout, etc.
468  *
469  * Return: Selected operating channel frequency
470  */
471 uint32_t sap_select_default_oper_chan(struct mac_context *mac_ctx,
472 				      struct sap_acs_cfg *acs_cfg);
473 
474 /*
475  * sap_is_dfs_cac_wait_state() - check if sap is in cac wait state
476  * @sap_ctx: sap context to check
477  *
478  * Return: true if sap is in cac wait state
479  */
480 bool sap_is_dfs_cac_wait_state(struct sap_context *sap_ctx);
481 
482 /**
483  * sap_chan_bond_dfs_sub_chan - check bonded channel includes dfs sub chan
484  * @sap_context: Handle to SAP context.
485  * @channel_freq: chan whose bonded chan will be checked
486  * @bond_state: The channel bonding mode of the passed channel.
487  *
488  * This function checks if a given bonded channel includes dfs sub chan.
489  *
490  * Return: true if at least one dfs sub chan is bonded, otherwise false
491  */
492 bool
493 sap_chan_bond_dfs_sub_chan(struct sap_context *sap_context,
494 			   qdf_freq_t channel_freq,
495 			   ePhyChanBondState bond_state);
496 
497 void
498 sap_build_start_bss_config(struct start_bss_config *sap_bss_cfg,
499 			   struct sap_config *config);
500 #endif
501