xref: /wlan-driver/qca-wifi-host-cmn/target_if/regulatory/src/target_if_reg_11d.c (revision 5113495b16420b49004c444715d2daae2066e7dc)
1 /*
2  * Copyright (c) 2017-2020 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  * DOC: target_if_reg_11d.c
23  * This file contains regulatory target interface
24  */
25 
26 #include "target_if_reg_11d.h"
27 
28 #ifdef TARGET_11D_SCAN
tgt_if_regulatory_is_11d_offloaded(struct wlan_objmgr_psoc * psoc)29 bool tgt_if_regulatory_is_11d_offloaded(struct wlan_objmgr_psoc *psoc)
30 {
31 	wmi_unified_t wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
32 	struct wlan_lmac_if_reg_rx_ops *reg_rx_ops;
33 
34 	reg_rx_ops = target_if_regulatory_get_rx_ops(psoc);
35 
36 	if (!wmi_handle)
37 		return false;
38 
39 	if (reg_rx_ops && reg_rx_ops->reg_ignore_fw_reg_offload_ind &&
40 	    reg_rx_ops->reg_ignore_fw_reg_offload_ind(psoc)) {
41 		target_if_debug("Ignore fw reg 11d offload indication");
42 		return 0;
43 	}
44 
45 	return wmi_service_enabled(wmi_handle, wmi_service_11d_offload);
46 }
47 
48 /**
49  * tgt_reg_11d_new_cc_handler() - 11d country code event handler
50  * @handle: scn handle
51  * @event_buf: event buffer
52  * @len: length of @event_buf
53  *
54  * Return: 0 on success
55  */
tgt_reg_11d_new_cc_handler(ol_scn_t handle,uint8_t * event_buf,uint32_t len)56 static int tgt_reg_11d_new_cc_handler(ol_scn_t handle, uint8_t *event_buf,
57 				      uint32_t len)
58 {
59 	struct wlan_objmgr_psoc *psoc;
60 	struct wlan_lmac_if_reg_rx_ops *reg_rx_ops;
61 	struct reg_11d_new_country reg_11d_new_cc;
62 	QDF_STATUS status;
63 	struct wmi_unified *wmi_handle;
64 
65 	TARGET_IF_ENTER();
66 
67 	psoc = target_if_get_psoc_from_scn_hdl(handle);
68 	if (!psoc) {
69 		target_if_err("psoc ptr is NULL");
70 		return -EINVAL;
71 	}
72 
73 	reg_rx_ops = target_if_regulatory_get_rx_ops(psoc);
74 
75 	if (!reg_rx_ops || !reg_rx_ops->reg_11d_new_cc_handler) {
76 		target_if_err("reg_11d_new_cc_handler is NULL");
77 		return -EINVAL;
78 	}
79 
80 	wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
81 	if (!wmi_handle) {
82 		target_if_err("Invalid WMI handle");
83 		return -EINVAL;
84 	}
85 	if (wmi_extract_reg_11d_new_cc_event(wmi_handle, event_buf,
86 					     &reg_11d_new_cc, len)
87 	    != QDF_STATUS_SUCCESS) {
88 		target_if_err("Extraction of new country event failed");
89 		return -EFAULT;
90 	}
91 
92 	status = reg_rx_ops->reg_11d_new_cc_handler(psoc, &reg_11d_new_cc);
93 	if (status != QDF_STATUS_SUCCESS) {
94 		target_if_err("Failed to process new country code event");
95 		return -EFAULT;
96 	}
97 
98 	target_if_debug("processed 11d new country code event");
99 
100 	return 0;
101 }
102 
tgt_if_regulatory_register_11d_new_cc_handler(struct wlan_objmgr_psoc * psoc,void * arg)103 QDF_STATUS tgt_if_regulatory_register_11d_new_cc_handler(
104 	struct wlan_objmgr_psoc *psoc, void *arg)
105 {
106 	wmi_unified_t wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
107 
108 	if (!wmi_handle)
109 		return QDF_STATUS_E_FAILURE;
110 
111 	return wmi_unified_register_event(wmi_handle,
112 					  wmi_11d_new_country_event_id,
113 					  tgt_reg_11d_new_cc_handler);
114 }
115 
tgt_if_regulatory_unregister_11d_new_cc_handler(struct wlan_objmgr_psoc * psoc,void * arg)116 QDF_STATUS tgt_if_regulatory_unregister_11d_new_cc_handler(
117 	struct wlan_objmgr_psoc *psoc, void *arg)
118 {
119 	wmi_unified_t wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
120 
121 	if (!wmi_handle)
122 		return QDF_STATUS_E_FAILURE;
123 
124 	return wmi_unified_unregister_event(wmi_handle,
125 					    wmi_11d_new_country_event_id);
126 }
127 
tgt_if_regulatory_start_11d_scan(struct wlan_objmgr_psoc * psoc,struct reg_start_11d_scan_req * reg_start_11d_scan_req)128 QDF_STATUS tgt_if_regulatory_start_11d_scan(
129 		struct wlan_objmgr_psoc *psoc,
130 		struct reg_start_11d_scan_req *reg_start_11d_scan_req)
131 {
132 	wmi_unified_t wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
133 
134 	if (!wmi_handle)
135 		return QDF_STATUS_E_FAILURE;
136 
137 	return wmi_unified_send_start_11d_scan_cmd(wmi_handle,
138 						   reg_start_11d_scan_req);
139 }
140 
tgt_if_regulatory_stop_11d_scan(struct wlan_objmgr_psoc * psoc,struct reg_stop_11d_scan_req * reg_stop_11d_scan_req)141 QDF_STATUS tgt_if_regulatory_stop_11d_scan(
142 		   struct wlan_objmgr_psoc *psoc,
143 		   struct reg_stop_11d_scan_req *reg_stop_11d_scan_req)
144 {
145 	wmi_unified_t wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
146 
147 	if (!wmi_handle)
148 		return QDF_STATUS_E_FAILURE;
149 
150 	return wmi_unified_send_stop_11d_scan_cmd(wmi_handle,
151 						  reg_stop_11d_scan_req);
152 }
153 #endif
154