xref: /wlan-dirver/qca-wifi-host-cmn/target_if/regulatory/src/target_if_reg_lte.c (revision 1397a33f48ea6455be40871470b286e535820eb8)
1 /*
2  * Copyright (c) 2017-2019 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_lte.c
22  * This file contains regulatory target LTE interface
23  */
24 
25 #include "target_if_reg_lte.h"
26 
27 /**
28  * tgt_reg_ch_avoid_event_handler() - Avoid channel list event handler.
29  * @handle: Pointer to scn handler.
30  * @event_buf: Pointer to event buffer.
31  * @len: Buffer length.
32  *
33  * Return: Error code.
34  */
35 static int tgt_reg_ch_avoid_event_handler(ol_scn_t handle, uint8_t *event_buf,
36 					  uint32_t len)
37 {
38 	struct wlan_objmgr_psoc *psoc;
39 	struct wlan_lmac_if_reg_rx_ops *reg_rx_ops;
40 	struct ch_avoid_ind_type ch_avoid_event;
41 	QDF_STATUS status;
42 	struct wmi_unified *wmi_handle;
43 
44 	TARGET_IF_ENTER();
45 
46 	psoc = target_if_get_psoc_from_scn_hdl(handle);
47 	if (!psoc) {
48 		target_if_err("psoc ptr is NULL");
49 		return -EINVAL;
50 	}
51 
52 	reg_rx_ops = target_if_regulatory_get_rx_ops(psoc);
53 
54 	if (!reg_rx_ops->reg_ch_avoid_event_handler) {
55 		target_if_err("reg_ch_avoid_event_handler is NULL");
56 		return -EINVAL;
57 	}
58 
59 	wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
60 	if (!wmi_handle) {
61 		target_if_err("Invalid WMI handle");
62 		return -EINVAL;
63 	}
64 
65 	if (wmi_extract_reg_ch_avoid_event(
66 				wmi_handle, event_buf, &ch_avoid_event, len)
67 	    != QDF_STATUS_SUCCESS) {
68 		target_if_err("Extraction of CH avoid event failed");
69 		return -EFAULT;
70 	}
71 
72 	status = reg_rx_ops->reg_ch_avoid_event_handler(psoc, &ch_avoid_event);
73 	if (status != QDF_STATUS_SUCCESS) {
74 		target_if_err("Failed to process CH avoid event");
75 		return -EFAULT;
76 	}
77 
78 	target_if_debug("processed CH avoid event");
79 
80 	return 0;
81 }
82 
83 QDF_STATUS tgt_if_regulatory_register_ch_avoid_event_handler(
84 	struct wlan_objmgr_psoc *psoc, void *arg)
85 {
86 	wmi_unified_t wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
87 
88 	if (!wmi_handle)
89 		return QDF_STATUS_E_FAILURE;
90 
91 	return wmi_unified_register_event(wmi_handle,
92 					  wmi_wlan_freq_avoid_event_id,
93 					  tgt_reg_ch_avoid_event_handler);
94 }
95 
96 QDF_STATUS tgt_if_regulatory_unregister_ch_avoid_event_handler(
97 	struct wlan_objmgr_psoc *psoc, void *arg)
98 {
99 	wmi_unified_t wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
100 
101 	if (!wmi_handle)
102 		return QDF_STATUS_E_FAILURE;
103 
104 	return wmi_unified_unregister_event(wmi_handle,
105 			wmi_wlan_freq_avoid_event_id);
106 }
107