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