xref: /wlan-dirver/qca-wifi-host-cmn/umac/regulatory/dispatcher/src/wlan_reg_ucfg_api.c (revision 901120c066e139c7f8a2c8e4820561fdd83c67ef)
1 /*
2  * Copyright (c) 2017-2021 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
4  *
5  *
6  * Permission to use, copy, modify, and/or distribute this software for
7  * any purpose with or without fee is hereby granted, provided that the
8  * above copyright notice and this permission notice appear in all
9  * copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
12  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
13  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
14  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
15  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
16  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
17  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
18  * PERFORMANCE OF THIS SOFTWARE.
19  */
20 
21  /**
22  * @file wlan_req_ucfg_api.c
23  * @brief contains regulatory user config interface definitions
24  */
25 
26 #include <wlan_objmgr_vdev_obj.h>
27 #include <wlan_reg_ucfg_api.h>
28 #include <wlan_objmgr_psoc_obj.h>
29 #include <../../core/src/reg_priv_objs.h>
30 #include <../../core/src/reg_utils.h>
31 #include <../../core/src/reg_services_common.h>
32 #include <../../core/src/reg_lte.h>
33 #include <../../core/src/reg_offload_11d_scan.h>
34 #include <../../core/src/reg_build_chan_list.h>
35 #include <../../core/src/reg_callbacks.h>
36 #include <qdf_module.h>
37 
38 QDF_STATUS ucfg_reg_register_event_handler(uint8_t vdev_id, reg_event_cb cb,
39 		void *arg)
40 {
41 	/* Register a event cb handler */
42 	return QDF_STATUS_SUCCESS;
43 }
44 
45 QDF_STATUS ucfg_reg_unregister_event_handler(uint8_t vdev_id, reg_event_cb cb,
46 		void *arg)
47 {
48 	/* unregister a event cb handler */
49 	return QDF_STATUS_SUCCESS;
50 }
51 
52 QDF_STATUS ucfg_reg_init_handler(uint8_t pdev_id)
53 {
54 	/* regulatory initialization handler */
55 	return QDF_STATUS_SUCCESS;
56 }
57 
58 QDF_STATUS ucfg_reg_get_current_chan_list(struct wlan_objmgr_pdev *pdev,
59 					  struct regulatory_channel *chan_list)
60 {
61 	return reg_get_current_chan_list(pdev, chan_list);
62 }
63 
64 qdf_export_symbol(ucfg_reg_get_current_chan_list);
65 
66 QDF_STATUS ucfg_reg_modify_chan_144(struct wlan_objmgr_pdev *pdev,
67 				    bool enable_ch_144)
68 {
69 	return reg_modify_chan_144(pdev, enable_ch_144);
70 }
71 
72 bool ucfg_reg_get_en_chan_144(struct wlan_objmgr_pdev *pdev)
73 {
74 	return reg_get_en_chan_144(pdev);
75 }
76 
77 QDF_STATUS ucfg_reg_set_config_vars(struct wlan_objmgr_psoc *psoc,
78 				 struct reg_config_vars config_vars)
79 {
80 	return reg_set_config_vars(psoc, config_vars);
81 }
82 
83 bool ucfg_reg_is_regdb_offloaded(struct wlan_objmgr_psoc *psoc)
84 {
85 	return reg_is_regdb_offloaded(psoc);
86 }
87 
88 void ucfg_reg_program_mas_chan_list(struct wlan_objmgr_psoc *psoc,
89 				    struct regulatory_channel *reg_channels,
90 				    uint8_t *alpha2,
91 				    enum dfs_reg dfs_region)
92 {
93 	reg_program_mas_chan_list(psoc, reg_channels, alpha2, dfs_region);
94 }
95 
96 QDF_STATUS ucfg_reg_get_regd_rules(struct wlan_objmgr_pdev *pdev,
97 				   struct reg_rule_info *reg_rules)
98 {
99 	return reg_get_regd_rules(pdev, reg_rules);
100 }
101 
102 #ifdef WLAN_REG_PARTIAL_OFFLOAD
103 QDF_STATUS ucfg_reg_program_default_cc(struct wlan_objmgr_pdev *pdev,
104 				       uint16_t regdmn)
105 {
106 	return reg_program_default_cc(pdev, regdmn);
107 }
108 #endif
109 
110 QDF_STATUS ucfg_reg_program_cc(struct wlan_objmgr_pdev *pdev,
111 			       struct cc_regdmn_s *rd)
112 {
113 	return reg_program_chan_list(pdev, rd);
114 }
115 
116 QDF_STATUS ucfg_reg_get_current_cc(struct wlan_objmgr_pdev *pdev,
117 				   struct cc_regdmn_s *rd)
118 {
119 	return reg_get_current_cc(pdev, rd);
120 }
121 
122 #ifdef CONFIG_REG_CLIENT
123 
124 QDF_STATUS ucfg_reg_set_band(struct wlan_objmgr_pdev *pdev,
125 			     uint32_t band_bitmap)
126 {
127 	return reg_set_band(pdev, band_bitmap);
128 }
129 
130 QDF_STATUS ucfg_reg_get_band(struct wlan_objmgr_pdev *pdev,
131 			     uint32_t *band_bitmap)
132 {
133 	return reg_get_band(pdev, band_bitmap);
134 }
135 
136 /**
137  * ucfg_reg_notify_sap_event() - Notify regulatory domain for sap event
138  * @pdev: The physical dev to set the band for
139  * @sap_state: true for sap start else false
140  *
141  * Return: QDF_STATUS
142  */
143 QDF_STATUS ucfg_reg_notify_sap_event(struct wlan_objmgr_pdev *pdev,
144 			bool sap_state)
145 {
146 	return reg_notify_sap_event(pdev, sap_state);
147 }
148 
149 /**
150  * ucfg_reg_set_fcc_constraint() - apply fcc constraints on channels 12/13
151  * @pdev: The physical pdev to reduce tx power for
152  *
153  * This function adjusts the transmit power on channels 12 and 13, to comply
154  * with FCC regulations in the USA.
155  *
156  * Return: QDF_STATUS
157  */
158 QDF_STATUS ucfg_reg_set_fcc_constraint(struct wlan_objmgr_pdev *pdev,
159 				       bool fcc_constraint)
160 {
161 	return reg_set_fcc_constraint(pdev, fcc_constraint);
162 }
163 
164 QDF_STATUS ucfg_reg_get_current_country(struct wlan_objmgr_psoc *psoc,
165 					       uint8_t *country_code)
166 {
167 	return reg_read_current_country(psoc, country_code);
168 }
169 
170 /**
171  * ucfg_reg_set_default_country() - Set the default regulatory country
172  * @psoc: The physical SoC to set default country for
173  * @country: The country information to configure
174  *
175  * Return: QDF_STATUS
176  */
177 QDF_STATUS ucfg_reg_set_default_country(struct wlan_objmgr_psoc *psoc,
178 					uint8_t *country)
179 {
180 	return reg_set_default_country(psoc, country);
181 }
182 #endif
183 
184 /**
185  * ucfg_reg_get_default_country() - Get the default regulatory country
186  * @psoc: The physical SoC to get default country from
187  * @country_code: the buffer to populate the country code into
188  *
189  * Return: QDF_STATUS
190  */
191 QDF_STATUS ucfg_reg_get_default_country(struct wlan_objmgr_psoc *psoc,
192 					uint8_t *country_code)
193 {
194 	return reg_read_default_country(psoc, country_code);
195 }
196 
197 /**
198  * ucfg_reg_set_country() - Set the current regulatory country
199  * @pdev: The physical dev to set current country for
200  * @country: The country information to configure
201  *
202  * Return: QDF_STATUS
203  */
204 QDF_STATUS ucfg_reg_set_country(struct wlan_objmgr_pdev *pdev,
205 				uint8_t *country)
206 {
207 	return reg_set_country(pdev, country);
208 }
209 
210 /**
211  * ucfg_reg_reset_country() - Reset the regulatory country to default
212  * @psoc: The physical SoC to reset country for
213  *
214  * Return: QDF_STATUS
215  */
216 QDF_STATUS ucfg_reg_reset_country(struct wlan_objmgr_psoc *psoc)
217 {
218 	return reg_reset_country(psoc);
219 }
220 
221 /**
222  * ucfg_reg_enable_dfs_channels() - Enable the use of DFS channels
223  * @pdev: The physical dev to enable DFS channels for
224  *
225  * Return: QDF_STATUS
226  */
227 QDF_STATUS ucfg_reg_enable_dfs_channels(struct wlan_objmgr_pdev *pdev,
228 					bool dfs_enable)
229 {
230 	return reg_enable_dfs_channels(pdev, dfs_enable);
231 }
232 
233 void ucfg_reg_register_chan_change_callback(struct wlan_objmgr_psoc *psoc,
234 					    void *cbk, void *arg)
235 {
236 	reg_register_chan_change_callback(psoc, (reg_chan_change_callback)cbk,
237 					  arg);
238 }
239 
240 void ucfg_reg_unregister_chan_change_callback(struct wlan_objmgr_psoc *psoc,
241 					      void *cbk)
242 {
243 	reg_unregister_chan_change_callback(psoc,
244 					    (reg_chan_change_callback)cbk);
245 }
246 
247 #ifdef CONFIG_AFC_SUPPORT
248 QDF_STATUS ucfg_reg_register_afc_req_rx_callback(struct wlan_objmgr_pdev *pdev,
249 						 afc_req_rx_evt_handler cbf,
250 						 void *arg)
251 {
252 	return reg_register_afc_req_rx_callback(pdev, cbf, arg);
253 }
254 
255 qdf_export_symbol(ucfg_reg_register_afc_req_rx_callback);
256 
257 QDF_STATUS ucfg_reg_unregister_afc_req_rx_callback(struct wlan_objmgr_pdev *pdev,
258 						   afc_req_rx_evt_handler cbf)
259 {
260 	return reg_unregister_afc_req_rx_callback(pdev, cbf);
261 }
262 
263 QDF_STATUS
264 ucfg_reg_register_afc_power_event_callback(struct wlan_objmgr_pdev *pdev,
265 					   afc_power_tx_evt_handler cbf,
266 					   void *arg)
267 {
268 	return reg_register_afc_power_event_callback(pdev, cbf, arg);
269 }
270 
271 qdf_export_symbol(ucfg_reg_register_afc_power_event_callback);
272 
273 QDF_STATUS
274 ucfg_reg_unregister_afc_power_event_callback(struct wlan_objmgr_pdev *pdev,
275 					     afc_power_tx_evt_handler cbf)
276 {
277 	return reg_unregister_afc_power_event_callback(pdev, cbf);
278 }
279 
280 QDF_STATUS ucfg_reg_get_partial_afc_req_info(
281 		struct wlan_objmgr_pdev *pdev,
282 		struct wlan_afc_host_partial_request **afc_req,
283 		uint64_t req_id)
284 {
285 	QDF_STATUS status;
286 
287 	status = reg_get_partial_afc_req_info(pdev, afc_req);
288 
289 	if (!afc_req)
290 		return QDF_STATUS_E_NOMEM;
291 
292 	if (status == QDF_STATUS_SUCCESS)
293 		reg_dmn_set_afc_req_id(*afc_req, req_id);
294 
295 	return status;
296 }
297 #endif
298 
299 enum country_src ucfg_reg_get_cc_and_src(struct wlan_objmgr_psoc *psoc,
300 					 uint8_t *alpha2)
301 {
302 	return reg_get_cc_and_src(psoc, alpha2);
303 }
304 
305 void ucfg_reg_unit_simulate_ch_avoid(struct wlan_objmgr_psoc *psoc,
306 	struct ch_avoid_ind_type *ch_avoid)
307 {
308 	reg_process_ch_avoid_event(psoc, ch_avoid);
309 }
310 
311 void ucfg_reg_ch_avoid(struct wlan_objmgr_psoc *psoc,
312 		       struct ch_avoid_ind_type *ch_avoid)
313 {
314 	reg_process_ch_avoid_event(psoc, ch_avoid);
315 }
316 
317 #ifdef FEATURE_WLAN_CH_AVOID_EXT
318 void ucfg_reg_ch_avoid_ext(struct wlan_objmgr_psoc *psoc,
319 			   struct ch_avoid_ind_type *ch_avoid)
320 {
321 	reg_process_ch_avoid_ext_event(psoc, ch_avoid);
322 }
323 #endif
324 
325 QDF_STATUS ucfg_reg_11d_vdev_delete_update(struct wlan_objmgr_vdev *vdev)
326 {
327 	return reg_11d_vdev_delete_update(vdev);
328 }
329 
330 QDF_STATUS ucfg_reg_11d_vdev_created_update(struct wlan_objmgr_vdev *vdev)
331 {
332 	return reg_11d_vdev_created_update(vdev);
333 }
334 
335 struct wlan_psoc_host_hal_reg_capabilities_ext *ucfg_reg_get_hal_reg_cap(
336 				struct wlan_objmgr_psoc *psoc)
337 {
338 	return reg_get_hal_reg_cap(psoc);
339 }
340 qdf_export_symbol(ucfg_reg_get_hal_reg_cap);
341 
342 QDF_STATUS ucfg_reg_set_hal_reg_cap(struct wlan_objmgr_psoc *psoc,
343 		struct wlan_psoc_host_hal_reg_capabilities_ext *hal_reg_cap,
344 		uint16_t phy_cnt)
345 
346 {
347 	return reg_set_hal_reg_cap(psoc, hal_reg_cap, phy_cnt);
348 }
349 qdf_export_symbol(ucfg_reg_set_hal_reg_cap);
350 
351 QDF_STATUS ucfg_reg_update_hal_reg_cap(struct wlan_objmgr_psoc *psoc,
352 				       uint64_t wireless_modes, uint8_t phy_id)
353 {
354 	return reg_update_hal_reg_cap(psoc, wireless_modes, phy_id);
355 }
356 
357 qdf_export_symbol(ucfg_reg_update_hal_reg_cap);
358 
359 #ifdef DISABLE_CHANNEL_LIST
360 #ifdef CONFIG_CHAN_FREQ_API
361 /**
362  * ucfg_reg_cache_channel_freq_state() - Cache the current state of the channels
363  * based of the channel center frequency.
364  * @pdev: The physical dev to cache the channels for
365  * @channel_list: List of the channels for which states needs to be cached
366  * @num_channels: Number of channels in the list
367  *
368  */
369 void ucfg_reg_cache_channel_freq_state(struct wlan_objmgr_pdev *pdev,
370 				       uint32_t *channel_list,
371 				       uint32_t num_channels)
372 {
373 	reg_cache_channel_freq_state(pdev, channel_list, num_channels);
374 }
375 #endif /* CONFIG_CHAN_FREQ_API */
376 
377 void ucfg_reg_restore_cached_channels(struct wlan_objmgr_pdev *pdev)
378 {
379 	reg_restore_cached_channels(pdev);
380 }
381 
382 void ucfg_reg_disable_cached_channels(struct wlan_objmgr_pdev *pdev)
383 {
384 	reg_disable_cached_channels(pdev);
385 }
386 
387 #endif
388 
389 QDF_STATUS ucfg_set_ignore_fw_reg_offload_ind(struct wlan_objmgr_psoc *psoc)
390 {
391 	return reg_set_ignore_fw_reg_offload_ind(psoc);
392 }
393 
394 #ifdef DISABLE_UNII_SHARED_BANDS
395 QDF_STATUS
396 ucfg_reg_get_unii_5g_bitmap(struct wlan_objmgr_pdev *pdev, uint8_t *bitmap)
397 {
398 	return reg_get_unii_5g_bitmap(pdev, bitmap);
399 }
400 #endif
401 
402 #if defined(CONFIG_BAND_6GHZ)
403 QDF_STATUS
404 ucfg_reg_set_cur_6g_ap_pwr_type(struct wlan_objmgr_pdev *pdev,
405 				enum reg_6g_ap_type reg_cur_6g_ap_pwr_type)
406 {
407 	return reg_set_cur_6g_ap_pwr_type(pdev, reg_cur_6g_ap_pwr_type);
408 }
409 
410 QDF_STATUS
411 ucfg_reg_get_cur_6g_ap_pwr_type(struct wlan_objmgr_pdev *pdev,
412 				enum reg_6g_ap_type *reg_cur_6g_ap_pwr_type)
413 {
414 	return reg_get_cur_6g_ap_pwr_type(pdev, reg_cur_6g_ap_pwr_type);
415 }
416 
417 qdf_export_symbol(ucfg_reg_get_cur_6g_ap_pwr_type);
418 #endif
419 
420 #if defined(CONFIG_AFC_SUPPORT) && defined(CONFIG_BAND_6GHZ)
421 QDF_STATUS
422 ucfg_reg_send_afc_resp_rx_ind(struct wlan_objmgr_pdev *pdev,
423 			      struct reg_afc_resp_rx_ind_info *afc_ind_obj)
424 {
425 	return reg_send_afc_cmd(pdev, afc_ind_obj);
426 }
427 
428 QDF_STATUS
429 ucfg_reg_afc_start(struct wlan_objmgr_pdev *pdev, uint64_t req_id)
430 {
431 	return reg_afc_start(pdev, req_id);
432 }
433 #endif
434