xref: /wlan-driver/qca-wifi-host-cmn/target_if/regulatory/src/target_if_reg_lte.c (revision 5113495b16420b49004c444715d2daae2066e7dc)
1 /*
2  * Copyright (c) 2017-2021 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  */
tgt_reg_ch_avoid_event_handler(ol_scn_t handle,uint8_t * event_buf,uint32_t len)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 	if (!reg_rx_ops) {
56 		target_if_err("reg_rx_ops is NULL");
57 		return -EINVAL;
58 	}
59 
60 	if (!reg_rx_ops->reg_ch_avoid_event_handler) {
61 		target_if_err("reg_ch_avoid_event_handler is NULL");
62 		return -EINVAL;
63 	}
64 
65 	wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
66 	if (!wmi_handle) {
67 		target_if_err("Invalid WMI handle");
68 		return -EINVAL;
69 	}
70 
71 	if (wmi_extract_reg_ch_avoid_event(
72 				wmi_handle, event_buf, &ch_avoid_event, len)
73 	    != QDF_STATUS_SUCCESS) {
74 		target_if_err("Extraction of CH avoid event failed");
75 		return -EFAULT;
76 	}
77 
78 	status = reg_rx_ops->reg_ch_avoid_event_handler(psoc, &ch_avoid_event);
79 	if (status != QDF_STATUS_SUCCESS) {
80 		target_if_err("Failed to process CH avoid event");
81 		return -EFAULT;
82 	}
83 
84 	TARGET_IF_EXIT();
85 
86 	return 0;
87 }
88 
tgt_if_regulatory_register_ch_avoid_event_handler(struct wlan_objmgr_psoc * psoc,void * arg)89 QDF_STATUS tgt_if_regulatory_register_ch_avoid_event_handler(
90 	struct wlan_objmgr_psoc *psoc, void *arg)
91 {
92 	wmi_unified_t wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
93 
94 	if (!wmi_handle)
95 		return QDF_STATUS_E_FAILURE;
96 
97 	return wmi_unified_register_event(wmi_handle,
98 					  wmi_wlan_freq_avoid_event_id,
99 					  tgt_reg_ch_avoid_event_handler);
100 }
101 
tgt_if_regulatory_unregister_ch_avoid_event_handler(struct wlan_objmgr_psoc * psoc,void * arg)102 QDF_STATUS tgt_if_regulatory_unregister_ch_avoid_event_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_unregister_event(wmi_handle,
111 			wmi_wlan_freq_avoid_event_id);
112 }
113 #endif
114