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