xref: /wlan-driver/qca-wifi-host-cmn/wmi/src/wmi_unified_action_oui_tlv.c (revision 5113495b16420b49004c444715d2daae2066e7dc) !
1 /*
2  * Copyright (c) 2016-2018, 2020 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
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 #include "wmi_unified_action_oui_tlv.h"
21 #include "wmi_unified_priv.h"
22 
wmi_get_action_oui_id(enum action_oui_id action_id,wmi_vendor_oui_action_id * id)23 bool wmi_get_action_oui_id(enum action_oui_id action_id,
24 			   wmi_vendor_oui_action_id *id)
25 {
26 	switch (action_id) {
27 
28 	case ACTION_OUI_CONNECT_1X1:
29 		*id = WMI_VENDOR_OUI_ACTION_CONNECTION_1X1;
30 		return true;
31 
32 	case ACTION_OUI_ITO_EXTENSION:
33 		*id = WMI_VENDOR_OUI_ACTION_ITO_EXTENSION;
34 		return true;
35 
36 	case ACTION_OUI_CCKM_1X1:
37 		*id = WMI_VENDOR_OUI_ACTION_CCKM_1X1;
38 		return true;
39 
40 	case ACTION_OUI_ITO_ALTERNATE:
41 		*id = WMI_VENDOR_OUI_ACTION_ALT_ITO;
42 		return true;
43 
44 	case ACTION_OUI_SWITCH_TO_11N_MODE:
45 		*id = WMI_VENDOR_OUI_ACTION_SWITCH_TO_11N_MODE;
46 		return true;
47 
48 	case ACTION_OUI_CONNECT_1X1_WITH_1_CHAIN:
49 		*id = WMI_VENDOR_OUI_ACTION_CONNECTION_1X1_NUM_TX_RX_CHAINS_1;
50 		return true;
51 
52 	case ACTION_OUI_DISABLE_AGGRESSIVE_TX:
53 		*id = WMI_VENDOR_OUI_ACTION_DISABLE_AGGRESSIVE_TX;
54 		return true;
55 
56 	case ACTION_OUI_DISABLE_TWT:
57 		*id = WMI_VENDOR_OUI_ACTION_DISABLE_FW_TRIGGERED_TWT;
58 		return true;
59 
60 	case ACTION_OUI_EXTEND_WOW_ITO:
61 		*id = WMI_VENDOR_OUI_ACTION_EXTEND_WOW_ITO;
62 		return true;
63 	case ACTION_OUI_11BE_OUI_ALLOW:
64 		*id = WMI_VENDOR_OUI_ACTION_ALLOW_11BE;
65 		return true;
66 	case ACTION_OUI_DISABLE_DYNAMIC_QOS_NULL_TX_RATE:
67 		*id = WMI_VENDOR_OUI_ACTION_DISABLE_DYNAMIC_QOS_NULL_TX_RATE;
68 		return true;
69 	case ACTION_OUI_ENABLE_CTS2SELF_WITH_QOS_NULL:
70 		*id = WMI_VENDOR_OUI_ACTION_ENABLE_CTS2SELF_WITH_QOS_NULL;
71 		return true;
72 	case ACTION_OUI_SEND_SMPS_FRAME_WITH_OMN:
73 		*id = WMI_VENDOR_OUI_ACTION_SEND_SMPS_FRAME_WITH_OMN;
74 		return true;
75 	default:
76 		return false;
77 	}
78 }
79 
wmi_get_action_oui_info_mask(uint32_t info_mask)80 uint32_t wmi_get_action_oui_info_mask(uint32_t info_mask)
81 {
82 	uint32_t info_presence = 0;
83 
84 	if (info_mask & ACTION_OUI_INFO_OUI)
85 		info_presence |= WMI_BEACON_INFO_PRESENCE_OUI_EXT;
86 
87 	if (info_mask & ACTION_OUI_INFO_MAC_ADDRESS)
88 		info_presence |= WMI_BEACON_INFO_PRESENCE_MAC_ADDRESS;
89 
90 	if (info_mask & ACTION_OUI_INFO_AP_CAPABILITY_NSS)
91 		info_presence |= WMI_BEACON_INFO_PRESENCE_AP_CAPABILITY_NSS;
92 
93 	if (info_mask & ACTION_OUI_INFO_AP_CAPABILITY_HT)
94 		info_presence |= WMI_BEACON_INFO_PRESENCE_AP_CAPABILITY_HT;
95 
96 	if (info_mask & ACTION_OUI_INFO_AP_CAPABILITY_VHT)
97 		info_presence |= WMI_BEACON_INFO_PRESENCE_AP_CAPABILITY_VHT;
98 
99 	if (info_mask & ACTION_OUI_INFO_AP_CAPABILITY_BAND)
100 		info_presence |= WMI_BEACON_INFO_PRESENCE_AP_CAPABILITY_BAND;
101 
102 	return info_presence;
103 }
104 
wmi_fill_oui_extensions(struct action_oui_extension * extension,uint32_t no_oui_extns,wmi_vendor_oui_ext * cmd_ext)105 void wmi_fill_oui_extensions(struct action_oui_extension *extension,
106 			     uint32_t no_oui_extns,
107 			     wmi_vendor_oui_ext *cmd_ext)
108 {
109 	uint32_t i;
110 	uint32_t buffer_length;
111 
112 	for (i = 0; i < no_oui_extns; i++) {
113 		WMITLV_SET_HDR(&cmd_ext->tlv_header,
114 			       WMITLV_TAG_STRUC_wmi_vendor_oui_ext,
115 			       WMITLV_GET_STRUCT_TLVLEN(wmi_vendor_oui_ext));
116 		cmd_ext->info_presence_bit_mask =
117 			wmi_get_action_oui_info_mask(extension->info_mask);
118 
119 		cmd_ext->oui_header_length = extension->oui_length;
120 		cmd_ext->oui_data_length = extension->data_length;
121 		cmd_ext->mac_address_length = extension->mac_addr_length;
122 		cmd_ext->capability_data_length =
123 					extension->capability_length;
124 
125 		buffer_length = extension->oui_length +
126 				extension->data_length +
127 				extension->data_mask_length +
128 				extension->mac_addr_length +
129 				extension->mac_mask_length +
130 				extension->capability_length;
131 
132 		cmd_ext->buf_data_length = buffer_length + 1;
133 
134 		cmd_ext++;
135 		extension++;
136 	}
137 
138 }
139 
140 QDF_STATUS
wmi_fill_oui_extensions_buffer(struct action_oui_extension * extension,wmi_vendor_oui_ext * cmd_ext,uint32_t no_oui_extns,uint32_t rem_var_buf_len,uint8_t * var_buf)141 wmi_fill_oui_extensions_buffer(struct action_oui_extension *extension,
142 			       wmi_vendor_oui_ext *cmd_ext,
143 			       uint32_t no_oui_extns, uint32_t rem_var_buf_len,
144 			       uint8_t *var_buf)
145 {
146 	uint8_t i;
147 
148 	for (i = 0; i < (uint8_t)no_oui_extns; i++) {
149 		if ((rem_var_buf_len - cmd_ext->buf_data_length) < 0) {
150 			wmi_err("Invalid action oui command length");
151 			return QDF_STATUS_E_INVAL;
152 		}
153 
154 		var_buf[0] = i;
155 		var_buf++;
156 
157 		if (extension->oui_length) {
158 			qdf_mem_copy(var_buf, extension->oui,
159 				     extension->oui_length);
160 			var_buf += extension->oui_length;
161 		}
162 
163 		if (extension->data_length) {
164 			qdf_mem_copy(var_buf, extension->data,
165 				     extension->data_length);
166 			var_buf += extension->data_length;
167 		}
168 
169 		if (extension->data_mask_length) {
170 			qdf_mem_copy(var_buf, extension->data_mask,
171 				     extension->data_mask_length);
172 			var_buf += extension->data_mask_length;
173 		}
174 
175 		if (extension->mac_addr_length) {
176 			qdf_mem_copy(var_buf, extension->mac_addr,
177 				     extension->mac_addr_length);
178 			var_buf += extension->mac_addr_length;
179 		}
180 
181 		if (extension->mac_mask_length) {
182 			qdf_mem_copy(var_buf, extension->mac_mask,
183 				     extension->mac_mask_length);
184 			var_buf += extension->mac_mask_length;
185 		}
186 
187 		if (extension->capability_length) {
188 			qdf_mem_copy(var_buf, extension->capability,
189 				     extension->capability_length);
190 			var_buf += extension->capability_length;
191 		}
192 
193 		rem_var_buf_len -= cmd_ext->buf_data_length;
194 		cmd_ext++;
195 		extension++;
196 	}
197 
198 	return QDF_STATUS_SUCCESS;
199 }
200 
201 QDF_STATUS
send_action_oui_cmd_tlv(wmi_unified_t wmi_handle,struct action_oui_request * req)202 send_action_oui_cmd_tlv(wmi_unified_t wmi_handle,
203 			struct action_oui_request *req)
204 {
205 	wmi_pdev_config_vendor_oui_action_fixed_param *cmd;
206 	wmi_vendor_oui_ext *cmd_ext;
207 	wmi_buf_t wmi_buf;
208 	struct action_oui_extension *extension;
209 	uint32_t len;
210 	uint32_t i;
211 	uint8_t *buf_ptr;
212 	uint32_t no_oui_extns;
213 	uint32_t total_no_oui_extns;
214 	uint32_t var_buf_len = 0;
215 	wmi_vendor_oui_action_id action_id;
216 	bool valid;
217 	uint32_t rem_var_buf_len;
218 	QDF_STATUS status;
219 
220 	if (!req) {
221 		wmi_err("action oui is empty");
222 		return QDF_STATUS_E_INVAL;
223 	}
224 
225 	no_oui_extns = req->no_oui_extensions;
226 	total_no_oui_extns = req->total_no_oui_extensions;
227 
228 	len = sizeof(*cmd);
229 	len += WMI_TLV_HDR_SIZE; /* Array of wmi_vendor_oui_ext structures */
230 
231 	if (no_oui_extns > WMI_MAX_VENDOR_OUI_ACTION_SUPPORTED_PER_ACTION ||
232 	    (total_no_oui_extns > WMI_VENDOR_OUI_ACTION_MAX_ACTION_ID *
233 	     WMI_MAX_VENDOR_OUI_ACTION_SUPPORTED_PER_ACTION)) {
234 		wmi_err("Invalid number of action oui extensions");
235 		return QDF_STATUS_E_INVAL;
236 	}
237 
238 	valid = wmi_get_action_oui_id(req->action_id, &action_id);
239 	if (!valid) {
240 		wmi_err("Invalid action id");
241 		return QDF_STATUS_E_INVAL;
242 	}
243 	wmi_debug("wmi action_id %d num %d total_num %d", action_id,
244 		  no_oui_extns, total_no_oui_extns);
245 
246 	len += no_oui_extns * sizeof(*cmd_ext);
247 	len += WMI_TLV_HDR_SIZE; /* Variable length buffer */
248 
249 	extension = req->extension;
250 	for (i = 0; i < no_oui_extns; i++) {
251 		var_buf_len += extension->oui_length +
252 		       extension->data_length +
253 		       extension->data_mask_length +
254 		       extension->mac_addr_length +
255 		       extension->mac_mask_length +
256 		       extension->capability_length;
257 		extension++;
258 	}
259 
260 	var_buf_len += no_oui_extns; /* to store indexes */
261 	rem_var_buf_len = var_buf_len;
262 	var_buf_len = (var_buf_len + 3) & ~0x3;
263 	len += var_buf_len;
264 
265 	wmi_buf = wmi_buf_alloc(wmi_handle, len);
266 	if (!wmi_buf) {
267 		wmi_err("Failed to allocate wmi buffer");
268 		return QDF_STATUS_E_FAILURE;
269 	}
270 
271 	buf_ptr = (uint8_t *)wmi_buf_data(wmi_buf);
272 	cmd = (wmi_pdev_config_vendor_oui_action_fixed_param *)buf_ptr;
273 
274 	WMITLV_SET_HDR(&cmd->tlv_header,
275 		WMITLV_TAG_STRUC_wmi_pdev_config_vendor_oui_action_fixed_param,
276 		WMITLV_GET_STRUCT_TLVLEN(
277 			wmi_pdev_config_vendor_oui_action_fixed_param));
278 
279 	cmd->action_id = action_id;
280 	cmd->total_num_vendor_oui = total_no_oui_extns;
281 	cmd->num_vendor_oui_ext = no_oui_extns;
282 
283 	buf_ptr += sizeof(*cmd);
284 	WMITLV_SET_HDR(buf_ptr, WMITLV_TAG_ARRAY_STRUC,
285 		       no_oui_extns * sizeof(*cmd_ext));
286 	buf_ptr += WMI_TLV_HDR_SIZE;
287 	cmd_ext = (wmi_vendor_oui_ext *)buf_ptr;
288 	wmi_fill_oui_extensions(req->extension, no_oui_extns, cmd_ext);
289 
290 	buf_ptr += no_oui_extns * sizeof(*cmd_ext);
291 	WMITLV_SET_HDR(buf_ptr, WMITLV_TAG_ARRAY_BYTE, var_buf_len);
292 	buf_ptr += WMI_TLV_HDR_SIZE;
293 	status = wmi_fill_oui_extensions_buffer(req->extension,
294 						cmd_ext, no_oui_extns,
295 						rem_var_buf_len, buf_ptr);
296 	if (!QDF_IS_STATUS_SUCCESS(status)) {
297 		wmi_buf_free(wmi_buf);
298 		wmi_buf = NULL;
299 		wmi_err("failed to fill oui ext status %d", status);
300 		return QDF_STATUS_E_INVAL;
301 	}
302 
303 	buf_ptr += var_buf_len;
304 
305 	if (wmi_unified_cmd_send(wmi_handle, wmi_buf, len,
306 				 WMI_PDEV_CONFIG_VENDOR_OUI_ACTION_CMDID)) {
307 		wmi_err("WMI_PDEV_CONFIG_VENDOR_OUI_ACTION send fail");
308 		wmi_buf_free(wmi_buf);
309 		wmi_buf = NULL;
310 		return QDF_STATUS_E_FAILURE;
311 	}
312 
313 	return QDF_STATUS_SUCCESS;
314 }
315