1 /*
2  * Copyright (c) 2013-2021 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2022-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 #if !defined(WLAN_HDD_HOSTAPD_H)
21 #define WLAN_HDD_HOSTAPD_H
22 
23 /**
24  * DOC: wlan_hdd_hostapd.h
25  *
26  * WLAN Host Device driver hostapd header file
27  */
28 
29 /* Include files */
30 
31 #include <linux/netdevice.h>
32 #include <linux/skbuff.h>
33 #include <qdf_list.h>
34 #include <qdf_types.h>
35 #include <wlan_hdd_main.h>
36 
37 /* Preprocessor definitions and constants */
38 
39 struct hdd_adapter *hdd_wlan_create_ap_dev(struct hdd_context *hdd_ctx,
40 				      tSirMacAddr macAddr,
41 				      unsigned char name_assign_type,
42 				      uint8_t *name);
43 
44 enum csr_akm_type
45 hdd_translate_rsn_to_csr_auth_type(uint8_t auth_suite[4]);
46 
47 /**
48  * hdd_filter_ft_info() -
49  * This function to filter fast BSS transition related IE
50  * @frame: pointer to the input frame.
51  * @len: input frame length.
52  * @ft_info_len: store the total length of FT related IE.
53  *
54  * Return: pointer to a buffer which stored the FT related IE
55  * This is a malloced memory that must be freed by the caller
56  */
57 
58 void *hdd_filter_ft_info(const uint8_t *frame,
59 			 size_t len, uint32_t *ft_info_len);
60 
61 /**
62  * hdd_softap_set_channel_change() -
63  * This function to support SAP channel change with CSA IE
64  * set in the beacons.
65  *
66  * @dev: pointer to the net device.
67  * @target_chan_freq: target channel frequency.
68  * @target_bw: Target bandwidth to move.
69  * If no bandwidth is specified, the value is CH_WIDTH_MAX
70  * @forced: Force to switch channel, ignore SCC/MCC check
71  *
72  * Return: 0 for success, non zero for failure
73  */
74 int hdd_softap_set_channel_change(struct net_device *dev,
75 					int target_chan_freq,
76 					enum phy_ch_width target_bw,
77 					bool forced);
78 /**
79  * hdd_stop_sap_set_tx_power() - Function to set tx power
80  * for unsafe channel if restriction bit mask is set else stop the SAP.
81  * @psoc: PSOC object information
82  * @adapter: AP/SAP adapter
83  *
84  * This function set tx power/stop the SAP interface
85  *
86  * Return:
87  *
88  */
89 void hdd_stop_sap_set_tx_power(struct wlan_objmgr_psoc *psoc,
90 			       struct hdd_adapter *adapter);
91 
92 #ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
93 /**
94  * hdd_sap_restart_with_channel_switch() - SAP channel change with E/CSA
95  * @psoc: psoc common object
96  * @ap_adapter: HDD adapter
97  * @target_chan_freq: Channel frequency to which switch must happen
98  * @target_bw: Bandwidth of the target channel
99  * @forced: Force to switch channel, ignore SCC/MCC check
100  *
101  * Invokes the necessary API to perform channel switch for the SAP or GO
102  *
103  * Return: QDF_STATUS_SUCCESS if successfully
104  */
105 QDF_STATUS hdd_sap_restart_with_channel_switch(struct wlan_objmgr_psoc *psoc,
106 					       struct hdd_adapter *ap_adapter,
107 					       uint32_t target_chan_freq,
108 					       uint32_t target_bw,
109 					       bool forced);
110 
111 /**
112  * hdd_sap_restart_chan_switch_cb() - Function to restart SAP with
113  * a different channel
114  * @psoc: PSOC object information
115  * @vdev_id: vdev id
116  * @ch_freq: channel to switch
117  * @channel_bw: channel bandwidth
118  * @forced: Force to switch channel, ignore SCC/MCC check
119  *
120  * This function restarts SAP with a different channel
121  *
122  * Return: QDF_STATUS_SUCCESS if successfully
123  *
124  */
125 QDF_STATUS hdd_sap_restart_chan_switch_cb(struct wlan_objmgr_psoc *psoc,
126 					  uint8_t vdev_id, uint32_t ch_freq,
127 					  uint32_t channel_bw, bool forced);
128 
129 /**
130  * wlan_hdd_check_cc_intf_cb() - Check force SCC for vdev interface.
131  * @psoc: PSOC object information
132  * @vdev_id: vdev id
133  * @ch_freq: channel frequency to switch to
134  *
135  * This function will return a channel frequency to avoid MCC for SAP/GO.
136  *
137  * Return: QDF_STATUS_SUCCESS if successfully
138  *
139  */
140 QDF_STATUS wlan_hdd_check_cc_intf_cb(struct wlan_objmgr_psoc *psoc,
141 				     uint8_t vdev_id, uint32_t *ch_freq);
142 
143 /**
144  * wlan_hdd_get_channel_for_sap_restart() - Function to get
145  * suitable channel and restart SAP
146  * @psoc: PSOC object information
147  * @vdev_id: vdev id
148  * @ch_freq: channel to be returned
149  *
150  * This function gets the channel parameters to restart SAP
151  *
152  * Return: None
153  *
154  */
155 QDF_STATUS wlan_hdd_get_channel_for_sap_restart(
156 				struct wlan_objmgr_psoc *psoc,
157 				uint8_t vdev_id, uint32_t *ch_freq);
158 
159 /**
160  * wlan_get_sap_acs_band() - Get  sap acs band
161  *
162  * @psoc: pointer to psoc
163  * @vdev_id: vdev id
164  * @acs_band: Pointer to acs_band
165  *
166  * This function is used to get sap acs band from sap config
167  *
168  * Return: QDF_STATUS_SUCCESS if successful
169  */
170 uint32_t
171 wlan_get_sap_acs_band(struct wlan_objmgr_psoc *psoc, uint8_t vdev_id,
172 		      uint32_t *acs_band);
173 
174 /**
175  * wlan_get_ap_prefer_conc_ch_params() - Get prefer sap target channel
176  *  bw parameters
177  * @psoc: pointer to psoc
178  * @vdev_id: vdev id
179  * @chan_freq: sap channel
180  * @ch_params: output channel parameters
181  *
182  * This function is used to get prefer sap target channel bw during sap force
183  * scc CSA. The new bw will not exceed the original bw during start ap
184  * request.
185  *
186  * Return: QDF_STATUS_SUCCESS if successfully
187  */
188 QDF_STATUS
189 wlan_get_ap_prefer_conc_ch_params(
190 		struct wlan_objmgr_psoc *psoc,
191 		uint8_t vdev_id, uint32_t chan_freq,
192 		struct ch_params *ch_params);
193 
194 /**
195  * hdd_get_ap_6ghz_capable() - Get ap vdev 6ghz capable flags
196  * @psoc: PSOC object information
197  * @vdev_id: vdev id
198  *
199  * This function gets 6ghz capable information based on hdd ap adapter
200  * context.
201  *
202  * Return: uint32_t, vdev 6g capable flags from enum conn_6ghz_flag
203  */
204 uint32_t hdd_get_ap_6ghz_capable(struct wlan_objmgr_psoc *psoc,
205 				 uint8_t vdev_id);
206 #endif
207 
208 /**
209  * wlan_hdd_set_sap_csa_reason() - Function to set
210  * sap csa reason
211  * @psoc: PSOC object information
212  * @vdev_id: vdev id
213  * @reason: reason to be updated
214  *
215  * This function sets the reason for SAP channel switch
216  *
217  * Return: None
218  *
219  */
220 void wlan_hdd_set_sap_csa_reason(struct wlan_objmgr_psoc *psoc, uint8_t vdev_id,
221 				 uint8_t reason);
222 eCsrEncryptionType
223 hdd_translate_rsn_to_csr_encryption_type(uint8_t cipher_suite[4]);
224 
225 eCsrEncryptionType
226 hdd_translate_rsn_to_csr_encryption_type(uint8_t cipher_suite[4]);
227 
228 enum csr_akm_type
229 hdd_translate_wpa_to_csr_auth_type(uint8_t auth_suite[4]);
230 
231 eCsrEncryptionType
232 hdd_translate_wpa_to_csr_encryption_type(uint8_t cipher_suite[4]);
233 
234 QDF_STATUS hdd_softap_sta_deauth(struct hdd_adapter *adapter,
235 				 struct csr_del_sta_params *param);
236 void hdd_softap_sta_disassoc(struct hdd_adapter *adapter,
237 			     struct csr_del_sta_params *param);
238 
239 QDF_STATUS hdd_hostapd_sap_event_cb(struct sap_event *sap_event,
240 				    void *context);
241 /**
242  * hdd_init_ap_mode() - to init the AP adaptor
243  * @adapter: SAP/GO adapter
244  * @reinit: true if re-init, otherwise initial init
245  * @rtnl_held: true if rtnl lock is taken, otherwise false
246  *
247  * This API can be called to open the SAP session as well as
248  * to create and store the vdev object. It also initializes necessary
249  * SAP adapter related params.
250  */
251 QDF_STATUS hdd_init_ap_mode(struct hdd_adapter *adapter,
252 			    bool reinit,
253 			    bool rtnl_held);
254 
255 /**
256  * hdd_deinit_ap_mode() - to deinit the AP adaptor
257  * @link_info: Link info pointer in HDD adapter
258  *
259  * This API can be called to close the SAP session as well as
260  * release the vdev object completely. It also deinitializes necessary
261  * SAP adapter related params.
262  */
263 void hdd_deinit_ap_mode(struct wlan_hdd_link_info *link_info);
264 
265 void hdd_set_ap_ops(struct net_device *dev);
266 /**
267  * hdd_sap_create_ctx() - Wrapper API to create SAP context
268  * @adapter: pointer to adapter
269  *
270  * This wrapper API can be called to create the sap context. It will
271  * eventually calls SAP API to create the sap context
272  *
273  * Return: true or false based on overall success or failure
274  */
275 bool hdd_sap_create_ctx(struct hdd_adapter *adapter);
276 /**
277  * hdd_sap_destroy_ctx() - Wrapper API to destroy SAP context
278  * @link_info: Pointer of link_info in adapter
279  *
280  * This wrapper API can be called to destroy the sap context. It will
281  * eventually calls SAP API to destroy the sap context
282  *
283  * Return: true or false based on overall success or failure
284  */
285 bool hdd_sap_destroy_ctx(struct wlan_hdd_link_info *link_info);
286 /**
287  * hdd_sap_destroy_ctx_all() - Wrapper API to destroy all SAP context
288  * @hdd_ctx: pointer to HDD context
289  * @is_ssr: true if SSR is in progress
290  *
291  * This wrapper API can be called to destroy all the sap context.
292  * if is_ssr is true, it will return as sap_ctx will be used when
293  * restart sap.
294  *
295  * Return: none
296  */
297 void hdd_sap_destroy_ctx_all(struct hdd_context *hdd_ctx, bool is_ssr);
298 
299 /**
300  * hdd_hostapd_stop_no_trans() - hdd stop function for hostapd interface
301  * @dev: pointer to net_device structure
302  *
303  * This is called in response to ifconfig down. Vdev sync transaction
304  * should be started before calling this API.
305  *
306  * Return - 0 for success non-zero for failure
307  */
308 int hdd_hostapd_stop_no_trans(struct net_device *dev);
309 
310 int hdd_hostapd_stop(struct net_device *dev);
311 int hdd_sap_context_init(struct hdd_context *hdd_ctx);
312 void hdd_sap_context_destroy(struct hdd_context *hdd_ctx);
313 #ifdef QCA_HT_2040_COEX
314 QDF_STATUS hdd_set_sap_ht2040_mode(struct hdd_adapter *adapter,
315 				   uint8_t channel_type);
316 
317 /**
318  * hdd_get_sap_ht2040_mode() - get ht2040 mode
319  * @adapter: pointer to adapter
320  * @channel_type: given channel type
321  *
322  * Return: QDF_STATUS_SUCCESS if successfully
323  */
324 QDF_STATUS hdd_get_sap_ht2040_mode(struct hdd_adapter *adapter,
325 				   enum eSirMacHTChannelType *channel_type);
326 #else
hdd_set_sap_ht2040_mode(struct hdd_adapter * adapter,uint8_t channel_type)327 static inline QDF_STATUS hdd_set_sap_ht2040_mode(struct hdd_adapter *adapter,
328 						 uint8_t channel_type)
329 {
330 	return QDF_STATUS_SUCCESS;
331 }
332 
hdd_get_sap_ht2040_mode(struct hdd_adapter * adapter,enum eSirMacHTChannelType * channel_type)333 static inline QDF_STATUS hdd_get_sap_ht2040_mode(
334 				struct hdd_adapter *adapter,
335 				enum eSirMacHTChannelType *channel_type)
336 {
337 	return QDF_STATUS_E_FAILURE;
338 }
339 #endif
340 
341 #ifdef CFG80211_SINGLE_NETDEV_MULTI_LINK_SUPPORT
342 /**
343  * wlan_hdd_cfg80211_stop_ap() - stop sap
344  * @wiphy: Pointer to wiphy
345  * @dev: Pointer to netdev
346  * @link_id: Link id for which this stop_ap is received.
347  *
348  * Return: zero for success non-zero for failure
349  */
350 int wlan_hdd_cfg80211_stop_ap(struct wiphy *wiphy, struct net_device *dev,
351 			      unsigned int link_id);
352 #else
353 int wlan_hdd_cfg80211_stop_ap(struct wiphy *wiphy,
354 			      struct net_device *dev);
355 #endif
356 
357 int wlan_hdd_cfg80211_start_ap(struct wiphy *wiphy,
358 			       struct net_device *dev,
359 			       struct cfg80211_ap_settings *params);
360 
361 int wlan_hdd_cfg80211_change_beacon(struct wiphy *wiphy,
362 				    struct net_device *dev,
363 				    struct cfg80211_beacon_data *params);
364 
365 /**
366  * hdd_is_peer_associated - is peer connected to softap
367  * @adapter: pointer to softap adapter
368  * @mac_addr: address to check in peer list
369  *
370  * This function has to be invoked only when bss is started and is used
371  * to check whether station with specified addr is peer or not
372  *
373  * Return: true if peer mac, else false
374  */
375 bool hdd_is_peer_associated(struct hdd_adapter *adapter,
376 			    struct qdf_mac_addr *mac_addr);
377 
378 int hdd_destroy_acs_timer(struct hdd_adapter *adapter);
379 
380 QDF_STATUS wlan_hdd_config_acs(struct hdd_context *hdd_ctx,
381 			       struct hdd_adapter *adapter);
382 
383 void hdd_sap_indicate_disconnect_for_sta(struct hdd_adapter *adapter);
384 
385 /**
386  * hdd_handle_acs_2g_preferred_sap_conc() - Handle 2G pereferred SAP
387  * concurrency with GO
388  * @psoc: soc object
389  * @adapter: HDD adapter context
390  * @sap_config: sap config
391  *
392  * In SAP+GO concurrency, if GO is started on 2G and SAP is
393  * doing ACS with 2G preferred channel list, then we will
394  * move GO to 5G band. The purpose is to have more choice
395  * in SAP ACS instead of starting on GO home channel for SCC.
396  * This API is to check such condition and move GO to 5G.
397  *
398  * Return: void
399  */
400 void
401 hdd_handle_acs_2g_preferred_sap_conc(struct wlan_objmgr_psoc *psoc,
402 				     struct hdd_adapter *adapter,
403 				     struct sap_config *sap_config);
404 
405 /**
406  * wlan_hdd_disable_channels() - Cache the channels
407  * and current state of the channels from the channel list
408  * received in the command and disable the channels on the
409  * wiphy and reg table.
410  * @hdd_ctx: Pointer to hdd context
411  *
412  * Return: 0 on success, Error code on failure
413  */
414 int wlan_hdd_disable_channels(struct hdd_context *hdd_ctx);
415 
416 /*
417  * hdd_check_and_disconnect_sta_on_invalid_channel() - Disconnect STA if it is
418  * on invalid channel
419  * @hdd_ctx: pointer to hdd context
420  * @reason: Mac Disconnect reason code as per @enum wlan_reason_code
421  *
422  * STA should be disconnected before starting the SAP if it is on indoor
423  * channel.
424  *
425  * Return: void
426  */
427 void
428 hdd_check_and_disconnect_sta_on_invalid_channel(struct hdd_context *hdd_ctx,
429 						enum wlan_reason_code reason);
430 
431 /**
432  * hdd_convert_dot11mode_from_phymode() - get dot11 mode from phymode
433  * @phymode: phymode of sta associated to SAP
434  *
435  * The function is to convert the phymode to corresponding dot11 mode
436  *
437  * Return: dot11mode.
438  */
439 enum qca_wlan_802_11_mode hdd_convert_dot11mode_from_phymode(int phymode);
440 
441 /**
442  * hdd_stop_sap_due_to_invalid_channel() - to stop sap in case of invalid chnl
443  * @work: pointer to work structure
444  *
445  * Let's say SAP detected RADAR and trying to select the new channel and if no
446  * valid channel is found due to none of the channels are available or
447  * regulatory restriction then SAP needs to be stopped. so SAP state-machine
448  * will create a work to stop the bss
449  *
450  * stop bss has to happen through worker thread because radar indication comes
451  * from FW through mc thread or main host thread and if same thread is used to
452  * do stopbss then waiting for stopbss to finish operation will halt mc thread
453  * to freeze which will trigger stopbss timeout. Instead worker thread can do
454  * the stopbss operation while mc thread waits for stopbss to finish.
455  *
456  * Return: none
457  */
458 void hdd_stop_sap_due_to_invalid_channel(struct work_struct *work);
459 
460 /**
461  * hdd_is_any_sta_connecting() - check if any sta is connecting
462  * @hdd_ctx: hdd context
463  *
464  * Return: true if any sta is connecting
465  */
466 bool hdd_is_any_sta_connecting(struct hdd_context *hdd_ctx);
467 
468 /**
469  * wlan_hdd_configure_twt_responder() - configure twt responder in sap_config
470  * @hdd_ctx: Pointer to hdd context
471  * @twt_responder: twt responder configure value
472  *
473  * Return: none
474  */
475 void
476 wlan_hdd_configure_twt_responder(struct hdd_context *hdd_ctx,
477 				 bool twt_responder);
478 #ifdef WLAN_FEATURE_11BE_MLO
479 /**
480  * wlan_hdd_mlo_reset() - reset mlo configuration if start bss fails
481  * @link_info: Pointer to link_info in hostapd adapter
482  *
483  * Return: void
484  */
485 void wlan_hdd_mlo_reset(struct wlan_hdd_link_info *link_info);
486 #else
wlan_hdd_mlo_reset(struct wlan_hdd_link_info * link_info)487 static inline void wlan_hdd_mlo_reset(struct wlan_hdd_link_info *link_info)
488 {
489 }
490 #endif /* end WLAN_FEATURE_11BE_MLO */
491 
492 #ifdef WLAN_FEATURE_SAP_ACS_OPTIMIZE
493 /**
494  * hdd_sap_is_acs_in_progress() - API to return if ACS is in progress
495  * @vdev: pointer t vdev object
496  *
497  * Return: bool
498  */
499 bool hdd_sap_is_acs_in_progress(struct wlan_objmgr_vdev *vdev);
500 #else
501 static inline
hdd_sap_is_acs_in_progress(struct wlan_objmgr_vdev * vdev)502 bool hdd_sap_is_acs_in_progress(struct wlan_objmgr_vdev *vdev)
503 {
504 	return false;
505 }
506 #endif
507 
508 #ifdef WLAN_CHIPSET_STATS
509 /*
510  * hdd_cp_stats_cstats_sap_go_start_event() - chipset stats for sap/go start
511  * event
512  *
513  * @link_info: pointer to link_info object
514  * @sap_event: pointer to sap_event object
515  *
516  * Return : void
517  */
518 void
519 hdd_cp_stats_cstats_sap_go_start_event(struct wlan_hdd_link_info *link_info,
520 				       struct sap_event *sap_event);
521 
522 /**
523  * hdd_cp_stats_cstats_sap_go_stop_event() - chipset stats for sap/go stop event
524  *
525  * @link_info: pointer to link_info object
526  * @sap_event: pointer to sap_event object
527  *
528  * Return : void
529  */
530 void
531 hdd_cp_stats_cstats_sap_go_stop_event(struct wlan_hdd_link_info *link_info,
532 				      struct sap_event *sap_event);
533 
534 /**
535  * hdd_cp_stats_cstats_log_sap_go_sta_disassoc_event() - chipset stats for
536  * sap/go STA disconnect event
537  *
538  * @li: pointer to link_info object
539  * @sap_evt: pointer to sap_event object
540  *
541  * Return : void
542  */
543 void
544 hdd_cp_stats_cstats_log_sap_go_sta_disassoc_event(struct wlan_hdd_link_info *li,
545 						  struct sap_event *sap_evt);
546 
547 /**
548  * hdd_cp_stats_cstats_log_sap_go_sta_assoc_reassoc_event() - chipset stats for
549  * sap/go STA assoc event
550  *
551  * @li: pointer to link_info object
552  * @sap_evt: pointer to sap_event object
553  *
554  * Return : void
555  */
556 void
557 hdd_cp_stats_cstats_log_sap_go_sta_assoc_reassoc_event
558 		     (struct wlan_hdd_link_info *li, struct sap_event *sap_evt);
559 
560 /**
561  * hdd_cp_stats_cstats_log_sap_go_dfs_event() - chipset stats for
562  * sap/go dfs event
563  *
564  * @li: pointer to link_info object
565  * @event_id: eSapHddEvent event
566  *
567  * Return : void
568  */
569 void hdd_cp_stats_cstats_log_sap_go_dfs_event(struct wlan_hdd_link_info *li,
570 					      eSapHddEvent event_id);
571 #else
572 static inline void
hdd_cp_stats_cstats_sap_go_start_event(struct wlan_hdd_link_info * link_info,struct sap_event * sap_event)573 hdd_cp_stats_cstats_sap_go_start_event(struct wlan_hdd_link_info *link_info,
574 				       struct sap_event *sap_event)
575 {
576 }
577 
578 static inline void
hdd_cp_stats_cstats_sap_go_stop_event(struct wlan_hdd_link_info * link_info,struct sap_event * sap_event)579 hdd_cp_stats_cstats_sap_go_stop_event(struct wlan_hdd_link_info *link_info,
580 				      struct sap_event *sap_event)
581 {
582 }
583 
584 static inline void
hdd_cp_stats_cstats_log_sap_go_sta_disassoc_event(struct wlan_hdd_link_info * li,struct sap_event * sap_evt)585 hdd_cp_stats_cstats_log_sap_go_sta_disassoc_event(struct wlan_hdd_link_info *li,
586 						  struct sap_event *sap_evt)
587 {
588 }
589 
590 static inline void
hdd_cp_stats_cstats_log_sap_go_sta_assoc_reassoc_event(struct wlan_hdd_link_info * li,struct sap_event * sap_evt)591 hdd_cp_stats_cstats_log_sap_go_sta_assoc_reassoc_event
592 		     (struct wlan_hdd_link_info *li, struct sap_event *sap_evt)
593 {
594 }
595 
596 static inline void
hdd_cp_stats_cstats_log_sap_go_dfs_event(struct wlan_hdd_link_info * li,eSapHddEvent event_id)597 hdd_cp_stats_cstats_log_sap_go_dfs_event(struct wlan_hdd_link_info *li,
598 					 eSapHddEvent event_id)
599 {
600 }
601 #endif /* WLAN_CHIPSET_STATS */
602 #endif /* end #if !defined(WLAN_HDD_HOSTAPD_H) */
603