xref: /wlan-driver/qcacld-3.0/core/sap/src/sap_internal.h (revision 5113495b16420b49004c444715d2daae2066e7dc)
1 /*
2  * Copyright (c) 2012-2021 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2021-2024 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 #define MAX_VLAN 4
125 struct sap_context {
126 
127 	/* Include the current channel frequency of AP */
128 	uint32_t chan_freq;
129 	uint32_t sec_ch_freq;
130 
131 #ifdef DCS_INTERFERENCE_DETECTION
132 	qdf_freq_t dcs_ch_freq;
133 #endif
134 	union {
135 		uint8_t sessionId;
136 		uint8_t vdev_id;
137 	};
138 	uint8_t sap_radar_found_status;
139 
140 	/* vdev object corresponding to sessionId */
141 	struct wlan_objmgr_vdev *vdev;
142 
143 	/* Include the associations MAC addresses */
144 	uint8_t self_mac_addr[CDS_MAC_ADDRESS_LEN];
145 	struct start_bss_config sap_bss_cfg;
146 
147 	/* SAP event Callback to hdd */
148 	sap_event_cb sap_event_cb;
149 
150 	/*
151 	 * Include the state machine structure here, state var that keeps
152 	 * track of state machine
153 	 */
154 	enum sap_fsm_state fsm_state;
155 	enum sap_csa_reason_code csa_reason;
156 
157 	/* Actual storage for AP and self (STA) SSID */
158 	tCsrSSIDInfo SSIDList[2];
159 
160 	/* Actual storage for AP bssid */
161 	struct qdf_mac_addr bssid;
162 
163 	/* Mac filtering settings */
164 	eSapMacAddrACL eSapMacAddrAclMode;
165 	struct qdf_mac_addr acceptMacList[MAX_ACL_MAC_ADDRESS];
166 	uint16_t nAcceptMac;
167 	struct qdf_mac_addr denyMacList[MAX_ACL_MAC_ADDRESS];
168 	uint16_t nDenyMac;
169 
170 	void *user_context;
171 
172 	uint32_t nStaWPARSnReqIeLength;
173 	uint8_t pStaWpaRsnReqIE[MAX_ASSOC_IND_IE_LEN];
174 
175 	eCsrPhyMode phyMode;
176 	uint32_t *freq_list;
177 	uint8_t num_of_channel;
178 	uint16_t ch_width_orig;
179 	struct ch_params ch_params;
180 	uint32_t chan_freq_before_switch_band;
181 	enum phy_ch_width chan_width_before_switch_band;
182 	uint32_t auto_channel_select_weight;
183 	bool enableOverLapCh;
184 	struct sap_acs_cfg *acs_cfg;
185 
186 	qdf_time_t acs_req_timestamp;
187 
188 #ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
189 	uint8_t cc_switch_mode;
190 #endif
191 
192 #if defined(FEATURE_WLAN_STA_AP_MODE_DFS_DISABLE)
193 	bool dfs_ch_disable;
194 #endif
195 	bool isCacEndNotified;
196 	bool isCacStartNotified;
197 	bool is_sap_ready_for_chnl_chng;
198 #ifdef FEATURE_RADAR_HISTORY
199 	struct prev_cac_result cac_result;
200 #endif
201 #ifdef FEATURE_AP_MCC_CH_AVOIDANCE
202 	/*
203 	 * In a setup having two MDM both operating in AP+AP MCC scenario
204 	 * if both the AP decides to use same or close channel set, CTS to
205 	 * self, mechanism is causing issues with connectivity. For this, its
206 	 * proposed that 2nd MDM devices which comes up later should detect
207 	 * presence of first MDM device via special Q2Q IE present in becon
208 	 * and avoid those channels mentioned in IE.
209 	 *
210 	 * this struct contains the list of channels on which another MDM AP
211 	 * in MCC mode were detected.
212 	 */
213 	struct sap_avoid_channels_info sap_detected_avoid_ch_ie;
214 #endif /* FEATURE_AP_MCC_CH_AVOIDANCE */
215 	/*
216 	 * sap_state, sap_status are created
217 	 * to inform upper layers about ACS scan status.
218 	 * Don't use these members for any other purposes.
219 	 */
220 	eSapHddEvent sap_state;
221 	eSapStatus sap_status;
222 	uint32_t roc_ind_scan_id;
223 	bool vendor_acs_dfs_lte_enabled;
224 	uint8_t dfs_vendor_channel;
225 	uint8_t dfs_vendor_chan_bw;
226 	uint16_t beacon_tx_rate;
227 	enum sap_acs_dfs_mode dfs_mode;
228 	wlan_scan_requester req_id;
229 	uint8_t sap_sta_id;
230 	bool dfs_cac_offload;
231 	bool is_chan_change_inprogress;
232 	/* Disabled mcs13 by sap or not */
233 	bool disabled_mcs13;
234 	qdf_list_t owe_pending_assoc_ind_list;
235 	qdf_list_t ft_pending_assoc_ind_list;
236 	qdf_event_t ft_pending_event;
237 	uint32_t freq_before_ch_switch;
238 	struct ch_params ch_params_before_ch_switch;
239 #ifdef WLAN_FEATURE_P2P_P2P_STA
240 /*
241  *This param is used for GO+GO force scc logic where after
242  *setkey first GO will move to latest GO's channel
243  */
244 	bool is_forcescc_restart_required;
245 #endif
246 	qdf_freq_t candidate_freq;
247 #ifdef FEATURE_WLAN_CH_AVOID_EXT
248 	uint32_t restriction_mask;
249 #endif
250 	bool require_h2e;
251 	bool partial_acs_scan;
252 	bool optimize_acs_chan_selected;
253 #ifdef WLAN_FEATURE_SAP_ACS_OPTIMIZE
254 /*
255  * This param is used to track clean channels where there
256  * is no AP found on these channels
257  */
258 	bool clean_channel_array[NUM_CHANNELS];
259 #endif
260 #ifdef QCA_MULTIPASS_SUPPORT
261 	uint16_t vlan_map[2 * MAX_VLAN];
262 #endif
263 };
264 
265 /*----------------------------------------------------------------------------
266  *  External declarations for global context
267  * -------------------------------------------------------------------------*/
268 
269 /**
270  * struct sap_sm_event - SAP state machine event definition
271  * @params: A VOID pointer type for all possible inputs
272  * @event: State machine input event message
273  * @u1: Introduced to handle csr_roam_complete_cb roamStatus
274  * @u2: Introduced to handle csr_roam_complete_cb roamResult
275  */
276 struct sap_sm_event {
277 	void *params;
278 	uint32_t event;
279 	uint32_t u1;
280 	uint32_t u2;
281 };
282 
283 /*----------------------------------------------------------------------------
284  * Function Declarations and Documentation
285  * -------------------------------------------------------------------------*/
286 
287 /**
288  * sap_get_mac_context() - Get a pointer to the global MAC context
289  *
290  * Return: pointer to the global MAC context, or NULL if the MAC
291  *         context is no longer registered
292  */
sap_get_mac_context(void)293 static inline struct mac_context *sap_get_mac_context(void)
294 {
295 	return cds_get_context(QDF_MODULE_ID_PE);
296 }
297 
298 QDF_STATUS wlansap_context_get(struct sap_context *ctx);
299 void wlansap_context_put(struct sap_context *ctx);
300 
301 /**
302  * wlansap_pre_start_bss_acs_scan_callback() - callback for scan results
303  * @mac_handle:    the mac_handle passed in with the scan request
304  * @sap_ctx:       the SAP context pointer.
305  * @scanid:        scan id passed
306  * @sessionid:     session identifier
307  * @scan_status:        status of scan -success, failure or abort
308  *
309  * Api for scan callback. This function is invoked as a result of scan
310  * completion and reports the scan results.
311  *
312  * Return: The QDF_STATUS code associated with performing the operation
313  */
314 QDF_STATUS wlansap_pre_start_bss_acs_scan_callback(mac_handle_t mac_handle,
315 						   struct sap_context *sap_ctx,
316 						   uint8_t sessionid,
317 						   uint32_t scanid,
318 						   eCsrScanStatus scan_status);
319 
320 /**
321  * sap_chan_sel_exit() - Exit function for free out the allocated memory,
322  * @ch_info_params: Pointer to sap_sel_ch_info structure
323  *
324  * Return: None
325  */
326 void sap_chan_sel_exit(struct sap_sel_ch_info *ch_info_params);
327 
328 /**
329  * sap_sort_channel_list() - Sort channel list based on channel weight
330  * @mac_ctx: Pointer to mac_context
331  * @vdev_id: Vdev ID
332  * @ch_list: Pointer to qdf_list_t
333  * @ch_info: Pointer to sap_sel_ch_info structure
334  * @domain: Regulatory Domain
335  * @operating_band: Operating band
336  *
337  * Return: None
338  *
339  */
340 void
341 sap_sort_channel_list(struct mac_context *mac_ctx, uint8_t vdev_id,
342 		      qdf_list_t *ch_list, struct sap_sel_ch_info *ch_info,
343 		      v_REGDOMAIN_t *domain, uint32_t *operating_band);
344 
345 /**
346  * sap_select_channel() - select SAP channel
347  * @mac_handle: Opaque handle to the global MAC context
348  * @sap_ctx: Sap context
349  * @scan_list: scan entry list
350  *
351  * Runs a algorithm to select the best channel to operate in based on BSS
352  * rssi and bss count on each channel
353  *
354  * Returns: channel frequency if success, 0 otherwise
355  */
356 uint32_t sap_select_channel(mac_handle_t mac_handle, struct sap_context *sap_ctx,
357 			   qdf_list_t *scan_list);
358 
359 QDF_STATUS
360 sap_signal_hdd_event(struct sap_context *sap_ctx,
361 		  struct csr_roam_info *pCsrRoamInfo,
362 		  eSapHddEvent sapHddevent, void *);
363 
364 QDF_STATUS sap_fsm(struct sap_context *sap_ctx, struct sap_sm_event *sap_event);
365 
366 QDF_STATUS
367 sap_is_peer_mac_allowed(struct sap_context *sap_ctx, uint8_t *peerMac);
368 
369 void
370 sap_sort_mac_list(struct qdf_mac_addr *macList, uint16_t size);
371 
372 void
373 sap_add_mac_to_acl(struct qdf_mac_addr *macList, uint16_t *size,
374 		   uint8_t *peerMac);
375 
376 void
377 sap_remove_mac_from_acl(struct qdf_mac_addr *macList, uint16_t *size,
378 			uint16_t index);
379 
380 void
381 sap_print_acl(struct qdf_mac_addr *macList, uint16_t size);
382 
383 bool
384 sap_search_mac_list(struct qdf_mac_addr *macList, uint16_t num_mac,
385 		    uint8_t *peerMac, uint16_t *index);
386 
387 QDF_STATUS sap_init_dfs_channel_nol_list(struct sap_context *sap_ctx);
388 
389 bool sap_dfs_is_channel_in_nol_list(struct sap_context *sap_ctx,
390 				    qdf_freq_t chan_freq,
391 				    ePhyChanBondState chanBondState);
392 void sap_dfs_cac_timer_callback(void *data);
393 
394 /**
395  * sap_cac_reset_notify() - BSS cleanup notification handler
396  * @mac_handle: Opaque handle to the global MAC context
397  *
398  * This function should be called upon stop bss indication to clean up
399  * DFS global structure.
400  */
401 void sap_cac_reset_notify(mac_handle_t mac_handle);
402 
403 bool is_concurrent_sap_ready_for_channel_change(mac_handle_t mac_handle,
404 						struct sap_context *sap_ctx);
405 
406 bool sap_is_conc_sap_doing_scc_dfs(mac_handle_t mac_handle,
407 				   struct sap_context *given_sapctx);
408 
409 uint8_t sap_get_total_number_sap_intf(mac_handle_t mac_handle);
410 
411 /**
412  * sap_channel_sel - Function for initiating scan request for ACS
413  * @sap_context: Sap Context value.
414  *
415  * Initiates Scan for ACS to pick a channel.
416  *
417  * Return: The QDF_STATUS code associated with performing the operation.
418  */
419 QDF_STATUS sap_channel_sel(struct sap_context *sap_context);
420 
421 /**
422  * sap_validate_chan - Function validate the channel and forces SCC
423  * @sap_context: Sap Context value.
424  * @pre_start_bss: if its called pre start BSS with valid channel.
425  * @check_for_connection_update: true, check and wait for connection update
426  *				 false, do not perform connection update
427  *
428  * validate and update the channel in case of force SCC.
429  *
430  * Return: The QDF_STATUS code associated with performing the operation.
431  */
432 QDF_STATUS
433 sap_validate_chan(struct sap_context *sap_context,
434 		  bool pre_start_bss,
435 		  bool check_for_connection_update);
436 
437 /**
438  * sap_check_in_avoid_ch_list() - checks if given channel present is channel
439  * avoidance list
440  * avoid_channels_info struct
441  * @sap_ctx:        sap context.
442  * @channel:        channel to be checked in sap_ctx's avoid ch list
443  *
444  * sap_ctx contains sap_avoid_ch_info strcut containing the list of channels on
445  * which MDM device's AP with MCC was detected. This function checks if given
446  * channel is present in that list.
447  *
448  * Return: true, if channel was present, false othersie.
449  */
450 bool
451 sap_check_in_avoid_ch_list(struct sap_context *sap_ctx, uint8_t channel);
452 
453 /**
454  * sap_set_session_param() - set sap related param to sap context and global var
455  * @mac_handle: Opaque handle to the global MAC context
456  * @sapctx: pointer to sapctx
457  * @session_id: session id for sap
458  *
459  * This API will set appropriate softap parameters to sap context
460  *
461  * Return: QDF_STATUS
462  */
463 QDF_STATUS sap_set_session_param(mac_handle_t mac_handle,
464 				 struct sap_context *sapctx,
465 				 uint32_t session_id);
466 
467 /**
468  * sap_clear_session_param() - clear sap related param from sap context
469  * @mac_handle: Opaque handle to the global MAC context
470  * @sapctx: pointer to sapctx
471  * @session_id: session id for sap
472  *
473  * This API will clear appropriate softap parameters from sap context
474  *
475  * Return: QDF_STATUS
476  */
477 QDF_STATUS sap_clear_session_param(mac_handle_t mac_handle,
478 				   struct sap_context *sapctx,
479 				   uint32_t session_id);
480 
481 void sap_scan_event_callback(struct wlan_objmgr_vdev *vdev,
482 			struct scan_event *event, void *arg);
483 
484 #ifdef DFS_COMPONENT_ENABLE
485 /**
486  * sap_indicate_radar() - Process radar indication
487  * @sap_ctx: pointer to sap context
488  *
489  * process radar indication.
490  *
491  * Return: frequency to which sap wishes to switch.
492  */
493 qdf_freq_t sap_indicate_radar(struct sap_context *sap_ctx);
494 #else
sap_indicate_radar(struct sap_context * sap_ctx)495 static inline qdf_freq_t sap_indicate_radar(struct sap_context *sap_ctx)
496 {
497 	return 0;
498 }
499 #endif
500 
501 /**
502  * sap_select_default_oper_chan() - Select AP mode default operating channel
503  * @mac_ctx: mac context
504  * @acs_cfg: pointer to ACS config info
505  *
506  * Select AP mode default operating channel based on ACS hw mode and channel
507  * range configuration when ACS scan fails due to some reasons, such as scan
508  * timeout, etc.
509  *
510  * Return: Selected operating channel frequency
511  */
512 uint32_t sap_select_default_oper_chan(struct mac_context *mac_ctx,
513 				      struct sap_acs_cfg *acs_cfg);
514 
515 /*
516  * sap_is_dfs_cac_wait_state() - check if sap is in cac wait state
517  * @sap_ctx: sap context to check
518  *
519  * Return: true if sap is in cac wait state
520  */
521 bool sap_is_dfs_cac_wait_state(struct sap_context *sap_ctx);
522 
523 /**
524  * sap_chan_bond_dfs_sub_chan - check bonded channel includes dfs sub chan
525  * @sap_context: Handle to SAP context.
526  * @channel_freq: chan whose bonded chan will be checked
527  * @bond_state: The channel bonding mode of the passed channel.
528  *
529  * This function checks if a given bonded channel includes dfs sub chan.
530  *
531  * Return: true if at least one dfs sub chan is bonded, otherwise false
532  */
533 bool
534 sap_chan_bond_dfs_sub_chan(struct sap_context *sap_context,
535 			   qdf_freq_t channel_freq,
536 			   ePhyChanBondState bond_state);
537 
538 /**
539  * sap_plus_sap_cac_skip() - Check current sap can skip CAC or not
540  *  in SAP+SAP concurrency
541  * @mac: mac ctx
542  * @sap_ctx: SAP context
543  * @chan_freq: SAP channel frequency
544  *
545  * All APs are done with CAC timer, all APs should start beaconing.
546  * Lets assume AP1 and AP2 started beaconing on DFS channel, Now lets
547  * say AP1 goes down and comes back on same DFS channel. In this case
548  * AP1 shouldn't start CAC timer and start beacon immediately because
549  * AP2 is already beaconing on this channel. This case will be handled
550  * by checking CAC completion on AP2.
551  *
552  * Return: true if current SAP can skip CAC
553  */
554 bool sap_plus_sap_cac_skip(struct mac_context *mac,
555 			   struct sap_context *sap_ctx,
556 			   qdf_freq_t chan_freq);
557 
558 void
559 sap_build_start_bss_config(struct start_bss_config *sap_bss_cfg,
560 			   struct sap_config *config);
561 #endif
562