1 /*
2 * Copyright (c) 2017-2020 The Linux Foundation. All rights reserved.
3 *
4 * Permission to use, copy, modify, and/or distribute this software for
5 * any purpose with or without fee is hereby granted, provided that the
6 * above copyright notice and this permission notice appear in all
7 * copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 * PERFORMANCE OF THIS SOFTWARE.
17 */
18
19 /**
20 * DOC: offload lmac interface APIs for tdls
21 *
22 */
23
24 #include <qdf_mem.h>
25 #include <target_if.h>
26 #include <qdf_status.h>
27 #include <wmi_unified_api.h>
28 #include <wmi_unified_priv.h>
29 #include <wmi_unified_param.h>
30 #include <wlan_objmgr_psoc_obj.h>
31 #include <wlan_tdls_tgt_api.h>
32 #include <target_if_tdls.h>
33 #include <cdp_txrx_peer_ops.h>
34 #include <wlan_utility.h>
35
36 static inline struct wlan_lmac_if_tdls_rx_ops *
target_if_tdls_get_rx_ops(struct wlan_objmgr_psoc * psoc)37 target_if_tdls_get_rx_ops(struct wlan_objmgr_psoc *psoc)
38 {
39 return &psoc->soc_cb.rx_ops->tdls_rx_ops;
40 }
41
42 static int
target_if_tdls_event_handler(ol_scn_t scn,uint8_t * data,uint32_t datalen)43 target_if_tdls_event_handler(ol_scn_t scn, uint8_t *data, uint32_t datalen)
44 {
45 struct wlan_objmgr_psoc *psoc;
46 struct wmi_unified *wmi_handle;
47 struct wlan_lmac_if_tdls_rx_ops *tdls_rx_ops;
48 struct tdls_event_info info;
49 QDF_STATUS status;
50
51 if (!scn || !data) {
52 target_if_err("scn: 0x%pK, data: 0x%pK", scn, data);
53 return -EINVAL;
54 }
55 psoc = target_if_get_psoc_from_scn_hdl(scn);
56 if (!psoc) {
57 target_if_err("null psoc");
58 return -EINVAL;
59 }
60 wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
61
62 if (!wmi_handle) {
63 target_if_err("null wmi_handle");
64 return -EINVAL;
65 }
66
67 if (wmi_extract_vdev_tdls_ev_param(wmi_handle, data, &info)) {
68 target_if_err("Failed to extract wmi tdls event");
69 return -EINVAL;
70 }
71
72 tdls_rx_ops = target_if_tdls_get_rx_ops(psoc);
73 if (tdls_rx_ops && tdls_rx_ops->tdls_ev_handler) {
74 status = tdls_rx_ops->tdls_ev_handler(psoc, &info);
75 if (QDF_IS_STATUS_ERROR(status)) {
76 target_if_err("fail to handle tdls event");
77 return -EINVAL;
78 }
79 }
80
81 return 0;
82 }
83
84 QDF_STATUS
target_if_tdls_update_fw_state(struct wlan_objmgr_psoc * psoc,struct tdls_info * param)85 target_if_tdls_update_fw_state(struct wlan_objmgr_psoc *psoc,
86 struct tdls_info *param)
87 {
88 QDF_STATUS status;
89 enum wmi_tdls_state tdls_state;
90 struct wmi_unified *wmi_handle;
91
92 wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
93 if (!wmi_handle) {
94 target_if_err("Invalid WMI handle");
95 return QDF_STATUS_E_FAILURE;
96 }
97
98 if (TDLS_SUPPORT_EXP_TRIG_ONLY == param->tdls_state)
99 tdls_state = WMI_TDLS_ENABLE_PASSIVE;
100 else if (TDLS_SUPPORT_IMP_MODE == param->tdls_state ||
101 TDLS_SUPPORT_EXT_CONTROL == param->tdls_state)
102 tdls_state = WMI_TDLS_ENABLE_CONNECTION_TRACKER_IN_HOST;
103 else
104 tdls_state = WMI_TDLS_DISABLE;
105
106 status = wmi_unified_update_fw_tdls_state_cmd(wmi_handle,
107 param, tdls_state);
108
109 target_if_debug("vdev_id %d", param->vdev_id);
110 return status;
111 }
112
113 QDF_STATUS
target_if_tdls_update_peer_state(struct wlan_objmgr_psoc * psoc,struct tdls_peer_update_state * peer_params)114 target_if_tdls_update_peer_state(struct wlan_objmgr_psoc *psoc,
115 struct tdls_peer_update_state *peer_params)
116 {
117 return QDF_STATUS_SUCCESS;
118 }
119
120 QDF_STATUS
target_if_tdls_set_offchan_mode(struct wlan_objmgr_psoc * psoc,struct tdls_channel_switch_params * params)121 target_if_tdls_set_offchan_mode(struct wlan_objmgr_psoc *psoc,
122 struct tdls_channel_switch_params *params)
123 {
124 QDF_STATUS status;
125 struct wmi_unified *wmi_handle;
126
127 wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
128 if (!wmi_handle) {
129 target_if_err("Invalid WMI handle");
130 return QDF_STATUS_E_FAILURE;
131 }
132 status = wmi_unified_set_tdls_offchan_mode_cmd(wmi_handle,
133 params);
134
135 return status;
136 }
137
138 QDF_STATUS
target_if_tdls_register_event_handler(struct wlan_objmgr_psoc * psoc,void * arg)139 target_if_tdls_register_event_handler(struct wlan_objmgr_psoc *psoc,
140 void *arg)
141 {
142 struct wmi_unified *wmi_handle;
143
144 wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
145 if (!wmi_handle) {
146 target_if_err("null wmi_handle");
147 return QDF_STATUS_E_INVAL;
148 }
149 return wmi_unified_register_event(wmi_handle,
150 wmi_tdls_peer_event_id,
151 target_if_tdls_event_handler);
152 }
153
154 QDF_STATUS
target_if_tdls_unregister_event_handler(struct wlan_objmgr_psoc * psoc,void * arg)155 target_if_tdls_unregister_event_handler(struct wlan_objmgr_psoc *psoc,
156 void *arg)
157 {
158 struct wmi_unified *wmi_handle;
159
160 wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
161 if (!wmi_handle) {
162 target_if_err("null wmi_handle");
163 return QDF_STATUS_E_INVAL;
164 }
165 return wmi_unified_unregister_event(wmi_handle,
166 wmi_tdls_peer_event_id);
167 }
168
169 QDF_STATUS
target_if_tdls_register_tx_ops(struct wlan_lmac_if_tx_ops * tx_ops)170 target_if_tdls_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
171 {
172 struct wlan_lmac_if_tdls_tx_ops *tdls_txops;
173
174 tdls_txops = &tx_ops->tdls_tx_ops;
175
176 tdls_txops->update_fw_state = target_if_tdls_update_fw_state;
177 tdls_txops->update_peer_state = target_if_tdls_update_peer_state;
178 tdls_txops->set_offchan_mode = target_if_tdls_set_offchan_mode;
179 tdls_txops->tdls_reg_ev_handler = target_if_tdls_register_event_handler;
180 tdls_txops->tdls_unreg_ev_handler =
181 target_if_tdls_unregister_event_handler;
182
183 return QDF_STATUS_SUCCESS;
184 }
185