xref: /wlan-driver/qca-wifi-host-cmn/target_if/regulatory/src/target_if_reg_11d.c (revision 5113495b16420b49004c444715d2daae2066e7dc)
1*5113495bSYour Name /*
2*5113495bSYour Name  * Copyright (c) 2017-2020 The Linux Foundation. All rights reserved.
3*5113495bSYour Name  * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
4*5113495bSYour Name  *
5*5113495bSYour Name  *
6*5113495bSYour Name  * Permission to use, copy, modify, and/or distribute this software for
7*5113495bSYour Name  * any purpose with or without fee is hereby granted, provided that the
8*5113495bSYour Name  * above copyright notice and this permission notice appear in all
9*5113495bSYour Name  * copies.
10*5113495bSYour Name  *
11*5113495bSYour Name  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
12*5113495bSYour Name  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
13*5113495bSYour Name  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
14*5113495bSYour Name  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
15*5113495bSYour Name  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
16*5113495bSYour Name  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
17*5113495bSYour Name  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
18*5113495bSYour Name  * PERFORMANCE OF THIS SOFTWARE.
19*5113495bSYour Name  */
20*5113495bSYour Name 
21*5113495bSYour Name /**
22*5113495bSYour Name  * DOC: target_if_reg_11d.c
23*5113495bSYour Name  * This file contains regulatory target interface
24*5113495bSYour Name  */
25*5113495bSYour Name 
26*5113495bSYour Name #include "target_if_reg_11d.h"
27*5113495bSYour Name 
28*5113495bSYour Name #ifdef TARGET_11D_SCAN
tgt_if_regulatory_is_11d_offloaded(struct wlan_objmgr_psoc * psoc)29*5113495bSYour Name bool tgt_if_regulatory_is_11d_offloaded(struct wlan_objmgr_psoc *psoc)
30*5113495bSYour Name {
31*5113495bSYour Name 	wmi_unified_t wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
32*5113495bSYour Name 	struct wlan_lmac_if_reg_rx_ops *reg_rx_ops;
33*5113495bSYour Name 
34*5113495bSYour Name 	reg_rx_ops = target_if_regulatory_get_rx_ops(psoc);
35*5113495bSYour Name 
36*5113495bSYour Name 	if (!wmi_handle)
37*5113495bSYour Name 		return false;
38*5113495bSYour Name 
39*5113495bSYour Name 	if (reg_rx_ops && reg_rx_ops->reg_ignore_fw_reg_offload_ind &&
40*5113495bSYour Name 	    reg_rx_ops->reg_ignore_fw_reg_offload_ind(psoc)) {
41*5113495bSYour Name 		target_if_debug("Ignore fw reg 11d offload indication");
42*5113495bSYour Name 		return 0;
43*5113495bSYour Name 	}
44*5113495bSYour Name 
45*5113495bSYour Name 	return wmi_service_enabled(wmi_handle, wmi_service_11d_offload);
46*5113495bSYour Name }
47*5113495bSYour Name 
48*5113495bSYour Name /**
49*5113495bSYour Name  * tgt_reg_11d_new_cc_handler() - 11d country code event handler
50*5113495bSYour Name  * @handle: scn handle
51*5113495bSYour Name  * @event_buf: event buffer
52*5113495bSYour Name  * @len: length of @event_buf
53*5113495bSYour Name  *
54*5113495bSYour Name  * Return: 0 on success
55*5113495bSYour Name  */
tgt_reg_11d_new_cc_handler(ol_scn_t handle,uint8_t * event_buf,uint32_t len)56*5113495bSYour Name static int tgt_reg_11d_new_cc_handler(ol_scn_t handle, uint8_t *event_buf,
57*5113495bSYour Name 				      uint32_t len)
58*5113495bSYour Name {
59*5113495bSYour Name 	struct wlan_objmgr_psoc *psoc;
60*5113495bSYour Name 	struct wlan_lmac_if_reg_rx_ops *reg_rx_ops;
61*5113495bSYour Name 	struct reg_11d_new_country reg_11d_new_cc;
62*5113495bSYour Name 	QDF_STATUS status;
63*5113495bSYour Name 	struct wmi_unified *wmi_handle;
64*5113495bSYour Name 
65*5113495bSYour Name 	TARGET_IF_ENTER();
66*5113495bSYour Name 
67*5113495bSYour Name 	psoc = target_if_get_psoc_from_scn_hdl(handle);
68*5113495bSYour Name 	if (!psoc) {
69*5113495bSYour Name 		target_if_err("psoc ptr is NULL");
70*5113495bSYour Name 		return -EINVAL;
71*5113495bSYour Name 	}
72*5113495bSYour Name 
73*5113495bSYour Name 	reg_rx_ops = target_if_regulatory_get_rx_ops(psoc);
74*5113495bSYour Name 
75*5113495bSYour Name 	if (!reg_rx_ops || !reg_rx_ops->reg_11d_new_cc_handler) {
76*5113495bSYour Name 		target_if_err("reg_11d_new_cc_handler is NULL");
77*5113495bSYour Name 		return -EINVAL;
78*5113495bSYour Name 	}
79*5113495bSYour Name 
80*5113495bSYour Name 	wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
81*5113495bSYour Name 	if (!wmi_handle) {
82*5113495bSYour Name 		target_if_err("Invalid WMI handle");
83*5113495bSYour Name 		return -EINVAL;
84*5113495bSYour Name 	}
85*5113495bSYour Name 	if (wmi_extract_reg_11d_new_cc_event(wmi_handle, event_buf,
86*5113495bSYour Name 					     &reg_11d_new_cc, len)
87*5113495bSYour Name 	    != QDF_STATUS_SUCCESS) {
88*5113495bSYour Name 		target_if_err("Extraction of new country event failed");
89*5113495bSYour Name 		return -EFAULT;
90*5113495bSYour Name 	}
91*5113495bSYour Name 
92*5113495bSYour Name 	status = reg_rx_ops->reg_11d_new_cc_handler(psoc, &reg_11d_new_cc);
93*5113495bSYour Name 	if (status != QDF_STATUS_SUCCESS) {
94*5113495bSYour Name 		target_if_err("Failed to process new country code event");
95*5113495bSYour Name 		return -EFAULT;
96*5113495bSYour Name 	}
97*5113495bSYour Name 
98*5113495bSYour Name 	target_if_debug("processed 11d new country code event");
99*5113495bSYour Name 
100*5113495bSYour Name 	return 0;
101*5113495bSYour Name }
102*5113495bSYour Name 
tgt_if_regulatory_register_11d_new_cc_handler(struct wlan_objmgr_psoc * psoc,void * arg)103*5113495bSYour Name QDF_STATUS tgt_if_regulatory_register_11d_new_cc_handler(
104*5113495bSYour Name 	struct wlan_objmgr_psoc *psoc, void *arg)
105*5113495bSYour Name {
106*5113495bSYour Name 	wmi_unified_t wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
107*5113495bSYour Name 
108*5113495bSYour Name 	if (!wmi_handle)
109*5113495bSYour Name 		return QDF_STATUS_E_FAILURE;
110*5113495bSYour Name 
111*5113495bSYour Name 	return wmi_unified_register_event(wmi_handle,
112*5113495bSYour Name 					  wmi_11d_new_country_event_id,
113*5113495bSYour Name 					  tgt_reg_11d_new_cc_handler);
114*5113495bSYour Name }
115*5113495bSYour Name 
tgt_if_regulatory_unregister_11d_new_cc_handler(struct wlan_objmgr_psoc * psoc,void * arg)116*5113495bSYour Name QDF_STATUS tgt_if_regulatory_unregister_11d_new_cc_handler(
117*5113495bSYour Name 	struct wlan_objmgr_psoc *psoc, void *arg)
118*5113495bSYour Name {
119*5113495bSYour Name 	wmi_unified_t wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
120*5113495bSYour Name 
121*5113495bSYour Name 	if (!wmi_handle)
122*5113495bSYour Name 		return QDF_STATUS_E_FAILURE;
123*5113495bSYour Name 
124*5113495bSYour Name 	return wmi_unified_unregister_event(wmi_handle,
125*5113495bSYour Name 					    wmi_11d_new_country_event_id);
126*5113495bSYour Name }
127*5113495bSYour Name 
tgt_if_regulatory_start_11d_scan(struct wlan_objmgr_psoc * psoc,struct reg_start_11d_scan_req * reg_start_11d_scan_req)128*5113495bSYour Name QDF_STATUS tgt_if_regulatory_start_11d_scan(
129*5113495bSYour Name 		struct wlan_objmgr_psoc *psoc,
130*5113495bSYour Name 		struct reg_start_11d_scan_req *reg_start_11d_scan_req)
131*5113495bSYour Name {
132*5113495bSYour Name 	wmi_unified_t wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
133*5113495bSYour Name 
134*5113495bSYour Name 	if (!wmi_handle)
135*5113495bSYour Name 		return QDF_STATUS_E_FAILURE;
136*5113495bSYour Name 
137*5113495bSYour Name 	return wmi_unified_send_start_11d_scan_cmd(wmi_handle,
138*5113495bSYour Name 						   reg_start_11d_scan_req);
139*5113495bSYour Name }
140*5113495bSYour Name 
tgt_if_regulatory_stop_11d_scan(struct wlan_objmgr_psoc * psoc,struct reg_stop_11d_scan_req * reg_stop_11d_scan_req)141*5113495bSYour Name QDF_STATUS tgt_if_regulatory_stop_11d_scan(
142*5113495bSYour Name 		   struct wlan_objmgr_psoc *psoc,
143*5113495bSYour Name 		   struct reg_stop_11d_scan_req *reg_stop_11d_scan_req)
144*5113495bSYour Name {
145*5113495bSYour Name 	wmi_unified_t wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
146*5113495bSYour Name 
147*5113495bSYour Name 	if (!wmi_handle)
148*5113495bSYour Name 		return QDF_STATUS_E_FAILURE;
149*5113495bSYour Name 
150*5113495bSYour Name 	return wmi_unified_send_stop_11d_scan_cmd(wmi_handle,
151*5113495bSYour Name 						  reg_stop_11d_scan_req);
152*5113495bSYour Name }
153*5113495bSYour Name #endif
154