xref: /aosp_15_r20/external/wpa_supplicant_8/src/drivers/driver_nl80211_capa.c (revision 03f9172ca588f91df233974f4258bab95191f931)
1 /*
2  * Driver interaction with Linux nl80211/cfg80211 - Capabilities
3  * Copyright (c) 2002-2015, Jouni Malinen <[email protected]>
4  * Copyright (c) 2007, Johannes Berg <[email protected]>
5  * Copyright (c) 2009-2010, Atheros Communications
6  *
7  * This software may be distributed under the terms of the BSD license.
8  * See README for more details.
9  */
10 
11 #include "includes.h"
12 #include <netlink/genl/genl.h>
13 
14 #include "utils/common.h"
15 #include "common/ieee802_11_common.h"
16 #include "common/wpa_common.h"
17 #include "common/qca-vendor.h"
18 #include "common/qca-vendor-attr.h"
19 #include "common/brcm_vendor.h"
20 #include "driver_nl80211.h"
21 
protocol_feature_handler(struct nl_msg * msg,void * arg)22 static int protocol_feature_handler(struct nl_msg *msg, void *arg)
23 {
24 	u32 *feat = arg;
25 	struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
26 	struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
27 
28 	nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
29 		  genlmsg_attrlen(gnlh, 0), NULL);
30 
31 	if (tb_msg[NL80211_ATTR_PROTOCOL_FEATURES])
32 		*feat = nla_get_u32(tb_msg[NL80211_ATTR_PROTOCOL_FEATURES]);
33 
34 	return NL_SKIP;
35 }
36 
37 
get_nl80211_protocol_features(struct wpa_driver_nl80211_data * drv)38 static u32 get_nl80211_protocol_features(struct wpa_driver_nl80211_data *drv)
39 {
40 	u32 feat = 0;
41 	struct nl_msg *msg;
42 
43 	msg = nlmsg_alloc();
44 	if (!msg)
45 		return 0;
46 
47 	if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_PROTOCOL_FEATURES)) {
48 		nlmsg_free(msg);
49 		return 0;
50 	}
51 
52 	if (send_and_recv_resp(drv, msg, protocol_feature_handler, &feat) == 0)
53 		return feat;
54 
55 	return 0;
56 }
57 
58 
59 struct wiphy_info_data {
60 	struct wpa_driver_nl80211_data *drv;
61 	struct wpa_driver_capa *capa;
62 
63 	unsigned int num_multichan_concurrent;
64 
65 	unsigned int error:1;
66 	unsigned int device_ap_sme:1;
67 	unsigned int poll_command_supported:1;
68 	unsigned int data_tx_status:1;
69 	unsigned int auth_supported:1;
70 	unsigned int connect_supported:1;
71 	unsigned int p2p_go_supported:1;
72 	unsigned int p2p_client_supported:1;
73 	unsigned int p2p_go_ctwindow_supported:1;
74 	unsigned int p2p_concurrent:1;
75 	unsigned int channel_switch_supported:1;
76 	unsigned int set_qos_map_supported:1;
77 	unsigned int have_low_prio_scan:1;
78 	unsigned int wmm_ac_supported:1;
79 	unsigned int mac_addr_rand_scan_supported:1;
80 	unsigned int mac_addr_rand_sched_scan_supported:1;
81 	unsigned int update_ft_ies_supported:1;
82 	unsigned int has_key_mgmt:1;
83 	unsigned int has_key_mgmt_iftype:1;
84 };
85 
86 
probe_resp_offload_support(int supp_protocols)87 static unsigned int probe_resp_offload_support(int supp_protocols)
88 {
89 	unsigned int prot = 0;
90 
91 	if (supp_protocols & NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS)
92 		prot |= WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS;
93 	if (supp_protocols & NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2)
94 		prot |= WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2;
95 	if (supp_protocols & NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P)
96 		prot |= WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P;
97 	if (supp_protocols & NL80211_PROBE_RESP_OFFLOAD_SUPPORT_80211U)
98 		prot |= WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING;
99 
100 	return prot;
101 }
102 
103 
wiphy_info_supported_iftypes(struct wiphy_info_data * info,struct nlattr * tb)104 static void wiphy_info_supported_iftypes(struct wiphy_info_data *info,
105 					 struct nlattr *tb)
106 {
107 	struct nlattr *nl_mode;
108 	int i;
109 
110 	if (tb == NULL)
111 		return;
112 
113 	nla_for_each_nested(nl_mode, tb, i) {
114 		switch (nla_type(nl_mode)) {
115 		case NL80211_IFTYPE_AP:
116 			info->capa->flags |= WPA_DRIVER_FLAGS_AP;
117 			break;
118 		case NL80211_IFTYPE_MESH_POINT:
119 			info->capa->flags |= WPA_DRIVER_FLAGS_MESH;
120 			break;
121 		case NL80211_IFTYPE_ADHOC:
122 			info->capa->flags |= WPA_DRIVER_FLAGS_IBSS;
123 			break;
124 		case NL80211_IFTYPE_P2P_DEVICE:
125 			info->capa->flags |=
126 				WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE;
127 			break;
128 		case NL80211_IFTYPE_P2P_GO:
129 			info->p2p_go_supported = 1;
130 			break;
131 		case NL80211_IFTYPE_P2P_CLIENT:
132 			info->p2p_client_supported = 1;
133 			break;
134 		}
135 	}
136 }
137 
138 
wiphy_info_iface_comb_process(struct wiphy_info_data * info,struct nlattr * nl_combi)139 static int wiphy_info_iface_comb_process(struct wiphy_info_data *info,
140 					 struct nlattr *nl_combi)
141 {
142 	struct nlattr *tb_comb[NUM_NL80211_IFACE_COMB];
143 	struct nlattr *tb_limit[NUM_NL80211_IFACE_LIMIT];
144 	struct nlattr *nl_limit, *nl_mode;
145 	int err, rem_limit, rem_mode;
146 	int combination_has_p2p = 0, combination_has_mgd = 0;
147 	static struct nla_policy
148 	iface_combination_policy[NUM_NL80211_IFACE_COMB] = {
149 		[NL80211_IFACE_COMB_LIMITS] = { .type = NLA_NESTED },
150 		[NL80211_IFACE_COMB_MAXNUM] = { .type = NLA_U32 },
151 		[NL80211_IFACE_COMB_STA_AP_BI_MATCH] = { .type = NLA_FLAG },
152 		[NL80211_IFACE_COMB_NUM_CHANNELS] = { .type = NLA_U32 },
153 		[NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS] = { .type = NLA_U32 },
154 	},
155 	iface_limit_policy[NUM_NL80211_IFACE_LIMIT] = {
156 		[NL80211_IFACE_LIMIT_TYPES] = { .type = NLA_NESTED },
157 		[NL80211_IFACE_LIMIT_MAX] = { .type = NLA_U32 },
158 	};
159 
160 	err = nla_parse_nested(tb_comb, MAX_NL80211_IFACE_COMB,
161 			       nl_combi, iface_combination_policy);
162 	if (err || !tb_comb[NL80211_IFACE_COMB_LIMITS] ||
163 	    !tb_comb[NL80211_IFACE_COMB_MAXNUM] ||
164 	    !tb_comb[NL80211_IFACE_COMB_NUM_CHANNELS])
165 		return 0; /* broken combination */
166 
167 	if (tb_comb[NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS])
168 		info->capa->flags |= WPA_DRIVER_FLAGS_RADAR;
169 
170 	nla_for_each_nested(nl_limit, tb_comb[NL80211_IFACE_COMB_LIMITS],
171 			    rem_limit) {
172 		err = nla_parse_nested(tb_limit, MAX_NL80211_IFACE_LIMIT,
173 				       nl_limit, iface_limit_policy);
174 		if (err || !tb_limit[NL80211_IFACE_LIMIT_TYPES])
175 			return 0; /* broken combination */
176 
177 		nla_for_each_nested(nl_mode,
178 				    tb_limit[NL80211_IFACE_LIMIT_TYPES],
179 				    rem_mode) {
180 			int ift = nla_type(nl_mode);
181 			if (ift == NL80211_IFTYPE_P2P_GO ||
182 			    ift == NL80211_IFTYPE_P2P_CLIENT)
183 				combination_has_p2p = 1;
184 			if (ift == NL80211_IFTYPE_STATION)
185 				combination_has_mgd = 1;
186 		}
187 		if (combination_has_p2p && combination_has_mgd)
188 			break;
189 	}
190 
191 	if (combination_has_p2p && combination_has_mgd) {
192 		unsigned int num_channels =
193 			nla_get_u32(tb_comb[NL80211_IFACE_COMB_NUM_CHANNELS]);
194 
195 		info->p2p_concurrent = 1;
196 		if (info->num_multichan_concurrent < num_channels)
197 			info->num_multichan_concurrent = num_channels;
198 	}
199 
200 	return 0;
201 }
202 
203 
wiphy_info_iface_comb(struct wiphy_info_data * info,struct nlattr * tb)204 static void wiphy_info_iface_comb(struct wiphy_info_data *info,
205 				  struct nlattr *tb)
206 {
207 	struct nlattr *nl_combi;
208 	int rem_combi;
209 
210 	if (tb == NULL)
211 		return;
212 
213 	nla_for_each_nested(nl_combi, tb, rem_combi) {
214 		if (wiphy_info_iface_comb_process(info, nl_combi) > 0)
215 			break;
216 	}
217 }
218 
219 
wiphy_info_supp_cmds(struct wiphy_info_data * info,struct nlattr * tb)220 static void wiphy_info_supp_cmds(struct wiphy_info_data *info,
221 				 struct nlattr *tb)
222 {
223 	struct nlattr *nl_cmd;
224 	int i;
225 
226 	if (tb == NULL)
227 		return;
228 
229 	nla_for_each_nested(nl_cmd, tb, i) {
230 		switch (nla_get_u32(nl_cmd)) {
231 		case NL80211_CMD_AUTHENTICATE:
232 			info->auth_supported = 1;
233 			break;
234 		case NL80211_CMD_CONNECT:
235 			info->connect_supported = 1;
236 			break;
237 		case NL80211_CMD_START_SCHED_SCAN:
238 			info->capa->sched_scan_supported = 1;
239 			break;
240 		case NL80211_CMD_PROBE_CLIENT:
241 			info->poll_command_supported = 1;
242 			break;
243 		case NL80211_CMD_CHANNEL_SWITCH:
244 			info->channel_switch_supported = 1;
245 			break;
246 		case NL80211_CMD_SET_QOS_MAP:
247 			info->set_qos_map_supported = 1;
248 			break;
249 		case NL80211_CMD_UPDATE_FT_IES:
250 			info->update_ft_ies_supported = 1;
251 			break;
252 		}
253 	}
254 }
255 
256 
get_akm_suites_info(struct nlattr * tb)257 static unsigned int get_akm_suites_info(struct nlattr *tb)
258 {
259 	int i, num;
260 	unsigned int key_mgmt = 0;
261 	u32 *akms;
262 
263 	if (!tb)
264 		return 0;
265 
266 	num = nla_len(tb) / sizeof(u32);
267 	akms = nla_data(tb);
268 	for (i = 0; i < num; i++) {
269 		switch (akms[i]) {
270 		case RSN_AUTH_KEY_MGMT_UNSPEC_802_1X:
271 			key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_WPA |
272 				WPA_DRIVER_CAPA_KEY_MGMT_WPA2;
273 			break;
274 		case RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X:
275 			key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
276 				WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK;
277 			break;
278 		case RSN_AUTH_KEY_MGMT_FT_802_1X:
279 			key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT;
280 			break;
281 		case RSN_AUTH_KEY_MGMT_FT_PSK:
282 			key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK;
283 			break;
284 		case RSN_AUTH_KEY_MGMT_802_1X_SHA256:
285 			key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_802_1X_SHA256;
286 			break;
287 		case RSN_AUTH_KEY_MGMT_PSK_SHA256:
288 			key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_PSK_SHA256;
289 			break;
290 		case RSN_AUTH_KEY_MGMT_TPK_HANDSHAKE:
291 			key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_TPK_HANDSHAKE;
292 			break;
293 		case RSN_AUTH_KEY_MGMT_FT_SAE:
294 			key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT_SAE;
295 			break;
296 		case RSN_AUTH_KEY_MGMT_FT_SAE_EXT_KEY:
297 			key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT_SAE_EXT_KEY;
298 			break;
299 		case RSN_AUTH_KEY_MGMT_FT_802_1X_SHA384:
300 			key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT_802_1X_SHA384;
301 			break;
302 		case RSN_AUTH_KEY_MGMT_CCKM:
303 			key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_CCKM;
304 			break;
305 		case RSN_AUTH_KEY_MGMT_OSEN:
306 			key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_OSEN;
307 			break;
308 		case RSN_AUTH_KEY_MGMT_802_1X_SUITE_B:
309 			key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B;
310 			break;
311 		case RSN_AUTH_KEY_MGMT_802_1X_SUITE_B_192:
312 			key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192;
313 			break;
314 		case RSN_AUTH_KEY_MGMT_OWE:
315 			key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_OWE;
316 			break;
317 		case RSN_AUTH_KEY_MGMT_DPP:
318 			key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_DPP;
319 			break;
320 		case RSN_AUTH_KEY_MGMT_FILS_SHA256:
321 			key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256;
322 			break;
323 		case RSN_AUTH_KEY_MGMT_FILS_SHA384:
324 			key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384;
325 			break;
326 		case RSN_AUTH_KEY_MGMT_FT_FILS_SHA256:
327 			key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA256;
328 			break;
329 		case RSN_AUTH_KEY_MGMT_FT_FILS_SHA384:
330 			key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA384;
331 			break;
332 		case RSN_AUTH_KEY_MGMT_SAE:
333 			key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_SAE;
334 			break;
335 		case RSN_AUTH_KEY_MGMT_SAE_EXT_KEY:
336 			key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_SAE_EXT_KEY;
337 			break;
338 		}
339 	}
340 
341 	return key_mgmt;
342 }
343 
344 
get_iface_akm_suites_info(struct wiphy_info_data * info,struct nlattr * nl_akms)345 static void get_iface_akm_suites_info(struct wiphy_info_data *info,
346 					struct nlattr *nl_akms)
347 {
348 	struct nlattr *tb[NL80211_IFTYPE_AKM_ATTR_MAX + 1];
349 	struct nlattr *nl_iftype;
350 	unsigned int key_mgmt;
351 	int i;
352 
353 	if (!nl_akms)
354 		return;
355 
356 	nla_parse(tb, NL80211_IFTYPE_AKM_ATTR_MAX,
357 		  nla_data(nl_akms), nla_len(nl_akms), NULL);
358 
359 	if (!tb[NL80211_IFTYPE_AKM_ATTR_IFTYPES] ||
360 	    !tb[NL80211_IFTYPE_AKM_ATTR_SUITES])
361 		return;
362 
363 	info->has_key_mgmt_iftype = 1;
364 	key_mgmt = get_akm_suites_info(tb[NL80211_IFTYPE_AKM_ATTR_SUITES]);
365 
366 	nla_for_each_nested(nl_iftype, tb[NL80211_IFTYPE_AKM_ATTR_IFTYPES], i) {
367 		switch (nla_type(nl_iftype)) {
368 		case NL80211_IFTYPE_ADHOC:
369 			info->drv->capa.key_mgmt_iftype[WPA_IF_IBSS] = key_mgmt;
370 			break;
371 		case NL80211_IFTYPE_STATION:
372 			info->drv->capa.key_mgmt_iftype[WPA_IF_STATION] =
373 				key_mgmt;
374 			break;
375 		case NL80211_IFTYPE_AP:
376 			info->drv->capa.key_mgmt_iftype[WPA_IF_AP_BSS] =
377 				key_mgmt;
378 			break;
379 		case NL80211_IFTYPE_AP_VLAN:
380 			info->drv->capa.key_mgmt_iftype[WPA_IF_AP_VLAN] =
381 				key_mgmt;
382 			break;
383 		case NL80211_IFTYPE_MESH_POINT:
384 			info->drv->capa.key_mgmt_iftype[WPA_IF_MESH] = key_mgmt;
385 			break;
386 		case NL80211_IFTYPE_P2P_CLIENT:
387 			info->drv->capa.key_mgmt_iftype[WPA_IF_P2P_CLIENT] =
388 				key_mgmt;
389 			break;
390 		case NL80211_IFTYPE_P2P_GO:
391 			info->drv->capa.key_mgmt_iftype[WPA_IF_P2P_GO] =
392 				key_mgmt;
393 			break;
394 		case NL80211_IFTYPE_P2P_DEVICE:
395 			info->drv->capa.key_mgmt_iftype[WPA_IF_P2P_DEVICE] =
396 				key_mgmt;
397 			break;
398 		case NL80211_IFTYPE_NAN:
399 			info->drv->capa.key_mgmt_iftype[WPA_IF_NAN] = key_mgmt;
400 			break;
401 		}
402 		wpa_printf(MSG_DEBUG, "nl80211: %s supported key_mgmt 0x%x",
403 			   nl80211_iftype_str(nla_type(nl_iftype)),
404 			   key_mgmt);
405 	}
406 }
407 
408 
wiphy_info_iftype_akm_suites(struct wiphy_info_data * info,struct nlattr * tb)409 static void wiphy_info_iftype_akm_suites(struct wiphy_info_data *info,
410 					 struct nlattr *tb)
411 {
412 	struct nlattr *nl_if;
413 	int rem_if;
414 
415 	if (!tb)
416 		return;
417 
418 	nla_for_each_nested(nl_if, tb, rem_if)
419 		get_iface_akm_suites_info(info, nl_if);
420 }
421 
422 
wiphy_info_akm_suites(struct wiphy_info_data * info,struct nlattr * tb)423 static void wiphy_info_akm_suites(struct wiphy_info_data *info,
424 				  struct nlattr *tb)
425 {
426 	if (!tb)
427 		return;
428 
429 	info->has_key_mgmt = 1;
430 	info->capa->key_mgmt = get_akm_suites_info(tb);
431 	wpa_printf(MSG_DEBUG, "nl80211: wiphy supported key_mgmt 0x%x",
432 		   info->capa->key_mgmt);
433 }
434 
435 
wiphy_info_cipher_suites(struct wiphy_info_data * info,struct nlattr * tb)436 static void wiphy_info_cipher_suites(struct wiphy_info_data *info,
437 				     struct nlattr *tb)
438 {
439 	int i, num;
440 	u32 *ciphers;
441 
442 	if (tb == NULL)
443 		return;
444 
445 	num = nla_len(tb) / sizeof(u32);
446 	ciphers = nla_data(tb);
447 	for (i = 0; i < num; i++) {
448 		u32 c = ciphers[i];
449 
450 		wpa_printf(MSG_DEBUG, "nl80211: Supported cipher %02x-%02x-%02x:%d",
451 			   c >> 24, (c >> 16) & 0xff,
452 			   (c >> 8) & 0xff, c & 0xff);
453 		switch (c) {
454 		case RSN_CIPHER_SUITE_CCMP_256:
455 			info->capa->enc |= WPA_DRIVER_CAPA_ENC_CCMP_256;
456 			break;
457 		case RSN_CIPHER_SUITE_GCMP_256:
458 			info->capa->enc |= WPA_DRIVER_CAPA_ENC_GCMP_256;
459 			break;
460 		case RSN_CIPHER_SUITE_CCMP:
461 			info->capa->enc |= WPA_DRIVER_CAPA_ENC_CCMP;
462 			break;
463 		case RSN_CIPHER_SUITE_GCMP:
464 			info->capa->enc |= WPA_DRIVER_CAPA_ENC_GCMP;
465 			break;
466 		case RSN_CIPHER_SUITE_TKIP:
467 			info->capa->enc |= WPA_DRIVER_CAPA_ENC_TKIP;
468 			break;
469 		case RSN_CIPHER_SUITE_WEP104:
470 			info->capa->enc |= WPA_DRIVER_CAPA_ENC_WEP104;
471 			break;
472 		case RSN_CIPHER_SUITE_WEP40:
473 			info->capa->enc |= WPA_DRIVER_CAPA_ENC_WEP40;
474 			break;
475 		case RSN_CIPHER_SUITE_AES_128_CMAC:
476 			info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP;
477 			break;
478 		case RSN_CIPHER_SUITE_BIP_GMAC_128:
479 			info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP_GMAC_128;
480 			break;
481 		case RSN_CIPHER_SUITE_BIP_GMAC_256:
482 			info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP_GMAC_256;
483 			break;
484 		case RSN_CIPHER_SUITE_BIP_CMAC_256:
485 			info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP_CMAC_256;
486 			break;
487 		case RSN_CIPHER_SUITE_NO_GROUP_ADDRESSED:
488 			info->capa->enc |= WPA_DRIVER_CAPA_ENC_GTK_NOT_USED;
489 			break;
490 		}
491 	}
492 }
493 
494 
wiphy_info_max_roc(struct wpa_driver_capa * capa,struct nlattr * tb)495 static void wiphy_info_max_roc(struct wpa_driver_capa *capa,
496 			       struct nlattr *tb)
497 {
498 	if (tb)
499 		capa->max_remain_on_chan = nla_get_u32(tb);
500 }
501 
502 
wiphy_info_tdls(struct wpa_driver_capa * capa,struct nlattr * tdls,struct nlattr * ext_setup)503 static void wiphy_info_tdls(struct wpa_driver_capa *capa, struct nlattr *tdls,
504 			    struct nlattr *ext_setup)
505 {
506 	if (tdls == NULL)
507 		return;
508 
509 	wpa_printf(MSG_DEBUG, "nl80211: TDLS supported");
510 	capa->flags |= WPA_DRIVER_FLAGS_TDLS_SUPPORT;
511 
512 	if (ext_setup) {
513 		wpa_printf(MSG_DEBUG, "nl80211: TDLS external setup");
514 		capa->flags |= WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP;
515 	}
516 }
517 
518 
ext_feature_isset(const u8 * ext_features,int ext_features_len,enum nl80211_ext_feature_index ftidx)519 static int ext_feature_isset(const u8 *ext_features, int ext_features_len,
520 			     enum nl80211_ext_feature_index ftidx)
521 {
522 	u8 ft_byte;
523 
524 	if ((int) ftidx / 8 >= ext_features_len)
525 		return 0;
526 
527 	ft_byte = ext_features[ftidx / 8];
528 	return (ft_byte & BIT(ftidx % 8)) != 0;
529 }
530 
531 
wiphy_info_ext_feature_flags(struct wiphy_info_data * info,struct nlattr * tb)532 static void wiphy_info_ext_feature_flags(struct wiphy_info_data *info,
533 					 struct nlattr *tb)
534 {
535 	struct wpa_driver_capa *capa = info->capa;
536 	u8 *ext_features;
537 	int len;
538 
539 	if (tb == NULL)
540 		return;
541 
542 	ext_features = nla_data(tb);
543 	len = nla_len(tb);
544 
545 	if (ext_feature_isset(ext_features, len, NL80211_EXT_FEATURE_VHT_IBSS))
546 		capa->flags |= WPA_DRIVER_FLAGS_VHT_IBSS;
547 
548 	if (ext_feature_isset(ext_features, len, NL80211_EXT_FEATURE_RRM))
549 		capa->rrm_flags |= WPA_DRIVER_FLAGS_SUPPORT_RRM;
550 
551 	if (ext_feature_isset(ext_features, len, NL80211_EXT_FEATURE_FILS_STA))
552 		capa->flags |= WPA_DRIVER_FLAGS_SUPPORT_FILS;
553 
554 	if (ext_feature_isset(ext_features, len,
555 			      NL80211_EXT_FEATURE_BEACON_RATE_LEGACY))
556 		capa->flags |= WPA_DRIVER_FLAGS_BEACON_RATE_LEGACY;
557 
558 	if (ext_feature_isset(ext_features, len,
559 			      NL80211_EXT_FEATURE_BEACON_RATE_HT))
560 		capa->flags |= WPA_DRIVER_FLAGS_BEACON_RATE_HT;
561 
562 	if (ext_feature_isset(ext_features, len,
563 			      NL80211_EXT_FEATURE_BEACON_RATE_VHT))
564 		capa->flags |= WPA_DRIVER_FLAGS_BEACON_RATE_VHT;
565 
566 	if (ext_feature_isset(ext_features, len,
567 			      NL80211_EXT_FEATURE_BEACON_RATE_HE))
568 		capa->flags2 |= WPA_DRIVER_FLAGS2_BEACON_RATE_HE;
569 
570 	if (ext_feature_isset(ext_features, len,
571 			      NL80211_EXT_FEATURE_SET_SCAN_DWELL))
572 		capa->rrm_flags |= WPA_DRIVER_FLAGS_SUPPORT_SET_SCAN_DWELL;
573 
574 	if (ext_feature_isset(ext_features, len,
575 			      NL80211_EXT_FEATURE_SCAN_START_TIME) &&
576 	    ext_feature_isset(ext_features, len,
577 			      NL80211_EXT_FEATURE_BSS_PARENT_TSF) &&
578 	    ext_feature_isset(ext_features, len,
579 			      NL80211_EXT_FEATURE_SET_SCAN_DWELL))
580 		capa->rrm_flags |= WPA_DRIVER_FLAGS_SUPPORT_BEACON_REPORT;
581 	if (ext_feature_isset(ext_features, len,
582 			      NL80211_EXT_FEATURE_MGMT_TX_RANDOM_TA))
583 		capa->flags |= WPA_DRIVER_FLAGS_MGMT_TX_RANDOM_TA;
584 	if (ext_feature_isset(ext_features, len,
585 			      NL80211_EXT_FEATURE_MGMT_TX_RANDOM_TA_CONNECTED))
586 		capa->flags |= WPA_DRIVER_FLAGS_MGMT_TX_RANDOM_TA_CONNECTED;
587 	if (ext_feature_isset(ext_features, len,
588 			      NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI))
589 		capa->flags |= WPA_DRIVER_FLAGS_SCHED_SCAN_RELATIVE_RSSI;
590 	if (ext_feature_isset(ext_features, len,
591 			      NL80211_EXT_FEATURE_FILS_SK_OFFLOAD))
592 		capa->flags |= WPA_DRIVER_FLAGS_FILS_SK_OFFLOAD;
593 
594 	if (ext_feature_isset(ext_features, len,
595 			      NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK))
596 		capa->flags |= WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK;
597 	if (ext_feature_isset(ext_features, len,
598 			      NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
599 		capa->flags |= WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X;
600 
601 	if (ext_feature_isset(ext_features, len,
602 			      NL80211_EXT_FEATURE_SAE_OFFLOAD))
603 		capa->flags2 |= WPA_DRIVER_FLAGS2_SAE_OFFLOAD_STA;
604 
605 	if (ext_feature_isset(ext_features, len,
606 			      NL80211_EXT_FEATURE_MFP_OPTIONAL))
607 		capa->flags |= WPA_DRIVER_FLAGS_MFP_OPTIONAL;
608 
609 	if (ext_feature_isset(ext_features, len,
610 			      NL80211_EXT_FEATURE_DFS_OFFLOAD))
611 		capa->flags |= WPA_DRIVER_FLAGS_DFS_OFFLOAD;
612 
613 #ifdef CONFIG_MBO
614 	if (ext_feature_isset(ext_features, len,
615 			      NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME) &&
616 	    ext_feature_isset(ext_features, len,
617 			      NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP) &&
618 	    ext_feature_isset(ext_features, len,
619 			      NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE) &&
620 	    ext_feature_isset(
621 		    ext_features, len,
622 		    NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION))
623 		capa->flags |= WPA_DRIVER_FLAGS_OCE_STA;
624 #endif /* CONFIG_MBO */
625 
626 	if (ext_feature_isset(ext_features, len,
627 			      NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER))
628 		capa->flags |= WPA_DRIVER_FLAGS_FTM_RESPONDER;
629 
630 	if (ext_feature_isset(ext_features, len,
631 			      NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211))
632 		capa->flags |= WPA_DRIVER_FLAGS_CONTROL_PORT;
633 	if (ext_feature_isset(ext_features, len,
634 			      NL80211_EXT_FEATURE_CONTROL_PORT_NO_PREAUTH))
635 		capa->flags2 |= WPA_DRIVER_FLAGS2_CONTROL_PORT_RX;
636 	if (ext_feature_isset(
637 		    ext_features, len,
638 		    NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211_TX_STATUS))
639 		capa->flags2 |= WPA_DRIVER_FLAGS2_CONTROL_PORT_TX_STATUS;
640 
641 	if (ext_feature_isset(ext_features, len,
642 			      NL80211_EXT_FEATURE_VLAN_OFFLOAD))
643 		capa->flags |= WPA_DRIVER_FLAGS_VLAN_OFFLOAD;
644 
645 	if (ext_feature_isset(ext_features, len,
646 			      NL80211_EXT_FEATURE_CAN_REPLACE_PTK0))
647 		capa->flags |= WPA_DRIVER_FLAGS_SAFE_PTK0_REKEYS;
648 
649 	if (ext_feature_isset(ext_features, len,
650 			      NL80211_EXT_FEATURE_BEACON_PROTECTION))
651 		capa->flags |= WPA_DRIVER_FLAGS_BEACON_PROTECTION;
652 
653 	if (ext_feature_isset(ext_features, len,
654 			      NL80211_EXT_FEATURE_EXT_KEY_ID))
655 		capa->flags |= WPA_DRIVER_FLAGS_EXTENDED_KEY_ID;
656 
657 	if (ext_feature_isset(ext_features, len,
658 			      NL80211_EXT_FEATURE_MULTICAST_REGISTRATIONS))
659 		info->drv->multicast_registrations = 1;
660 
661 	if (ext_feature_isset(ext_features, len,
662 			      NL80211_EXT_FEATURE_FILS_DISCOVERY))
663 		info->drv->fils_discovery = 1;
664 
665 	if (ext_feature_isset(ext_features, len,
666 			      NL80211_EXT_FEATURE_UNSOL_BCAST_PROBE_RESP))
667 		info->drv->unsol_bcast_probe_resp = 1;
668 
669 	if (ext_feature_isset(ext_features, len, NL80211_EXT_FEATURE_PUNCT))
670 		info->drv->puncturing = 1;
671 
672 	if (ext_feature_isset(ext_features, len,
673 			      NL80211_EXT_FEATURE_BEACON_PROTECTION_CLIENT))
674 		capa->flags2 |= WPA_DRIVER_FLAGS2_BEACON_PROTECTION_CLIENT;
675 
676 	if (ext_feature_isset(ext_features, len,
677 			      NL80211_EXT_FEATURE_OPERATING_CHANNEL_VALIDATION))
678 		capa->flags2 |= WPA_DRIVER_FLAGS2_OCV;
679 
680 	if (ext_feature_isset(ext_features, len,
681 			      NL80211_EXT_FEATURE_RADAR_BACKGROUND))
682 		capa->flags2 |= WPA_DRIVER_FLAGS2_RADAR_BACKGROUND;
683 
684 	if (ext_feature_isset(ext_features, len,
685 			      NL80211_EXT_FEATURE_SECURE_LTF)) {
686 		capa->flags2 |= WPA_DRIVER_FLAGS2_SEC_LTF_STA;
687 		capa->flags2 |= WPA_DRIVER_FLAGS2_SEC_LTF_AP;
688 	}
689 
690 	if (ext_feature_isset(ext_features, len,
691 			      NL80211_EXT_FEATURE_SECURE_RTT)) {
692 		capa->flags2 |= WPA_DRIVER_FLAGS2_SEC_RTT_STA;
693 		capa->flags2 |= WPA_DRIVER_FLAGS2_SEC_RTT_AP;
694 	}
695 
696 	if (ext_feature_isset(
697 		    ext_features, len,
698 		    NL80211_EXT_FEATURE_PROT_RANGE_NEGO_AND_MEASURE)) {
699 		capa->flags2 |= WPA_DRIVER_FLAGS2_PROT_RANGE_NEG_STA;
700 		capa->flags2 |= WPA_DRIVER_FLAGS2_PROT_RANGE_NEG_AP;
701 	}
702 
703 	if (ext_feature_isset(ext_features, len,
704 			      NL80211_EXT_FEATURE_SCAN_MIN_PREQ_CONTENT))
705 		capa->flags2 |= WPA_DRIVER_FLAGS2_SCAN_MIN_PREQ;
706 
707 	if (ext_feature_isset(ext_features, len,
708 			      NL80211_EXT_FEATURE_4WAY_HANDSHAKE_AP_PSK))
709 		capa->flags2 |= WPA_DRIVER_FLAGS2_4WAY_HANDSHAKE_AP_PSK;
710 
711 	if (ext_feature_isset(ext_features, len,
712 			      NL80211_EXT_FEATURE_OWE_OFFLOAD))
713 		capa->flags2 |= WPA_DRIVER_FLAGS2_OWE_OFFLOAD_STA;
714 
715 	if (ext_feature_isset(ext_features, len,
716 			      NL80211_EXT_FEATURE_OWE_OFFLOAD_AP))
717 		capa->flags2 |= WPA_DRIVER_FLAGS2_OWE_OFFLOAD_AP;
718 
719 	if (ext_feature_isset(ext_features, len,
720 			      NL80211_EXT_FEATURE_SAE_OFFLOAD_AP))
721 		capa->flags2 |= WPA_DRIVER_FLAGS2_SAE_OFFLOAD_AP;
722 }
723 
724 
wiphy_info_feature_flags(struct wiphy_info_data * info,struct nlattr * tb)725 static void wiphy_info_feature_flags(struct wiphy_info_data *info,
726 				     struct nlattr *tb)
727 {
728 	u32 flags;
729 	struct wpa_driver_capa *capa = info->capa;
730 
731 	if (tb == NULL)
732 		return;
733 
734 	flags = nla_get_u32(tb);
735 
736 	if (flags & NL80211_FEATURE_SK_TX_STATUS)
737 		info->data_tx_status = 1;
738 
739 	if (flags & NL80211_FEATURE_INACTIVITY_TIMER)
740 		capa->flags |= WPA_DRIVER_FLAGS_INACTIVITY_TIMER;
741 
742 	if (flags & NL80211_FEATURE_SAE)
743 		capa->flags |= WPA_DRIVER_FLAGS_SAE;
744 
745 	if (flags & NL80211_FEATURE_NEED_OBSS_SCAN)
746 		capa->flags |= WPA_DRIVER_FLAGS_OBSS_SCAN;
747 
748 	if (flags & NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)
749 		capa->flags |= WPA_DRIVER_FLAGS_HT_2040_COEX;
750 
751 	if (flags & NL80211_FEATURE_TDLS_CHANNEL_SWITCH) {
752 		wpa_printf(MSG_DEBUG, "nl80211: TDLS channel switch");
753 		capa->flags |= WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH;
754 	}
755 
756 	if (flags & NL80211_FEATURE_P2P_GO_CTWIN)
757 		info->p2p_go_ctwindow_supported = 1;
758 
759 	if (flags & NL80211_FEATURE_LOW_PRIORITY_SCAN)
760 		info->have_low_prio_scan = 1;
761 
762 	if (flags & NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)
763 		info->mac_addr_rand_scan_supported = 1;
764 
765 	if (flags & NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR)
766 		info->mac_addr_rand_sched_scan_supported = 1;
767 
768 	if (flags & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
769 		info->wmm_ac_supported = 1;
770 
771 	if (flags & NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES)
772 		capa->rrm_flags |= WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES;
773 
774 	if (flags & NL80211_FEATURE_WFA_TPC_IE_IN_PROBES)
775 		capa->rrm_flags |= WPA_DRIVER_FLAGS_WFA_TPC_IE_IN_PROBES;
776 
777 	if (flags & NL80211_FEATURE_QUIET)
778 		capa->rrm_flags |= WPA_DRIVER_FLAGS_QUIET;
779 
780 	if (flags & NL80211_FEATURE_TX_POWER_INSERTION)
781 		capa->rrm_flags |= WPA_DRIVER_FLAGS_TX_POWER_INSERTION;
782 
783 	if (flags & NL80211_FEATURE_HT_IBSS)
784 		capa->flags |= WPA_DRIVER_FLAGS_HT_IBSS;
785 
786 	if (flags & NL80211_FEATURE_FULL_AP_CLIENT_STATE)
787 		capa->flags |= WPA_DRIVER_FLAGS_FULL_AP_CLIENT_STATE;
788 }
789 
790 
wiphy_info_probe_resp_offload(struct wpa_driver_capa * capa,struct nlattr * tb)791 static void wiphy_info_probe_resp_offload(struct wpa_driver_capa *capa,
792 					  struct nlattr *tb)
793 {
794 	u32 protocols;
795 
796 	if (tb == NULL)
797 		return;
798 
799 	protocols = nla_get_u32(tb);
800 	wpa_printf(MSG_DEBUG, "nl80211: Supports Probe Response offload in AP "
801 		   "mode");
802 	capa->flags |= WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD;
803 	capa->probe_resp_offloads = probe_resp_offload_support(protocols);
804 }
805 
806 
wiphy_info_wowlan_triggers(struct wpa_driver_capa * capa,struct nlattr * tb)807 static void wiphy_info_wowlan_triggers(struct wpa_driver_capa *capa,
808 				       struct nlattr *tb)
809 {
810 	struct nlattr *triggers[MAX_NL80211_WOWLAN_TRIG + 1];
811 
812 	if (tb == NULL)
813 		return;
814 
815 	if (nla_parse_nested(triggers, MAX_NL80211_WOWLAN_TRIG,
816 			     tb, NULL))
817 		return;
818 
819 	if (triggers[NL80211_WOWLAN_TRIG_ANY])
820 		capa->wowlan_triggers.any = 1;
821 	if (triggers[NL80211_WOWLAN_TRIG_DISCONNECT])
822 		capa->wowlan_triggers.disconnect = 1;
823 	if (triggers[NL80211_WOWLAN_TRIG_MAGIC_PKT])
824 		capa->wowlan_triggers.magic_pkt = 1;
825 	if (triggers[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE])
826 		capa->wowlan_triggers.gtk_rekey_failure = 1;
827 	if (triggers[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST])
828 		capa->wowlan_triggers.eap_identity_req = 1;
829 	if (triggers[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE])
830 		capa->wowlan_triggers.four_way_handshake = 1;
831 	if (triggers[NL80211_WOWLAN_TRIG_RFKILL_RELEASE])
832 		capa->wowlan_triggers.rfkill_release = 1;
833 }
834 
835 
wiphy_info_extended_capab(struct wpa_driver_nl80211_data * drv,struct nlattr * tb)836 static void wiphy_info_extended_capab(struct wpa_driver_nl80211_data *drv,
837 				      struct nlattr *tb)
838 {
839 	int rem = 0, i;
840 	struct nlattr *tb1[NL80211_ATTR_MAX + 1], *attr;
841 
842 	if (!tb || drv->num_iface_capa == NL80211_IFTYPE_MAX)
843 		return;
844 
845 	nla_for_each_nested(attr, tb, rem) {
846 		unsigned int len;
847 		struct drv_nl80211_iface_capa *capa;
848 
849 		nla_parse(tb1, NL80211_ATTR_MAX, nla_data(attr),
850 			  nla_len(attr), NULL);
851 
852 		if (!tb1[NL80211_ATTR_IFTYPE] ||
853 		    !tb1[NL80211_ATTR_EXT_CAPA] ||
854 		    !tb1[NL80211_ATTR_EXT_CAPA_MASK])
855 			continue;
856 
857 		capa = &drv->iface_capa[drv->num_iface_capa];
858 		capa->iftype = nla_get_u32(tb1[NL80211_ATTR_IFTYPE]);
859 		wpa_printf(MSG_DEBUG,
860 			   "nl80211: Driver-advertised extended capabilities for interface type %s",
861 			   nl80211_iftype_str(capa->iftype));
862 
863 		len = nla_len(tb1[NL80211_ATTR_EXT_CAPA]);
864 		capa->ext_capa = os_memdup(nla_data(tb1[NL80211_ATTR_EXT_CAPA]),
865 					   len);
866 		if (!capa->ext_capa)
867 			goto err;
868 
869 		capa->ext_capa_len = len;
870 		wpa_hexdump(MSG_DEBUG, "nl80211: Extended capabilities",
871 			    capa->ext_capa, capa->ext_capa_len);
872 
873 		len = nla_len(tb1[NL80211_ATTR_EXT_CAPA_MASK]);
874 		capa->ext_capa_mask =
875 			os_memdup(nla_data(tb1[NL80211_ATTR_EXT_CAPA_MASK]),
876 				  len);
877 		if (!capa->ext_capa_mask)
878 			goto err;
879 
880 		wpa_hexdump(MSG_DEBUG, "nl80211: Extended capabilities mask",
881 			    capa->ext_capa_mask, capa->ext_capa_len);
882 
883 		if (tb1[NL80211_ATTR_EML_CAPABILITY] &&
884 		    tb1[NL80211_ATTR_MLD_CAPA_AND_OPS]) {
885 			capa->eml_capa =
886 				nla_get_u16(tb1[NL80211_ATTR_EML_CAPABILITY]);
887 			capa->mld_capa_and_ops =
888 				nla_get_u16(tb1[NL80211_ATTR_MLD_CAPA_AND_OPS]);
889 		}
890 
891 		wpa_printf(MSG_DEBUG,
892 			   "nl80211: EML Capability: 0x%x MLD Capability: 0x%x",
893 			   capa->eml_capa, capa->mld_capa_and_ops);
894 
895 		drv->num_iface_capa++;
896 		if (drv->num_iface_capa == NL80211_IFTYPE_MAX)
897 			break;
898 	}
899 
900 	return;
901 
902 err:
903 	/* Cleanup allocated memory on error */
904 	for (i = 0; i < NL80211_IFTYPE_MAX; i++) {
905 		os_free(drv->iface_capa[i].ext_capa);
906 		drv->iface_capa[i].ext_capa = NULL;
907 		os_free(drv->iface_capa[i].ext_capa_mask);
908 		drv->iface_capa[i].ext_capa_mask = NULL;
909 		drv->iface_capa[i].ext_capa_len = 0;
910 	}
911 	drv->num_iface_capa = 0;
912 }
913 
914 
wiphy_info_mbssid(struct wpa_driver_capa * cap,struct nlattr * attr)915 static void wiphy_info_mbssid(struct wpa_driver_capa *cap, struct nlattr *attr)
916 {
917 	struct nlattr *config[NL80211_MBSSID_CONFIG_ATTR_MAX + 1];
918 
919 	if (nla_parse_nested(config, NL80211_MBSSID_CONFIG_ATTR_MAX, attr,
920 			     NULL))
921 		return;
922 
923 	if (!config[NL80211_MBSSID_CONFIG_ATTR_MAX_INTERFACES])
924 		return;
925 
926 	cap->mbssid_max_interfaces =
927 		nla_get_u8(config[NL80211_MBSSID_CONFIG_ATTR_MAX_INTERFACES]);
928 
929 	if (config[NL80211_MBSSID_CONFIG_ATTR_MAX_EMA_PROFILE_PERIODICITY])
930 		cap->ema_max_periodicity =
931 			nla_get_u8(config[NL80211_MBSSID_CONFIG_ATTR_MAX_EMA_PROFILE_PERIODICITY]);
932 
933 	wpa_printf(MSG_DEBUG,
934 		   "mbssid: max interfaces %u, max profile periodicity %u",
935 		   cap->mbssid_max_interfaces, cap->ema_max_periodicity);
936 }
937 
938 
wiphy_info_handler(struct nl_msg * msg,void * arg)939 static int wiphy_info_handler(struct nl_msg *msg, void *arg)
940 {
941 	struct nlattr *tb[NL80211_ATTR_MAX + 1];
942 	struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
943 	struct wiphy_info_data *info = arg;
944 	struct wpa_driver_capa *capa = info->capa;
945 	struct wpa_driver_nl80211_data *drv = info->drv;
946 
947 	nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
948 		  genlmsg_attrlen(gnlh, 0), NULL);
949 
950 	if (tb[NL80211_ATTR_WIPHY])
951 		drv->wiphy_idx = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
952 
953 	if (tb[NL80211_ATTR_WIPHY_NAME])
954 		os_strlcpy(drv->phyname,
955 			   nla_get_string(tb[NL80211_ATTR_WIPHY_NAME]),
956 			   sizeof(drv->phyname));
957 	if (tb[NL80211_ATTR_MAX_NUM_SCAN_SSIDS])
958 		capa->max_scan_ssids =
959 			nla_get_u8(tb[NL80211_ATTR_MAX_NUM_SCAN_SSIDS]);
960 
961 	if (tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS])
962 		capa->max_sched_scan_ssids =
963 			nla_get_u8(tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS]);
964 
965 	if (tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS] &&
966 	    tb[NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL] &&
967 	    tb[NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS]) {
968 		capa->max_sched_scan_plans =
969 			nla_get_u32(tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS]);
970 
971 		capa->max_sched_scan_plan_interval =
972 			nla_get_u32(tb[NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL]);
973 
974 		capa->max_sched_scan_plan_iterations =
975 			nla_get_u32(tb[NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS]);
976 	}
977 
978 	if (tb[NL80211_ATTR_MAX_MATCH_SETS])
979 		capa->max_match_sets =
980 			nla_get_u8(tb[NL80211_ATTR_MAX_MATCH_SETS]);
981 
982 	if (tb[NL80211_ATTR_MAC_ACL_MAX])
983 		capa->max_acl_mac_addrs =
984 			nla_get_u32(tb[NL80211_ATTR_MAC_ACL_MAX]);
985 
986 	wiphy_info_supported_iftypes(info, tb[NL80211_ATTR_SUPPORTED_IFTYPES]);
987 	wiphy_info_iface_comb(info, tb[NL80211_ATTR_INTERFACE_COMBINATIONS]);
988 	wiphy_info_supp_cmds(info, tb[NL80211_ATTR_SUPPORTED_COMMANDS]);
989 	wiphy_info_cipher_suites(info, tb[NL80211_ATTR_CIPHER_SUITES]);
990 	wiphy_info_akm_suites(info, tb[NL80211_ATTR_AKM_SUITES]);
991 	wiphy_info_iftype_akm_suites(info, tb[NL80211_ATTR_IFTYPE_AKM_SUITES]);
992 
993 	if (tb[NL80211_ATTR_OFFCHANNEL_TX_OK]) {
994 		wpa_printf(MSG_DEBUG, "nl80211: Using driver-based "
995 			   "off-channel TX");
996 		capa->flags |= WPA_DRIVER_FLAGS_OFFCHANNEL_TX;
997 	}
998 
999 	if (tb[NL80211_ATTR_ROAM_SUPPORT]) {
1000 		wpa_printf(MSG_DEBUG, "nl80211: Using driver-based roaming");
1001 		capa->flags |= WPA_DRIVER_FLAGS_BSS_SELECTION;
1002 	}
1003 
1004 	wiphy_info_max_roc(capa,
1005 			   tb[NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION]);
1006 
1007 	if (tb[NL80211_ATTR_SUPPORT_AP_UAPSD])
1008 		capa->flags |= WPA_DRIVER_FLAGS_AP_UAPSD;
1009 
1010 	wiphy_info_tdls(capa, tb[NL80211_ATTR_TDLS_SUPPORT],
1011 			tb[NL80211_ATTR_TDLS_EXTERNAL_SETUP]);
1012 
1013 	if (tb[NL80211_ATTR_DEVICE_AP_SME]) {
1014 		u32 ap_sme_features_flags =
1015 			nla_get_u32(tb[NL80211_ATTR_DEVICE_AP_SME]);
1016 
1017 		if (ap_sme_features_flags & NL80211_AP_SME_SA_QUERY_OFFLOAD)
1018 			capa->flags2 |= WPA_DRIVER_FLAGS2_SA_QUERY_OFFLOAD_AP;
1019 
1020 		info->device_ap_sme = 1;
1021 	}
1022 
1023 	wiphy_info_feature_flags(info, tb[NL80211_ATTR_FEATURE_FLAGS]);
1024 	wiphy_info_ext_feature_flags(info, tb[NL80211_ATTR_EXT_FEATURES]);
1025 	wiphy_info_probe_resp_offload(capa,
1026 				      tb[NL80211_ATTR_PROBE_RESP_OFFLOAD]);
1027 
1028 	if (tb[NL80211_ATTR_EXT_CAPA] && tb[NL80211_ATTR_EXT_CAPA_MASK] &&
1029 	    drv->extended_capa == NULL) {
1030 		drv->extended_capa =
1031 			os_malloc(nla_len(tb[NL80211_ATTR_EXT_CAPA]));
1032 		if (drv->extended_capa) {
1033 			os_memcpy(drv->extended_capa,
1034 				  nla_data(tb[NL80211_ATTR_EXT_CAPA]),
1035 				  nla_len(tb[NL80211_ATTR_EXT_CAPA]));
1036 			drv->extended_capa_len =
1037 				nla_len(tb[NL80211_ATTR_EXT_CAPA]);
1038 			wpa_hexdump(MSG_DEBUG,
1039 				    "nl80211: Driver-advertised extended capabilities (default)",
1040 				    drv->extended_capa, drv->extended_capa_len);
1041 		}
1042 		drv->extended_capa_mask =
1043 			os_malloc(nla_len(tb[NL80211_ATTR_EXT_CAPA_MASK]));
1044 		if (drv->extended_capa_mask) {
1045 			os_memcpy(drv->extended_capa_mask,
1046 				  nla_data(tb[NL80211_ATTR_EXT_CAPA_MASK]),
1047 				  nla_len(tb[NL80211_ATTR_EXT_CAPA_MASK]));
1048 			wpa_hexdump(MSG_DEBUG,
1049 				    "nl80211: Driver-advertised extended capabilities mask (default)",
1050 				    drv->extended_capa_mask,
1051 				    drv->extended_capa_len);
1052 		} else {
1053 			os_free(drv->extended_capa);
1054 			drv->extended_capa = NULL;
1055 			drv->extended_capa_len = 0;
1056 		}
1057 	}
1058 
1059 	wiphy_info_extended_capab(drv, tb[NL80211_ATTR_IFTYPE_EXT_CAPA]);
1060 
1061 	if (tb[NL80211_ATTR_VENDOR_DATA]) {
1062 		struct nlattr *nl;
1063 		int rem;
1064 
1065 		nla_for_each_nested(nl, tb[NL80211_ATTR_VENDOR_DATA], rem) {
1066 			struct nl80211_vendor_cmd_info *vinfo;
1067 			if (nla_len(nl) != sizeof(*vinfo)) {
1068 				wpa_printf(MSG_DEBUG, "nl80211: Unexpected vendor data info");
1069 				continue;
1070 			}
1071 			vinfo = nla_data(nl);
1072 			if (vinfo->vendor_id == OUI_QCA) {
1073 				switch (vinfo->subcmd) {
1074 				case QCA_NL80211_VENDOR_SUBCMD_TEST:
1075 					drv->vendor_cmd_test_avail = 1;
1076 					break;
1077 #ifdef CONFIG_DRIVER_NL80211_QCA
1078 				case QCA_NL80211_VENDOR_SUBCMD_ROAMING:
1079 					drv->roaming_vendor_cmd_avail = 1;
1080 					break;
1081 				case QCA_NL80211_VENDOR_SUBCMD_DFS_CAPABILITY:
1082 					drv->dfs_vendor_cmd_avail = 1;
1083 					break;
1084 				case QCA_NL80211_VENDOR_SUBCMD_GET_FEATURES:
1085 					drv->get_features_vendor_cmd_avail = 1;
1086 					break;
1087 				case QCA_NL80211_VENDOR_SUBCMD_GET_PREFERRED_FREQ_LIST:
1088 					drv->get_pref_freq_list = 1;
1089 					break;
1090 				case QCA_NL80211_VENDOR_SUBCMD_SET_PROBABLE_OPER_CHANNEL:
1091 					drv->set_prob_oper_freq = 1;
1092 					break;
1093 				case QCA_NL80211_VENDOR_SUBCMD_DO_ACS:
1094 					drv->capa.flags |=
1095 						WPA_DRIVER_FLAGS_ACS_OFFLOAD;
1096 					drv->qca_do_acs = 1;
1097 					break;
1098 				case QCA_NL80211_VENDOR_SUBCMD_SETBAND:
1099 					drv->setband_vendor_cmd_avail = 1;
1100 					break;
1101 				case QCA_NL80211_VENDOR_SUBCMD_TRIGGER_SCAN:
1102 					drv->scan_vendor_cmd_avail = 1;
1103 					break;
1104 				case QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION:
1105 					drv->set_wifi_conf_vendor_cmd_avail = 1;
1106 					break;
1107 				case QCA_NL80211_VENDOR_SUBCMD_FETCH_BSS_TRANSITION_STATUS:
1108 					drv->fetch_bss_trans_status = 1;
1109 					break;
1110 				case QCA_NL80211_VENDOR_SUBCMD_ROAM:
1111 					drv->roam_vendor_cmd_avail = 1;
1112 					break;
1113 				case QCA_NL80211_VENDOR_SUBCMD_ADD_STA_NODE:
1114 					drv->add_sta_node_vendor_cmd_avail = 1;
1115 					break;
1116 				case QCA_NL80211_VENDOR_SUBCMD_GET_STA_INFO:
1117 					drv->get_sta_info_vendor_cmd_avail = 1;
1118 					break;
1119 				case QCA_NL80211_VENDOR_SUBCMD_SECURE_RANGING_CONTEXT:
1120 					drv->secure_ranging_ctx_vendor_cmd_avail = 1;
1121 					break;
1122 				case QCA_NL80211_VENDOR_SUBCMD_CONNECT_EXT:
1123 					drv->connect_ext_vendor_cmd_avail = 1;
1124 					break;
1125 #endif /* CONFIG_DRIVER_NL80211_QCA */
1126 				}
1127 #if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
1128 			} else if (vinfo->vendor_id == OUI_BRCM) {
1129 				switch (vinfo->subcmd) {
1130 				case BRCM_VENDOR_SCMD_ACS:
1131 					drv->capa.flags |=
1132 						WPA_DRIVER_FLAGS_ACS_OFFLOAD;
1133 				    drv->capa.flags |=
1134 						WPA_DRIVER_FLAGS_SUPPORT_HW_MODE_ANY;
1135 					wpa_printf(MSG_DEBUG,
1136 						   "Enabled BRCM ACS");
1137 					drv->brcm_do_acs = 1;
1138 					break;
1139 				case BRCM_VENDOR_SCMD_SET_PMK:
1140 					drv->vendor_set_pmk = 1;
1141 					break;
1142 				default:
1143 					break;
1144 				}
1145 #endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
1146 			}
1147 			wpa_printf(MSG_DEBUG, "nl80211: Supported vendor command: vendor_id=0x%x subcmd=%u",
1148 				   vinfo->vendor_id, vinfo->subcmd);
1149 		}
1150 	}
1151 
1152 	if (tb[NL80211_ATTR_VENDOR_EVENTS]) {
1153 		struct nlattr *nl;
1154 		int rem;
1155 
1156 		nla_for_each_nested(nl, tb[NL80211_ATTR_VENDOR_EVENTS], rem) {
1157 			struct nl80211_vendor_cmd_info *vinfo;
1158 			if (nla_len(nl) != sizeof(*vinfo)) {
1159 				wpa_printf(MSG_DEBUG, "nl80211: Unexpected vendor data info");
1160 				continue;
1161 			}
1162 			vinfo = nla_data(nl);
1163 			wpa_printf(MSG_DEBUG, "nl80211: Supported vendor event: vendor_id=0x%x subcmd=%u",
1164 				   vinfo->vendor_id, vinfo->subcmd);
1165 		}
1166 	}
1167 
1168 	wiphy_info_wowlan_triggers(capa,
1169 				   tb[NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED]);
1170 
1171 	if (tb[NL80211_ATTR_MAX_AP_ASSOC_STA])
1172 		capa->max_stations =
1173 			nla_get_u32(tb[NL80211_ATTR_MAX_AP_ASSOC_STA]);
1174 
1175 	if (tb[NL80211_ATTR_MAX_CSA_COUNTERS])
1176 		capa->max_csa_counters =
1177 			nla_get_u8(tb[NL80211_ATTR_MAX_CSA_COUNTERS]);
1178 
1179 	if (tb[NL80211_ATTR_WIPHY_SELF_MANAGED_REG])
1180 		capa->flags |= WPA_DRIVER_FLAGS_SELF_MANAGED_REGULATORY;
1181 
1182 	if (tb[NL80211_ATTR_MAX_NUM_AKM_SUITES])
1183 		capa->max_num_akms =
1184 			nla_get_u16(tb[NL80211_ATTR_MAX_NUM_AKM_SUITES]);
1185 
1186 	if (tb[NL80211_ATTR_MBSSID_CONFIG])
1187 		wiphy_info_mbssid(capa, tb[NL80211_ATTR_MBSSID_CONFIG]);
1188 
1189 	if (tb[NL80211_ATTR_MLO_SUPPORT])
1190 		capa->flags2 |= WPA_DRIVER_FLAGS2_MLO;
1191 
1192 	return NL_SKIP;
1193 }
1194 
1195 
wpa_driver_nl80211_get_info(struct wpa_driver_nl80211_data * drv,struct wiphy_info_data * info)1196 static int wpa_driver_nl80211_get_info(struct wpa_driver_nl80211_data *drv,
1197 				       struct wiphy_info_data *info)
1198 {
1199 	u32 feat;
1200 	struct nl_msg *msg;
1201 	int flags = 0;
1202 
1203 	os_memset(info, 0, sizeof(*info));
1204 	info->capa = &drv->capa;
1205 	info->drv = drv;
1206 
1207 	feat = get_nl80211_protocol_features(drv);
1208 	if (feat & NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)
1209 		flags = NLM_F_DUMP;
1210 	msg = nl80211_cmd_msg(drv->first_bss, flags, NL80211_CMD_GET_WIPHY);
1211 	if (!msg || nla_put_flag(msg, NL80211_ATTR_SPLIT_WIPHY_DUMP)) {
1212 		nlmsg_free(msg);
1213 		return -1;
1214 	}
1215 
1216 	if (send_and_recv_resp(drv, msg, wiphy_info_handler, info))
1217 		return -1;
1218 
1219 	if (info->auth_supported)
1220 		drv->capa.flags |= WPA_DRIVER_FLAGS_SME;
1221 	else if (!info->connect_supported) {
1222 		wpa_printf(MSG_INFO, "nl80211: Driver does not support "
1223 			   "authentication/association or connect commands");
1224 		info->error = 1;
1225 	}
1226 
1227 	if (info->p2p_go_supported && info->p2p_client_supported)
1228 		drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CAPABLE;
1229 	if (info->p2p_concurrent) {
1230 		wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group "
1231 			   "interface (driver advertised support)");
1232 		drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT;
1233 		drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P;
1234 	}
1235 	if (info->num_multichan_concurrent > 1) {
1236 		wpa_printf(MSG_DEBUG, "nl80211: Enable multi-channel "
1237 			   "concurrent (driver advertised support)");
1238 		drv->capa.num_multichan_concurrent =
1239 			info->num_multichan_concurrent;
1240 	}
1241 	if (drv->capa.flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)
1242 		wpa_printf(MSG_DEBUG, "nl80211: use P2P_DEVICE support");
1243 
1244 	/* default to 5000 since early versions of mac80211 don't set it */
1245 	if (!drv->capa.max_remain_on_chan)
1246 		drv->capa.max_remain_on_chan = 5000;
1247 
1248 	drv->capa.wmm_ac_supported = info->wmm_ac_supported;
1249 
1250 	drv->capa.mac_addr_rand_sched_scan_supported =
1251 		info->mac_addr_rand_sched_scan_supported;
1252 	drv->capa.mac_addr_rand_scan_supported =
1253 		info->mac_addr_rand_scan_supported;
1254 
1255 	if (info->channel_switch_supported) {
1256 		drv->capa.flags |= WPA_DRIVER_FLAGS_AP_CSA;
1257 		if (!drv->capa.max_csa_counters)
1258 			drv->capa.max_csa_counters = 1;
1259 	}
1260 
1261 	if (!drv->capa.max_sched_scan_plans) {
1262 		drv->capa.max_sched_scan_plans = 1;
1263 		drv->capa.max_sched_scan_plan_interval = UINT32_MAX;
1264 		drv->capa.max_sched_scan_plan_iterations = 0;
1265 	}
1266 
1267 	if (info->update_ft_ies_supported)
1268 		drv->capa.flags |= WPA_DRIVER_FLAGS_UPDATE_FT_IES;
1269 
1270 	if (!drv->capa.max_num_akms)
1271 #if defined(CONFIG_DRIVER_NL80211_BRCM) && !defined(WIFI_BRCM_OPEN_SOURCE_MULTI_AKM)
1272 		drv->capa.max_num_akms = 1;
1273 #else
1274 		drv->capa.max_num_akms = NL80211_MAX_NR_AKM_SUITES;
1275 #endif /* CONFIG_DRIVER_NL80211_BRCM && !WIFI_BRCM_OPEN_SOURCE_MULTI_AKM */
1276 
1277 	return 0;
1278 }
1279 
1280 
1281 #ifdef CONFIG_DRIVER_NL80211_QCA
1282 
dfs_info_handler(struct nl_msg * msg,void * arg)1283 static int dfs_info_handler(struct nl_msg *msg, void *arg)
1284 {
1285 	struct nlattr *tb[NL80211_ATTR_MAX + 1];
1286 	struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1287 	int *dfs_capability_ptr = arg;
1288 
1289 	nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1290 		  genlmsg_attrlen(gnlh, 0), NULL);
1291 
1292 	if (tb[NL80211_ATTR_VENDOR_DATA]) {
1293 		struct nlattr *nl_vend = tb[NL80211_ATTR_VENDOR_DATA];
1294 		struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1];
1295 
1296 		nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX,
1297 			  nla_data(nl_vend), nla_len(nl_vend), NULL);
1298 
1299 		if (tb_vendor[QCA_WLAN_VENDOR_ATTR_DFS]) {
1300 			u32 val;
1301 			val = nla_get_u32(tb_vendor[QCA_WLAN_VENDOR_ATTR_DFS]);
1302 			wpa_printf(MSG_DEBUG, "nl80211: DFS offload capability: %u",
1303 				   val);
1304 			*dfs_capability_ptr = val;
1305 		}
1306 	}
1307 
1308 	return NL_SKIP;
1309 }
1310 
1311 
qca_nl80211_check_dfs_capa(struct wpa_driver_nl80211_data * drv)1312 static void qca_nl80211_check_dfs_capa(struct wpa_driver_nl80211_data *drv)
1313 {
1314 	struct nl_msg *msg;
1315 	int dfs_capability = 0;
1316 	int ret;
1317 
1318 	if (!drv->dfs_vendor_cmd_avail)
1319 		return;
1320 
1321 	if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
1322 	    nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
1323 	    nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
1324 			QCA_NL80211_VENDOR_SUBCMD_DFS_CAPABILITY)) {
1325 		nlmsg_free(msg);
1326 		return;
1327 	}
1328 
1329 	ret = send_and_recv_resp(drv, msg, dfs_info_handler, &dfs_capability);
1330 	if (!ret && dfs_capability)
1331 		drv->capa.flags |= WPA_DRIVER_FLAGS_DFS_OFFLOAD;
1332 }
1333 
1334 
1335 struct features_info {
1336 	u8 *flags;
1337 	size_t flags_len;
1338 	struct wpa_driver_capa *capa;
1339 };
1340 
1341 
features_info_handler(struct nl_msg * msg,void * arg)1342 static int features_info_handler(struct nl_msg *msg, void *arg)
1343 {
1344 	struct nlattr *tb[NL80211_ATTR_MAX + 1];
1345 	struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1346 	struct features_info *info = arg;
1347 	struct nlattr *nl_vend, *attr;
1348 
1349 	nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1350 		  genlmsg_attrlen(gnlh, 0), NULL);
1351 
1352 	nl_vend = tb[NL80211_ATTR_VENDOR_DATA];
1353 	if (nl_vend) {
1354 		struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1];
1355 
1356 		nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX,
1357 			  nla_data(nl_vend), nla_len(nl_vend), NULL);
1358 
1359 		attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_FEATURE_FLAGS];
1360 		if (attr) {
1361 			int len = nla_len(attr);
1362 			info->flags = os_malloc(len);
1363 			if (info->flags != NULL) {
1364 				os_memcpy(info->flags, nla_data(attr), len);
1365 				info->flags_len = len;
1366 			}
1367 		}
1368 		attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_CONCURRENCY_CAPA];
1369 		if (attr)
1370 			info->capa->conc_capab = nla_get_u32(attr);
1371 
1372 		attr = tb_vendor[
1373 			QCA_WLAN_VENDOR_ATTR_MAX_CONCURRENT_CHANNELS_2_4_BAND];
1374 		if (attr)
1375 			info->capa->max_conc_chan_2_4 = nla_get_u32(attr);
1376 
1377 		attr = tb_vendor[
1378 			QCA_WLAN_VENDOR_ATTR_MAX_CONCURRENT_CHANNELS_5_0_BAND];
1379 		if (attr)
1380 			info->capa->max_conc_chan_5_0 = nla_get_u32(attr);
1381 	}
1382 
1383 	return NL_SKIP;
1384 }
1385 
1386 
check_feature(enum qca_wlan_vendor_features feature,struct features_info * info)1387 static int check_feature(enum qca_wlan_vendor_features feature,
1388 			 struct features_info *info)
1389 {
1390 	size_t idx = feature / 8;
1391 
1392 	return (idx < info->flags_len) &&
1393 		(info->flags[idx] & BIT(feature % 8));
1394 }
1395 
1396 
qca_nl80211_get_features(struct wpa_driver_nl80211_data * drv)1397 static void qca_nl80211_get_features(struct wpa_driver_nl80211_data *drv)
1398 {
1399 	struct nl_msg *msg;
1400 	struct features_info info;
1401 	int ret;
1402 
1403 	if (!drv->get_features_vendor_cmd_avail)
1404 		return;
1405 
1406 	if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
1407 	    nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
1408 	    nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
1409 			QCA_NL80211_VENDOR_SUBCMD_GET_FEATURES)) {
1410 		nlmsg_free(msg);
1411 		return;
1412 	}
1413 
1414 	os_memset(&info, 0, sizeof(info));
1415 	info.capa = &drv->capa;
1416 	ret = send_and_recv_resp(drv, msg, features_info_handler, &info);
1417 	if (ret || !info.flags)
1418 		return;
1419 
1420 	if (check_feature(QCA_WLAN_VENDOR_FEATURE_KEY_MGMT_OFFLOAD, &info))
1421 		drv->capa.flags |= WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD;
1422 
1423 	if (check_feature(QCA_WLAN_VENDOR_FEATURE_SUPPORT_HW_MODE_ANY, &info))
1424 		drv->capa.flags |= WPA_DRIVER_FLAGS_SUPPORT_HW_MODE_ANY;
1425 
1426 	if (check_feature(QCA_WLAN_VENDOR_FEATURE_OFFCHANNEL_SIMULTANEOUS,
1427 			  &info))
1428 		drv->capa.flags |= WPA_DRIVER_FLAGS_OFFCHANNEL_SIMULTANEOUS;
1429 	if (check_feature(QCA_WLAN_VENDOR_FEATURE_P2P_LISTEN_OFFLOAD, &info))
1430 		drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD;
1431 	if (check_feature(QCA_WLAN_VENDOR_FEATURE_OCE_STA, &info))
1432 		drv->capa.flags |= WPA_DRIVER_FLAGS_OCE_STA;
1433 	if (check_feature(QCA_WLAN_VENDOR_FEATURE_OCE_AP, &info))
1434 		drv->capa.flags |= WPA_DRIVER_FLAGS_OCE_AP;
1435 	if (check_feature(QCA_WLAN_VENDOR_FEATURE_OCE_STA_CFON, &info))
1436 		drv->capa.flags |= WPA_DRIVER_FLAGS_OCE_STA_CFON;
1437 	if (check_feature(QCA_WLAN_VENDOR_FEATURE_SECURE_LTF_STA, &info))
1438 		drv->capa.flags2 |= WPA_DRIVER_FLAGS2_SEC_LTF_STA;
1439 	if (check_feature(QCA_WLAN_VENDOR_FEATURE_SECURE_LTF_AP, &info))
1440 		drv->capa.flags2 |= WPA_DRIVER_FLAGS2_SEC_LTF_AP;
1441 	if (check_feature(QCA_WLAN_VENDOR_FEATURE_SECURE_RTT_STA, &info))
1442 		drv->capa.flags2 |= WPA_DRIVER_FLAGS2_SEC_RTT_STA;
1443 	if (check_feature(QCA_WLAN_VENDOR_FEATURE_SECURE_RTT_AP, &info))
1444 		drv->capa.flags2 |= WPA_DRIVER_FLAGS2_SEC_RTT_AP;
1445 	if (check_feature(
1446 		    QCA_WLAN_VENDOR_FEATURE_PROT_RANGE_NEGO_AND_MEASURE_STA,
1447 		    &info))
1448 		drv->capa.flags2 |= WPA_DRIVER_FLAGS2_PROT_RANGE_NEG_STA;
1449 	if (check_feature(
1450 		    QCA_WLAN_VENDOR_FEATURE_PROT_RANGE_NEGO_AND_MEASURE_AP,
1451 		    &info))
1452 		drv->capa.flags2 |= WPA_DRIVER_FLAGS2_PROT_RANGE_NEG_AP;
1453 	if (check_feature(QCA_WLAN_VENDOR_FEATURE_AP_ALLOWED_FREQ_LIST,
1454 			  &info))
1455 		drv->qca_ap_allowed_freqs = 1;
1456 	if (check_feature(QCA_WLAN_VENDOR_FEATURE_HT_VHT_TWT_RESPONDER, &info))
1457 		drv->capa.flags2 |= WPA_DRIVER_FLAGS2_HT_VHT_TWT_RESPONDER;
1458 	if (check_feature(QCA_WLAN_VENDOR_FEATURE_RSN_OVERRIDE_STA, &info)) {
1459 		wpa_printf(MSG_DEBUG,
1460 			   "The driver supports RSN overriding in STA mode");
1461 		drv->capa.flags2 |= WPA_DRIVER_FLAGS2_RSN_OVERRIDE_STA;
1462 	}
1463 	if (check_feature(QCA_WLAN_VENDOR_FEATURE_NAN_USD_OFFLOAD, &info))
1464 		drv->capa.flags2 |= WPA_DRIVER_FLAGS2_NAN_OFFLOAD;
1465 
1466 	os_free(info.flags);
1467 }
1468 
1469 #endif /* CONFIG_DRIVER_NL80211_QCA */
1470 
1471 
wpa_driver_nl80211_capa(struct wpa_driver_nl80211_data * drv)1472 int wpa_driver_nl80211_capa(struct wpa_driver_nl80211_data *drv)
1473 {
1474 	struct wiphy_info_data info;
1475 	int i;
1476 
1477 	if (wpa_driver_nl80211_get_info(drv, &info))
1478 		return -1;
1479 
1480 	if (info.error)
1481 		return -1;
1482 
1483 	drv->has_capability = 1;
1484 	drv->has_driver_key_mgmt = info.has_key_mgmt | info.has_key_mgmt_iftype;
1485 
1486 	/* Fallback to hardcoded defaults if the driver does not advertise any
1487 	 * AKM capabilities. */
1488 	if (!drv->has_driver_key_mgmt) {
1489 		drv->capa.key_mgmt = WPA_DRIVER_CAPA_KEY_MGMT_WPA |
1490 			WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
1491 			WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
1492 			WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK |
1493 			WPA_DRIVER_CAPA_KEY_MGMT_PSK_SHA256 |
1494 			WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B |
1495 			WPA_DRIVER_CAPA_KEY_MGMT_OWE |
1496 			WPA_DRIVER_CAPA_KEY_MGMT_DPP;
1497 
1498 		if (drv->capa.enc & (WPA_DRIVER_CAPA_ENC_CCMP_256 |
1499 				     WPA_DRIVER_CAPA_ENC_GCMP_256))
1500 			drv->capa.key_mgmt |=
1501 				WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192;
1502 
1503 		if (drv->capa.flags & WPA_DRIVER_FLAGS_SME)
1504 			drv->capa.key_mgmt |=
1505 				WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256 |
1506 				WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384 |
1507 				WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA256 |
1508 				WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA384 |
1509 				WPA_DRIVER_CAPA_KEY_MGMT_SAE_EXT_KEY |
1510 				WPA_DRIVER_CAPA_KEY_MGMT_SAE;
1511 		else if (drv->capa.flags & WPA_DRIVER_FLAGS_FILS_SK_OFFLOAD)
1512 			drv->capa.key_mgmt |=
1513 				WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256 |
1514 				WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384;
1515 	}
1516 
1517 	if (!info.has_key_mgmt_iftype) {
1518 		/* If the driver does not advertize per interface AKM
1519 		 * capabilities, consider all interfaces to support default AKMs
1520 		 * in key_mgmt. */
1521 		for (i = 0; i < WPA_IF_MAX; i++)
1522 			drv->capa.key_mgmt_iftype[i] = drv->capa.key_mgmt;
1523 	} else if (info.has_key_mgmt_iftype && !info.has_key_mgmt) {
1524 		/* If the driver advertizes only per interface supported AKMs
1525 		 * but does not advertize per wiphy AKM capabilities, consider
1526 		 * the default key_mgmt as a mask of per interface supported
1527 		 * AKMs. */
1528 		drv->capa.key_mgmt = 0;
1529 		for (i = 0; i < WPA_IF_MAX; i++)
1530 			drv->capa.key_mgmt |= drv->capa.key_mgmt_iftype[i];
1531 	} else if (info.has_key_mgmt_iftype && info.has_key_mgmt) {
1532 		/* If the driver advertizes AKM capabilities both per wiphy and
1533 		 * per interface, consider the interfaces for which per
1534 		 * interface AKM capabilities were not received to support the
1535 		 * default key_mgmt capabilities.
1536 		 */
1537 		for (i = 0; i < WPA_IF_MAX; i++)
1538 			if (!drv->capa.key_mgmt_iftype[i])
1539 				drv->capa.key_mgmt_iftype[i] =
1540 					drv->capa.key_mgmt;
1541 	}
1542 
1543 	drv->capa.auth = WPA_DRIVER_AUTH_OPEN |
1544 		WPA_DRIVER_AUTH_SHARED |
1545 		WPA_DRIVER_AUTH_LEAP;
1546 
1547 	drv->capa.flags |= WPA_DRIVER_FLAGS_VALID_ERROR_CODES;
1548 	drv->capa.flags |= WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE;
1549 	drv->capa.flags |= WPA_DRIVER_FLAGS_EAPOL_TX_STATUS;
1550 
1551 	/*
1552 	 * As all cfg80211 drivers must support cases where the AP interface is
1553 	 * removed without the knowledge of wpa_supplicant/hostapd, e.g., in
1554 	 * case that the user space daemon has crashed, they must be able to
1555 	 * cleanup all stations and key entries in the AP tear down flow. Thus,
1556 	 * this flag can/should always be set for cfg80211 drivers.
1557 	 */
1558 	drv->capa.flags |= WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT;
1559 
1560 	if (!info.device_ap_sme) {
1561 		drv->capa.flags |= WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS;
1562 		drv->capa.flags2 |= WPA_DRIVER_FLAGS2_AP_SME;
1563 
1564 		/*
1565 		 * No AP SME is currently assumed to also indicate no AP MLME
1566 		 * in the driver/firmware.
1567 		 */
1568 		drv->capa.flags |= WPA_DRIVER_FLAGS_AP_MLME;
1569 	}
1570 
1571 	drv->device_ap_sme = info.device_ap_sme;
1572 	drv->poll_command_supported = info.poll_command_supported;
1573 	drv->data_tx_status = info.data_tx_status;
1574 	drv->p2p_go_ctwindow_supported = info.p2p_go_ctwindow_supported;
1575 	if (info.set_qos_map_supported)
1576 		drv->capa.flags |= WPA_DRIVER_FLAGS_QOS_MAPPING;
1577 	drv->have_low_prio_scan = info.have_low_prio_scan;
1578 
1579 	/*
1580 	 * If poll command and tx status are supported, mac80211 is new enough
1581 	 * to have everything we need to not need monitor interfaces.
1582 	 */
1583 	drv->use_monitor = !info.device_ap_sme &&
1584 		(!info.poll_command_supported || !info.data_tx_status);
1585 
1586 	/*
1587 	 * If we aren't going to use monitor interfaces, but the
1588 	 * driver doesn't support data TX status, we won't get TX
1589 	 * status for EAPOL frames.
1590 	 */
1591 	if (!drv->use_monitor && !info.data_tx_status)
1592 		drv->capa.flags &= ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS;
1593 
1594 #ifdef CONFIG_DRIVER_NL80211_QCA
1595 	if (!(info.capa->flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD))
1596 		qca_nl80211_check_dfs_capa(drv);
1597 	qca_nl80211_get_features(drv);
1598 
1599 	/*
1600 	 * To enable offchannel simultaneous support in wpa_supplicant, the
1601 	 * underlying driver needs to support the same along with offchannel TX.
1602 	 * Offchannel TX support is needed since remain_on_channel and
1603 	 * action_tx use some common data structures and hence cannot be
1604 	 * scheduled simultaneously.
1605 	 */
1606 	if (!(drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX))
1607 		drv->capa.flags &= ~WPA_DRIVER_FLAGS_OFFCHANNEL_SIMULTANEOUS;
1608 #endif /* CONFIG_DRIVER_NL80211_QCA */
1609 
1610 	wpa_printf(MSG_DEBUG,
1611 		   "nl80211: key_mgmt=0x%x enc=0x%x auth=0x%x flags=0x%llx flags2=0x%llx rrm_flags=0x%x probe_resp_offloads=0x%x max_stations=%u max_remain_on_chan=%u max_scan_ssids=%d",
1612 		   drv->capa.key_mgmt, drv->capa.enc, drv->capa.auth,
1613 		   (unsigned long long) drv->capa.flags,
1614 		   (unsigned long long) drv->capa.flags2, drv->capa.rrm_flags,
1615 		   drv->capa.probe_resp_offloads, drv->capa.max_stations,
1616 		   drv->capa.max_remain_on_chan, drv->capa.max_scan_ssids);
1617 	return 0;
1618 }
1619 
1620 
1621 struct phy_info_arg {
1622 	u16 *num_modes;
1623 	struct hostapd_hw_modes *modes;
1624 	int last_mode, last_chan_idx;
1625 	int failed;
1626 	u8 dfs_domain;
1627 };
1628 
phy_info_ht_capa(struct hostapd_hw_modes * mode,struct nlattr * capa,struct nlattr * ampdu_factor,struct nlattr * ampdu_density,struct nlattr * mcs_set)1629 static void phy_info_ht_capa(struct hostapd_hw_modes *mode, struct nlattr *capa,
1630 			     struct nlattr *ampdu_factor,
1631 			     struct nlattr *ampdu_density,
1632 			     struct nlattr *mcs_set)
1633 {
1634 	if (capa)
1635 		mode->ht_capab = nla_get_u16(capa);
1636 
1637 	if (ampdu_factor)
1638 		mode->a_mpdu_params |= nla_get_u8(ampdu_factor) & 0x03;
1639 
1640 	if (ampdu_density)
1641 		mode->a_mpdu_params |= nla_get_u8(ampdu_density) << 2;
1642 
1643 	if (mcs_set && nla_len(mcs_set) >= 16) {
1644 		u8 *mcs;
1645 		mcs = nla_data(mcs_set);
1646 		os_memcpy(mode->mcs_set, mcs, 16);
1647 	}
1648 }
1649 
1650 
phy_info_vht_capa(struct hostapd_hw_modes * mode,struct nlattr * capa,struct nlattr * mcs_set)1651 static void phy_info_vht_capa(struct hostapd_hw_modes *mode,
1652 			      struct nlattr *capa,
1653 			      struct nlattr *mcs_set)
1654 {
1655 	if (capa)
1656 		mode->vht_capab = nla_get_u32(capa);
1657 
1658 	if (mcs_set && nla_len(mcs_set) >= 8) {
1659 		u8 *mcs;
1660 		mcs = nla_data(mcs_set);
1661 		os_memcpy(mode->vht_mcs_set, mcs, 8);
1662 	}
1663 }
1664 
1665 
phy_info_edmg_capa(struct hostapd_hw_modes * mode,struct nlattr * bw_config,struct nlattr * channels)1666 static int phy_info_edmg_capa(struct hostapd_hw_modes *mode,
1667 			      struct nlattr *bw_config,
1668 			      struct nlattr *channels)
1669 {
1670 	if (!bw_config || !channels)
1671 		return NL_OK;
1672 
1673 	mode->edmg.bw_config = nla_get_u8(bw_config);
1674 	mode->edmg.channels = nla_get_u8(channels);
1675 
1676 	if (!mode->edmg.channels || !mode->edmg.bw_config)
1677 		return NL_STOP;
1678 
1679 	return NL_OK;
1680 }
1681 
1682 
cw2ecw(unsigned int cw)1683 static int cw2ecw(unsigned int cw)
1684 {
1685 	int bit;
1686 
1687 	if (cw == 0)
1688 		return 0;
1689 
1690 	for (bit = 1; cw != 1; bit++)
1691 		cw >>= 1;
1692 
1693 	return bit;
1694 }
1695 
1696 
phy_info_freq(struct hostapd_hw_modes * mode,struct hostapd_channel_data * chan,struct nlattr * tb_freq[])1697 static void phy_info_freq(struct hostapd_hw_modes *mode,
1698 			  struct hostapd_channel_data *chan,
1699 			  struct nlattr *tb_freq[])
1700 {
1701 	u8 channel;
1702 
1703 	os_memset(chan, 0, sizeof(*chan));
1704 	chan->freq = nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_FREQ]);
1705 	chan->flag = 0;
1706 	chan->allowed_bw = ~0;
1707 	chan->dfs_cac_ms = 0;
1708 	if (ieee80211_freq_to_chan(chan->freq, &channel) != NUM_HOSTAPD_MODES)
1709 		chan->chan = channel;
1710 	else
1711 		wpa_printf(MSG_DEBUG,
1712 			   "nl80211: No channel number found for frequency %u MHz",
1713 			   chan->freq);
1714 
1715 	if (tb_freq[NL80211_FREQUENCY_ATTR_DISABLED])
1716 		chan->flag |= HOSTAPD_CHAN_DISABLED;
1717 	if (tb_freq[NL80211_FREQUENCY_ATTR_NO_IR])
1718 		chan->flag |= HOSTAPD_CHAN_NO_IR;
1719 	if (tb_freq[NL80211_FREQUENCY_ATTR_RADAR])
1720 		chan->flag |= HOSTAPD_CHAN_RADAR;
1721 	if (tb_freq[NL80211_FREQUENCY_ATTR_INDOOR_ONLY])
1722 		chan->flag |= HOSTAPD_CHAN_INDOOR_ONLY;
1723 	if (tb_freq[NL80211_FREQUENCY_ATTR_GO_CONCURRENT])
1724 		chan->flag |= HOSTAPD_CHAN_GO_CONCURRENT;
1725 
1726 	if (tb_freq[NL80211_FREQUENCY_ATTR_NO_10MHZ])
1727 		chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_10;
1728 	if (tb_freq[NL80211_FREQUENCY_ATTR_NO_20MHZ])
1729 		chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_20;
1730 	if (tb_freq[NL80211_FREQUENCY_ATTR_NO_HT40_PLUS])
1731 		chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_40P;
1732 	if (tb_freq[NL80211_FREQUENCY_ATTR_NO_HT40_MINUS])
1733 		chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_40M;
1734 	if (tb_freq[NL80211_FREQUENCY_ATTR_NO_80MHZ])
1735 		chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_80;
1736 	if (tb_freq[NL80211_FREQUENCY_ATTR_NO_160MHZ])
1737 		chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_160;
1738 
1739 	if (tb_freq[NL80211_FREQUENCY_ATTR_DFS_STATE]) {
1740 		enum nl80211_dfs_state state =
1741 			nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_DFS_STATE]);
1742 
1743 		switch (state) {
1744 		case NL80211_DFS_USABLE:
1745 			chan->flag |= HOSTAPD_CHAN_DFS_USABLE;
1746 			break;
1747 		case NL80211_DFS_AVAILABLE:
1748 			chan->flag |= HOSTAPD_CHAN_DFS_AVAILABLE;
1749 			break;
1750 		case NL80211_DFS_UNAVAILABLE:
1751 			chan->flag |= HOSTAPD_CHAN_DFS_UNAVAILABLE;
1752 			break;
1753 		}
1754 	}
1755 
1756 	if (tb_freq[NL80211_FREQUENCY_ATTR_DFS_CAC_TIME]) {
1757 		chan->dfs_cac_ms = nla_get_u32(
1758 			tb_freq[NL80211_FREQUENCY_ATTR_DFS_CAC_TIME]);
1759 	}
1760 
1761 	chan->wmm_rules_valid = 0;
1762 	if (tb_freq[NL80211_FREQUENCY_ATTR_WMM]) {
1763 		static struct nla_policy wmm_policy[NL80211_WMMR_MAX + 1] = {
1764 			[NL80211_WMMR_CW_MIN] = { .type = NLA_U16 },
1765 			[NL80211_WMMR_CW_MAX] = { .type = NLA_U16 },
1766 			[NL80211_WMMR_AIFSN] = { .type = NLA_U8 },
1767 			[NL80211_WMMR_TXOP] = { .type = NLA_U16 },
1768 		};
1769 		static const u8 wmm_map[4] = {
1770 			[NL80211_AC_BE] = WMM_AC_BE,
1771 			[NL80211_AC_BK] = WMM_AC_BK,
1772 			[NL80211_AC_VI] = WMM_AC_VI,
1773 			[NL80211_AC_VO] = WMM_AC_VO,
1774 		};
1775 		struct nlattr *nl_wmm;
1776 		struct nlattr *tb_wmm[NL80211_WMMR_MAX + 1];
1777 		int rem_wmm, ac, count = 0;
1778 
1779 		nla_for_each_nested(nl_wmm, tb_freq[NL80211_FREQUENCY_ATTR_WMM],
1780 				    rem_wmm) {
1781 			if (nla_parse_nested(tb_wmm, NL80211_WMMR_MAX, nl_wmm,
1782 					     wmm_policy)) {
1783 				wpa_printf(MSG_DEBUG,
1784 					   "nl80211: Failed to parse WMM rules attribute");
1785 				return;
1786 			}
1787 			if (!tb_wmm[NL80211_WMMR_CW_MIN] ||
1788 			    !tb_wmm[NL80211_WMMR_CW_MAX] ||
1789 			    !tb_wmm[NL80211_WMMR_AIFSN] ||
1790 			    !tb_wmm[NL80211_WMMR_TXOP]) {
1791 				wpa_printf(MSG_DEBUG,
1792 					   "nl80211: Channel is missing WMM rule attribute");
1793 				return;
1794 			}
1795 			ac = nl_wmm->nla_type;
1796 			if ((unsigned int) ac >= ARRAY_SIZE(wmm_map)) {
1797 				wpa_printf(MSG_DEBUG,
1798 					   "nl80211: Invalid AC value %d", ac);
1799 				return;
1800 			}
1801 
1802 			ac = wmm_map[ac];
1803 			chan->wmm_rules[ac].min_cwmin =
1804 				cw2ecw(nla_get_u16(
1805 					       tb_wmm[NL80211_WMMR_CW_MIN]));
1806 			chan->wmm_rules[ac].min_cwmax =
1807 				cw2ecw(nla_get_u16(
1808 					       tb_wmm[NL80211_WMMR_CW_MAX]));
1809 			chan->wmm_rules[ac].min_aifs =
1810 				nla_get_u8(tb_wmm[NL80211_WMMR_AIFSN]);
1811 			chan->wmm_rules[ac].max_txop =
1812 				nla_get_u16(tb_wmm[NL80211_WMMR_TXOP]) / 32;
1813 			count++;
1814 		}
1815 
1816 		/* Set valid flag if all the AC rules are present */
1817 		if (count == WMM_AC_NUM)
1818 			chan->wmm_rules_valid = 1;
1819 	}
1820 }
1821 
1822 
phy_info_freqs(struct phy_info_arg * phy_info,struct hostapd_hw_modes * mode,struct nlattr * tb)1823 static int phy_info_freqs(struct phy_info_arg *phy_info,
1824 			  struct hostapd_hw_modes *mode, struct nlattr *tb)
1825 {
1826 	static struct nla_policy freq_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = {
1827 		[NL80211_FREQUENCY_ATTR_FREQ] = { .type = NLA_U32 },
1828 		[NL80211_FREQUENCY_ATTR_DISABLED] = { .type = NLA_FLAG },
1829 		[NL80211_FREQUENCY_ATTR_NO_IR] = { .type = NLA_FLAG },
1830 		[NL80211_FREQUENCY_ATTR_RADAR] = { .type = NLA_FLAG },
1831 		[NL80211_FREQUENCY_ATTR_MAX_TX_POWER] = { .type = NLA_U32 },
1832 		[NL80211_FREQUENCY_ATTR_DFS_STATE] = { .type = NLA_U32 },
1833 		[NL80211_FREQUENCY_ATTR_NO_10MHZ] = { .type = NLA_FLAG },
1834 		[NL80211_FREQUENCY_ATTR_NO_20MHZ] = { .type = NLA_FLAG },
1835 		[NL80211_FREQUENCY_ATTR_NO_HT40_PLUS] = { .type = NLA_FLAG },
1836 		[NL80211_FREQUENCY_ATTR_NO_HT40_MINUS] = { .type = NLA_FLAG },
1837 		[NL80211_FREQUENCY_ATTR_NO_80MHZ] = { .type = NLA_FLAG },
1838 		[NL80211_FREQUENCY_ATTR_NO_160MHZ] = { .type = NLA_FLAG },
1839 	};
1840 	int new_channels = 0;
1841 	struct hostapd_channel_data *channel;
1842 	struct nlattr *tb_freq[NL80211_FREQUENCY_ATTR_MAX + 1];
1843 	struct nlattr *nl_freq;
1844 	int rem_freq, idx;
1845 
1846 	if (tb == NULL)
1847 		return NL_OK;
1848 
1849 	nla_for_each_nested(nl_freq, tb, rem_freq) {
1850 		nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX,
1851 			  nla_data(nl_freq), nla_len(nl_freq), freq_policy);
1852 		if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ])
1853 			continue;
1854 		new_channels++;
1855 	}
1856 
1857 	channel = os_realloc_array(mode->channels,
1858 				   mode->num_channels + new_channels,
1859 				   sizeof(struct hostapd_channel_data));
1860 	if (!channel)
1861 		return NL_STOP;
1862 
1863 	mode->channels = channel;
1864 	mode->num_channels += new_channels;
1865 
1866 	idx = phy_info->last_chan_idx;
1867 
1868 	nla_for_each_nested(nl_freq, tb, rem_freq) {
1869 		nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX,
1870 			  nla_data(nl_freq), nla_len(nl_freq), freq_policy);
1871 		if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ])
1872 			continue;
1873 		phy_info_freq(mode, &mode->channels[idx], tb_freq);
1874 		idx++;
1875 	}
1876 	phy_info->last_chan_idx = idx;
1877 
1878 	return NL_OK;
1879 }
1880 
1881 
phy_info_rates(struct hostapd_hw_modes * mode,struct nlattr * tb)1882 static int phy_info_rates(struct hostapd_hw_modes *mode, struct nlattr *tb)
1883 {
1884 	static struct nla_policy rate_policy[NL80211_BITRATE_ATTR_MAX + 1] = {
1885 		[NL80211_BITRATE_ATTR_RATE] = { .type = NLA_U32 },
1886 		[NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE] =
1887 		{ .type = NLA_FLAG },
1888 	};
1889 	struct nlattr *tb_rate[NL80211_BITRATE_ATTR_MAX + 1];
1890 	struct nlattr *nl_rate;
1891 	int rem_rate, idx;
1892 
1893 	if (tb == NULL)
1894 		return NL_OK;
1895 
1896 	nla_for_each_nested(nl_rate, tb, rem_rate) {
1897 		nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX,
1898 			  nla_data(nl_rate), nla_len(nl_rate),
1899 			  rate_policy);
1900 		if (!tb_rate[NL80211_BITRATE_ATTR_RATE])
1901 			continue;
1902 		mode->num_rates++;
1903 	}
1904 
1905 	mode->rates = os_calloc(mode->num_rates, sizeof(int));
1906 	if (!mode->rates)
1907 		return NL_STOP;
1908 
1909 	idx = 0;
1910 
1911 	nla_for_each_nested(nl_rate, tb, rem_rate) {
1912 		nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX,
1913 			  nla_data(nl_rate), nla_len(nl_rate),
1914 			  rate_policy);
1915 		if (!tb_rate[NL80211_BITRATE_ATTR_RATE])
1916 			continue;
1917 		mode->rates[idx] = nla_get_u32(
1918 			tb_rate[NL80211_BITRATE_ATTR_RATE]);
1919 		idx++;
1920 	}
1921 
1922 	return NL_OK;
1923 }
1924 
1925 
phy_info_iftype_copy(struct hostapd_hw_modes * mode,enum ieee80211_op_mode opmode,struct nlattr ** tb,struct nlattr ** tb_flags)1926 static void phy_info_iftype_copy(struct hostapd_hw_modes *mode,
1927 				 enum ieee80211_op_mode opmode,
1928 				 struct nlattr **tb, struct nlattr **tb_flags)
1929 {
1930 	enum nl80211_iftype iftype;
1931 	size_t len;
1932 	struct he_capabilities *he_capab = &mode->he_capab[opmode];
1933 	struct eht_capabilities *eht_capab = &mode->eht_capab[opmode];
1934 
1935 	switch (opmode) {
1936 	case IEEE80211_MODE_INFRA:
1937 		iftype = NL80211_IFTYPE_STATION;
1938 		break;
1939 	case IEEE80211_MODE_IBSS:
1940 		iftype = NL80211_IFTYPE_ADHOC;
1941 		break;
1942 	case IEEE80211_MODE_AP:
1943 		iftype = NL80211_IFTYPE_AP;
1944 		break;
1945 	case IEEE80211_MODE_MESH:
1946 		iftype = NL80211_IFTYPE_MESH_POINT;
1947 		break;
1948 	default:
1949 		return;
1950 	}
1951 
1952 	if (!nla_get_flag(tb_flags[iftype]))
1953 		return;
1954 
1955 	he_capab->he_supported = 1;
1956 
1957 	if (tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY]) {
1958 		len = nla_len(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY]);
1959 
1960 		if (len > sizeof(he_capab->phy_cap))
1961 			len = sizeof(he_capab->phy_cap);
1962 		os_memcpy(he_capab->phy_cap,
1963 			  nla_data(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY]),
1964 			  len);
1965 	}
1966 
1967 	if (tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC]) {
1968 		len = nla_len(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC]);
1969 
1970 		if (len > sizeof(he_capab->mac_cap))
1971 			len = sizeof(he_capab->mac_cap);
1972 		os_memcpy(he_capab->mac_cap,
1973 			  nla_data(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC]),
1974 			  len);
1975 	}
1976 
1977 	if (tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET]) {
1978 		len = nla_len(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET]);
1979 
1980 		if (len > sizeof(he_capab->mcs))
1981 			len = sizeof(he_capab->mcs);
1982 		os_memcpy(he_capab->mcs,
1983 			  nla_data(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET]),
1984 			  len);
1985 	}
1986 
1987 	if (tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE]) {
1988 		len = nla_len(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE]);
1989 
1990 		if (len > sizeof(he_capab->ppet))
1991 			len = sizeof(he_capab->ppet);
1992 		os_memcpy(&he_capab->ppet,
1993 			  nla_data(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE]),
1994 			  len);
1995 	}
1996 
1997 	if (tb[NL80211_BAND_IFTYPE_ATTR_HE_6GHZ_CAPA]) {
1998 		u16 capa;
1999 
2000 		capa = nla_get_u16(tb[NL80211_BAND_IFTYPE_ATTR_HE_6GHZ_CAPA]);
2001 		he_capab->he_6ghz_capa = le_to_host16(capa);
2002 	}
2003 
2004 	if (!tb[NL80211_BAND_IFTYPE_ATTR_EHT_CAP_MAC] ||
2005 	    !tb[NL80211_BAND_IFTYPE_ATTR_EHT_CAP_PHY])
2006 		return;
2007 
2008 	eht_capab->eht_supported = true;
2009 
2010 	if (tb[NL80211_BAND_IFTYPE_ATTR_EHT_CAP_MAC] &&
2011 	    nla_len(tb[NL80211_BAND_IFTYPE_ATTR_EHT_CAP_MAC]) >= 2) {
2012 		    const u8 *pos;
2013 
2014 		    pos = nla_data(tb[NL80211_BAND_IFTYPE_ATTR_EHT_CAP_MAC]);
2015 		    eht_capab->mac_cap = WPA_GET_LE16(pos);
2016 	}
2017 
2018 	if (tb[NL80211_BAND_IFTYPE_ATTR_EHT_CAP_PHY]) {
2019 		len = nla_len(tb[NL80211_BAND_IFTYPE_ATTR_EHT_CAP_PHY]);
2020 		if (len > sizeof(eht_capab->phy_cap))
2021 			len = sizeof(eht_capab->phy_cap);
2022 		os_memcpy(eht_capab->phy_cap,
2023 			  nla_data(tb[NL80211_BAND_IFTYPE_ATTR_EHT_CAP_PHY]),
2024 			  len);
2025 	}
2026 
2027 	if (tb[NL80211_BAND_IFTYPE_ATTR_EHT_CAP_MCS_SET]) {
2028 		len = nla_len(tb[NL80211_BAND_IFTYPE_ATTR_EHT_CAP_MCS_SET]);
2029 		if (len > sizeof(eht_capab->mcs))
2030 			len = sizeof(eht_capab->mcs);
2031 		os_memcpy(eht_capab->mcs,
2032 			  nla_data(tb[NL80211_BAND_IFTYPE_ATTR_EHT_CAP_MCS_SET]),
2033 			  len);
2034 	}
2035 
2036 	if (tb[NL80211_BAND_IFTYPE_ATTR_EHT_CAP_PPE]) {
2037 		len = nla_len(tb[NL80211_BAND_IFTYPE_ATTR_EHT_CAP_PPE]);
2038 		if (len > sizeof(eht_capab->ppet))
2039 			len = sizeof(eht_capab->ppet);
2040 		os_memcpy(&eht_capab->ppet,
2041 			  nla_data(tb[NL80211_BAND_IFTYPE_ATTR_EHT_CAP_PPE]),
2042 			  len);
2043 	}
2044 }
2045 
2046 
phy_info_iftype(struct hostapd_hw_modes * mode,struct nlattr * nl_iftype)2047 static int phy_info_iftype(struct hostapd_hw_modes *mode,
2048 			   struct nlattr *nl_iftype)
2049 {
2050 	struct nlattr *tb[NL80211_BAND_IFTYPE_ATTR_MAX + 1];
2051 	struct nlattr *tb_flags[NL80211_IFTYPE_MAX + 1];
2052 	unsigned int i;
2053 
2054 	nla_parse(tb, NL80211_BAND_IFTYPE_ATTR_MAX,
2055 		  nla_data(nl_iftype), nla_len(nl_iftype), NULL);
2056 
2057 	if (!tb[NL80211_BAND_IFTYPE_ATTR_IFTYPES])
2058 		return NL_STOP;
2059 
2060 	if (nla_parse_nested(tb_flags, NL80211_IFTYPE_MAX,
2061 			     tb[NL80211_BAND_IFTYPE_ATTR_IFTYPES], NULL))
2062 		return NL_STOP;
2063 
2064 	for (i = 0; i < IEEE80211_MODE_NUM; i++)
2065 		phy_info_iftype_copy(mode, i, tb, tb_flags);
2066 
2067 	return NL_OK;
2068 }
2069 
2070 
phy_info_band(struct phy_info_arg * phy_info,struct nlattr * nl_band)2071 static int phy_info_band(struct phy_info_arg *phy_info, struct nlattr *nl_band)
2072 {
2073 	struct nlattr *tb_band[NL80211_BAND_ATTR_MAX + 1];
2074 	struct hostapd_hw_modes *mode;
2075 	int ret;
2076 
2077 	if (phy_info->last_mode != nl_band->nla_type) {
2078 		mode = os_realloc_array(phy_info->modes,
2079 					*phy_info->num_modes + 1,
2080 					sizeof(*mode));
2081 		if (!mode) {
2082 			phy_info->failed = 1;
2083 			return NL_STOP;
2084 		}
2085 		phy_info->modes = mode;
2086 
2087 		mode = &phy_info->modes[*(phy_info->num_modes)];
2088 		os_memset(mode, 0, sizeof(*mode));
2089 		mode->mode = NUM_HOSTAPD_MODES;
2090 		mode->flags = HOSTAPD_MODE_FLAG_HT_INFO_KNOWN |
2091 			HOSTAPD_MODE_FLAG_VHT_INFO_KNOWN |
2092 			HOSTAPD_MODE_FLAG_HE_INFO_KNOWN;
2093 
2094 		/*
2095 		 * Unsupported VHT MCS stream is defined as value 3, so the VHT
2096 		 * MCS RX/TX map must be initialized with 0xffff to mark all 8
2097 		 * possible streams as unsupported. This will be overridden if
2098 		 * driver advertises VHT support.
2099 		 */
2100 		mode->vht_mcs_set[0] = 0xff;
2101 		mode->vht_mcs_set[1] = 0xff;
2102 		mode->vht_mcs_set[4] = 0xff;
2103 		mode->vht_mcs_set[5] = 0xff;
2104 
2105 		*(phy_info->num_modes) += 1;
2106 		phy_info->last_mode = nl_band->nla_type;
2107 		phy_info->last_chan_idx = 0;
2108 	} else
2109 		mode = &phy_info->modes[*(phy_info->num_modes) - 1];
2110 
2111 	nla_parse(tb_band, NL80211_BAND_ATTR_MAX, nla_data(nl_band),
2112 		  nla_len(nl_band), NULL);
2113 
2114 	phy_info_ht_capa(mode, tb_band[NL80211_BAND_ATTR_HT_CAPA],
2115 			 tb_band[NL80211_BAND_ATTR_HT_AMPDU_FACTOR],
2116 			 tb_band[NL80211_BAND_ATTR_HT_AMPDU_DENSITY],
2117 			 tb_band[NL80211_BAND_ATTR_HT_MCS_SET]);
2118 	phy_info_vht_capa(mode, tb_band[NL80211_BAND_ATTR_VHT_CAPA],
2119 			  tb_band[NL80211_BAND_ATTR_VHT_MCS_SET]);
2120 	ret = phy_info_edmg_capa(mode,
2121 				 tb_band[NL80211_BAND_ATTR_EDMG_BW_CONFIG],
2122 				 tb_band[NL80211_BAND_ATTR_EDMG_CHANNELS]);
2123 	if (ret == NL_OK)
2124 		ret = phy_info_freqs(phy_info, mode,
2125 				     tb_band[NL80211_BAND_ATTR_FREQS]);
2126 	if (ret == NL_OK)
2127 		ret = phy_info_rates(mode, tb_band[NL80211_BAND_ATTR_RATES]);
2128 	if (ret != NL_OK) {
2129 		phy_info->failed = 1;
2130 		return ret;
2131 	}
2132 
2133 	if (tb_band[NL80211_BAND_ATTR_IFTYPE_DATA]) {
2134 		struct nlattr *nl_iftype;
2135 		int rem_band;
2136 
2137 		nla_for_each_nested(nl_iftype,
2138 				    tb_band[NL80211_BAND_ATTR_IFTYPE_DATA],
2139 				    rem_band) {
2140 			ret = phy_info_iftype(mode, nl_iftype);
2141 			if (ret != NL_OK)
2142 				return ret;
2143 		}
2144 	}
2145 
2146 	return NL_OK;
2147 }
2148 
2149 
phy_info_handler(struct nl_msg * msg,void * arg)2150 static int phy_info_handler(struct nl_msg *msg, void *arg)
2151 {
2152 	struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
2153 	struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
2154 	struct phy_info_arg *phy_info = arg;
2155 	struct nlattr *nl_band;
2156 	int rem_band;
2157 
2158 	nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
2159 		  genlmsg_attrlen(gnlh, 0), NULL);
2160 
2161 	if (!tb_msg[NL80211_ATTR_WIPHY_BANDS])
2162 		return NL_SKIP;
2163 
2164 	nla_for_each_nested(nl_band, tb_msg[NL80211_ATTR_WIPHY_BANDS], rem_band)
2165 	{
2166 		int res = phy_info_band(phy_info, nl_band);
2167 		if (res != NL_OK)
2168 			return res;
2169 	}
2170 
2171 	return NL_SKIP;
2172 }
2173 
2174 
2175 static struct hostapd_hw_modes *
wpa_driver_nl80211_postprocess_modes(struct hostapd_hw_modes * modes,u16 * num_modes)2176 wpa_driver_nl80211_postprocess_modes(struct hostapd_hw_modes *modes,
2177 				     u16 *num_modes)
2178 {
2179 	u16 m;
2180 	struct hostapd_hw_modes *mode11g = NULL, *nmodes, *mode;
2181 	int i, mode11g_idx = -1;
2182 
2183 	/* heuristic to set up modes */
2184 	for (m = 0; m < *num_modes; m++) {
2185 		if (!modes[m].num_channels)
2186 			continue;
2187 
2188 		modes[m].is_6ghz = false;
2189 
2190 		if (modes[m].channels[0].freq < 2000) {
2191 			modes[m].num_channels = 0;
2192 			continue;
2193 		} else if (modes[m].channels[0].freq < 4000) {
2194 			modes[m].mode = HOSTAPD_MODE_IEEE80211B;
2195 			for (i = 0; i < modes[m].num_rates; i++) {
2196 				if (modes[m].rates[i] > 200) {
2197 					modes[m].mode = HOSTAPD_MODE_IEEE80211G;
2198 					break;
2199 				}
2200 			}
2201 		} else if (modes[m].channels[0].freq > 50000) {
2202 			modes[m].mode = HOSTAPD_MODE_IEEE80211AD;
2203 		} else if (is_6ghz_freq(modes[m].channels[0].freq)) {
2204 			modes[m].mode = HOSTAPD_MODE_IEEE80211A;
2205 			modes[m].is_6ghz = true;
2206 		} else {
2207 			modes[m].mode = HOSTAPD_MODE_IEEE80211A;
2208 		}
2209 	}
2210 
2211 	/* Remove unsupported bands */
2212 	m = 0;
2213 	while (m < *num_modes) {
2214 		if (modes[m].mode == NUM_HOSTAPD_MODES) {
2215 			wpa_printf(MSG_DEBUG,
2216 				   "nl80211: Remove unsupported mode");
2217 			os_free(modes[m].channels);
2218 			os_free(modes[m].rates);
2219 			if (m + 1 < *num_modes)
2220 				os_memmove(&modes[m], &modes[m + 1],
2221 					   sizeof(struct hostapd_hw_modes) *
2222 					   (*num_modes - (m + 1)));
2223 			(*num_modes)--;
2224 			continue;
2225 		}
2226 		m++;
2227 	}
2228 
2229 	/* If only 802.11g mode is included, use it to construct matching
2230 	 * 802.11b mode data. */
2231 
2232 	for (m = 0; m < *num_modes; m++) {
2233 		if (modes[m].mode == HOSTAPD_MODE_IEEE80211B)
2234 			return modes; /* 802.11b already included */
2235 		if (modes[m].mode == HOSTAPD_MODE_IEEE80211G)
2236 			mode11g_idx = m;
2237 	}
2238 
2239 	if (mode11g_idx < 0)
2240 		return modes; /* 2.4 GHz band not supported at all */
2241 
2242 	nmodes = os_realloc_array(modes, *num_modes + 1, sizeof(*nmodes));
2243 	if (nmodes == NULL)
2244 		return modes; /* Could not add 802.11b mode */
2245 
2246 	mode = &nmodes[*num_modes];
2247 	os_memset(mode, 0, sizeof(*mode));
2248 	(*num_modes)++;
2249 	modes = nmodes;
2250 
2251 	mode->mode = HOSTAPD_MODE_IEEE80211B;
2252 
2253 	mode11g = &modes[mode11g_idx];
2254 	mode->num_channels = mode11g->num_channels;
2255 	mode->channels = os_memdup(mode11g->channels,
2256 				   mode11g->num_channels *
2257 				   sizeof(struct hostapd_channel_data));
2258 	if (mode->channels == NULL) {
2259 		(*num_modes)--;
2260 		return modes; /* Could not add 802.11b mode */
2261 	}
2262 
2263 	mode->num_rates = 0;
2264 	mode->rates = os_malloc(4 * sizeof(int));
2265 	if (mode->rates == NULL) {
2266 		os_free(mode->channels);
2267 		(*num_modes)--;
2268 		return modes; /* Could not add 802.11b mode */
2269 	}
2270 
2271 	for (i = 0; i < mode11g->num_rates; i++) {
2272 		if (mode11g->rates[i] != 10 && mode11g->rates[i] != 20 &&
2273 		    mode11g->rates[i] != 55 && mode11g->rates[i] != 110)
2274 			continue;
2275 		mode->rates[mode->num_rates] = mode11g->rates[i];
2276 		mode->num_rates++;
2277 		if (mode->num_rates == 4)
2278 			break;
2279 	}
2280 
2281 	if (mode->num_rates == 0) {
2282 		os_free(mode->channels);
2283 		os_free(mode->rates);
2284 		(*num_modes)--;
2285 		return modes; /* No 802.11b rates */
2286 	}
2287 
2288 	wpa_printf(MSG_DEBUG, "nl80211: Added 802.11b mode based on 802.11g "
2289 		   "information");
2290 
2291 	return modes;
2292 }
2293 
2294 
nl80211_set_ht40_mode(struct hostapd_hw_modes * mode,int start,int end)2295 static void nl80211_set_ht40_mode(struct hostapd_hw_modes *mode, int start,
2296 				  int end)
2297 {
2298 	int c;
2299 
2300 	for (c = 0; c < mode->num_channels; c++) {
2301 		struct hostapd_channel_data *chan = &mode->channels[c];
2302 		if (chan->freq - 10 >= start && chan->freq + 10 <= end)
2303 			chan->flag |= HOSTAPD_CHAN_HT40;
2304 	}
2305 }
2306 
2307 
nl80211_set_ht40_mode_sec(struct hostapd_hw_modes * mode,int start,int end)2308 static void nl80211_set_ht40_mode_sec(struct hostapd_hw_modes *mode, int start,
2309 				      int end)
2310 {
2311 	int c;
2312 
2313 	for (c = 0; c < mode->num_channels; c++) {
2314 		struct hostapd_channel_data *chan = &mode->channels[c];
2315 		if (!(chan->flag & HOSTAPD_CHAN_HT40))
2316 			continue;
2317 		if (chan->freq - 30 >= start && chan->freq - 10 <= end)
2318 			chan->flag |= HOSTAPD_CHAN_HT40MINUS;
2319 		if (chan->freq + 10 >= start && chan->freq + 30 <= end)
2320 			chan->flag |= HOSTAPD_CHAN_HT40PLUS;
2321 	}
2322 }
2323 
2324 
nl80211_reg_rule_max_eirp(u32 start,u32 end,u32 max_eirp,struct phy_info_arg * results)2325 static void nl80211_reg_rule_max_eirp(u32 start, u32 end, u32 max_eirp,
2326 				      struct phy_info_arg *results)
2327 {
2328 	u16 m;
2329 
2330 	for (m = 0; m < *results->num_modes; m++) {
2331 		int c;
2332 		struct hostapd_hw_modes *mode = &results->modes[m];
2333 
2334 		for (c = 0; c < mode->num_channels; c++) {
2335 			struct hostapd_channel_data *chan = &mode->channels[c];
2336 			if ((u32) chan->freq - 10 >= start &&
2337 			    (u32) chan->freq + 10 <= end)
2338 				chan->max_tx_power = max_eirp;
2339 		}
2340 	}
2341 }
2342 
2343 
nl80211_reg_rule_ht40(u32 start,u32 end,struct phy_info_arg * results)2344 static void nl80211_reg_rule_ht40(u32 start, u32 end,
2345 				  struct phy_info_arg *results)
2346 {
2347 	u16 m;
2348 
2349 	for (m = 0; m < *results->num_modes; m++) {
2350 		if (!(results->modes[m].ht_capab &
2351 		      HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET))
2352 			continue;
2353 		nl80211_set_ht40_mode(&results->modes[m], start, end);
2354 	}
2355 }
2356 
2357 
nl80211_reg_rule_sec(struct nlattr * tb[],struct phy_info_arg * results)2358 static void nl80211_reg_rule_sec(struct nlattr *tb[],
2359 				 struct phy_info_arg *results)
2360 {
2361 	u32 start, end, max_bw;
2362 	u16 m;
2363 
2364 	if (tb[NL80211_ATTR_FREQ_RANGE_START] == NULL ||
2365 	    tb[NL80211_ATTR_FREQ_RANGE_END] == NULL ||
2366 	    tb[NL80211_ATTR_FREQ_RANGE_MAX_BW] == NULL)
2367 		return;
2368 
2369 	start = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]) / 1000;
2370 	end = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]) / 1000;
2371 	max_bw = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) / 1000;
2372 
2373 	if (max_bw < 20)
2374 		return;
2375 
2376 	for (m = 0; m < *results->num_modes; m++) {
2377 		if (!(results->modes[m].ht_capab &
2378 		      HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET))
2379 			continue;
2380 		nl80211_set_ht40_mode_sec(&results->modes[m], start, end);
2381 	}
2382 }
2383 
2384 
nl80211_set_vht_mode(struct hostapd_hw_modes * mode,int start,int end,int max_bw)2385 static void nl80211_set_vht_mode(struct hostapd_hw_modes *mode, int start,
2386 				 int end, int max_bw)
2387 {
2388 	int c;
2389 
2390 	for (c = 0; c < mode->num_channels; c++) {
2391 		struct hostapd_channel_data *chan = &mode->channels[c];
2392 
2393 		if (chan->freq - 10 < start || chan->freq + 10 > end)
2394 			continue;
2395 
2396 		if (max_bw >= 80)
2397 			chan->flag |= HOSTAPD_CHAN_VHT_80MHZ_SUBCHANNEL;
2398 
2399 		if (max_bw >= 160)
2400 			chan->flag |= HOSTAPD_CHAN_VHT_160MHZ_SUBCHANNEL;
2401 	}
2402 }
2403 
2404 
nl80211_reg_rule_vht(struct nlattr * tb[],struct phy_info_arg * results)2405 static void nl80211_reg_rule_vht(struct nlattr *tb[],
2406 				 struct phy_info_arg *results)
2407 {
2408 	u32 start, end, max_bw;
2409 	u16 m;
2410 
2411 	if (tb[NL80211_ATTR_FREQ_RANGE_START] == NULL ||
2412 	    tb[NL80211_ATTR_FREQ_RANGE_END] == NULL ||
2413 	    tb[NL80211_ATTR_FREQ_RANGE_MAX_BW] == NULL)
2414 		return;
2415 
2416 	start = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]) / 1000;
2417 	end = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]) / 1000;
2418 	max_bw = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) / 1000;
2419 
2420 	if (max_bw < 80)
2421 		return;
2422 
2423 	for (m = 0; m < *results->num_modes; m++) {
2424 		if (!(results->modes[m].ht_capab &
2425 		      HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET))
2426 			continue;
2427 		/* TODO: use a real VHT support indication */
2428 		if (!results->modes[m].vht_capab)
2429 			continue;
2430 
2431 		nl80211_set_vht_mode(&results->modes[m], start, end, max_bw);
2432 	}
2433 }
2434 
2435 
nl80211_set_6ghz_mode(struct hostapd_hw_modes * mode,int start,int end,int max_bw)2436 static void nl80211_set_6ghz_mode(struct hostapd_hw_modes *mode, int start,
2437 				  int end, int max_bw)
2438 {
2439 	int c;
2440 
2441 	for (c = 0; c < mode->num_channels; c++) {
2442 		struct hostapd_channel_data *chan = &mode->channels[c];
2443 
2444 		if (chan->freq - 10 < start || chan->freq + 10 > end)
2445 			continue;
2446 
2447 		if (max_bw >= 80)
2448 			chan->flag |= HOSTAPD_CHAN_VHT_80MHZ_SUBCHANNEL;
2449 
2450 		if (max_bw >= 160)
2451 			chan->flag |= HOSTAPD_CHAN_VHT_160MHZ_SUBCHANNEL;
2452 
2453 		if (max_bw >= 320)
2454 			chan->flag |= HOSTAPD_CHAN_EHT_320MHZ_SUBCHANNEL;
2455 	}
2456 }
2457 
2458 
nl80211_reg_rule_6ghz(struct nlattr * tb[],struct phy_info_arg * results)2459 static void nl80211_reg_rule_6ghz(struct nlattr *tb[],
2460 				 struct phy_info_arg *results)
2461 {
2462 	u32 start, end, max_bw;
2463 	u16 m;
2464 
2465 	if (!tb[NL80211_ATTR_FREQ_RANGE_START] ||
2466 	    !tb[NL80211_ATTR_FREQ_RANGE_END] ||
2467 	    !tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
2468 		return;
2469 
2470 	start = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]) / 1000;
2471 	end = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]) / 1000;
2472 	max_bw = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) / 1000;
2473 
2474 	if (max_bw < 80)
2475 		return;
2476 
2477 	for (m = 0; m < *results->num_modes; m++) {
2478 		if (results->modes[m].num_channels == 0 ||
2479 		    !is_6ghz_freq(results->modes[m].channels[0].freq))
2480 			continue;
2481 
2482 		nl80211_set_6ghz_mode(&results->modes[m], start, end, max_bw);
2483 	}
2484 }
2485 
2486 
nl80211_set_dfs_domain(enum nl80211_dfs_regions region,u8 * dfs_domain)2487 static void nl80211_set_dfs_domain(enum nl80211_dfs_regions region,
2488 				   u8 *dfs_domain)
2489 {
2490 	if (region == NL80211_DFS_FCC)
2491 		*dfs_domain = HOSTAPD_DFS_REGION_FCC;
2492 	else if (region == NL80211_DFS_ETSI)
2493 		*dfs_domain = HOSTAPD_DFS_REGION_ETSI;
2494 	else if (region == NL80211_DFS_JP)
2495 		*dfs_domain = HOSTAPD_DFS_REGION_JP;
2496 	else
2497 		*dfs_domain = 0;
2498 }
2499 
2500 
dfs_domain_name(enum nl80211_dfs_regions region)2501 static const char * dfs_domain_name(enum nl80211_dfs_regions region)
2502 {
2503 	switch (region) {
2504 	case NL80211_DFS_UNSET:
2505 		return "DFS-UNSET";
2506 	case NL80211_DFS_FCC:
2507 		return "DFS-FCC";
2508 	case NL80211_DFS_ETSI:
2509 		return "DFS-ETSI";
2510 	case NL80211_DFS_JP:
2511 		return "DFS-JP";
2512 	default:
2513 		return "DFS-invalid";
2514 	}
2515 }
2516 
2517 
nl80211_get_reg(struct nl_msg * msg,void * arg)2518 static int nl80211_get_reg(struct nl_msg *msg, void *arg)
2519 {
2520 	struct phy_info_arg *results = arg;
2521 	struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
2522 	struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
2523 	struct nlattr *nl_rule;
2524 	struct nlattr *tb_rule[NL80211_FREQUENCY_ATTR_MAX + 1];
2525 	int rem_rule;
2526 	static struct nla_policy reg_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = {
2527 		[NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
2528 		[NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
2529 		[NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
2530 		[NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
2531 		[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
2532 		[NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
2533 	};
2534 
2535 	nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
2536 		  genlmsg_attrlen(gnlh, 0), NULL);
2537 	if (!tb_msg[NL80211_ATTR_REG_ALPHA2] ||
2538 	    !tb_msg[NL80211_ATTR_REG_RULES]) {
2539 		wpa_printf(MSG_DEBUG, "nl80211: No regulatory information "
2540 			   "available");
2541 		return NL_SKIP;
2542 	}
2543 
2544 	if (tb_msg[NL80211_ATTR_DFS_REGION]) {
2545 		enum nl80211_dfs_regions dfs_domain;
2546 		dfs_domain = nla_get_u8(tb_msg[NL80211_ATTR_DFS_REGION]);
2547 		nl80211_set_dfs_domain(dfs_domain, &results->dfs_domain);
2548 		wpa_printf(MSG_DEBUG, "nl80211: Regulatory information - country=%s (%s)",
2549 			   (char *) nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]),
2550 			   dfs_domain_name(dfs_domain));
2551 	} else {
2552 		wpa_printf(MSG_DEBUG, "nl80211: Regulatory information - country=%s",
2553 			   (char *) nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]));
2554 	}
2555 
2556 	nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule)
2557 	{
2558 		u32 start, end, max_eirp = 0, max_bw = 0, flags = 0;
2559 		nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX,
2560 			  nla_data(nl_rule), nla_len(nl_rule), reg_policy);
2561 		if (tb_rule[NL80211_ATTR_FREQ_RANGE_START] == NULL ||
2562 		    tb_rule[NL80211_ATTR_FREQ_RANGE_END] == NULL)
2563 			continue;
2564 		start = nla_get_u32(tb_rule[NL80211_ATTR_FREQ_RANGE_START]) / 1000;
2565 		end = nla_get_u32(tb_rule[NL80211_ATTR_FREQ_RANGE_END]) / 1000;
2566 		if (tb_rule[NL80211_ATTR_POWER_RULE_MAX_EIRP])
2567 			max_eirp = nla_get_u32(tb_rule[NL80211_ATTR_POWER_RULE_MAX_EIRP]) / 100;
2568 		if (tb_rule[NL80211_ATTR_FREQ_RANGE_MAX_BW])
2569 			max_bw = nla_get_u32(tb_rule[NL80211_ATTR_FREQ_RANGE_MAX_BW]) / 1000;
2570 		if (tb_rule[NL80211_ATTR_REG_RULE_FLAGS])
2571 			flags = nla_get_u32(tb_rule[NL80211_ATTR_REG_RULE_FLAGS]);
2572 
2573 		wpa_printf(MSG_DEBUG, "nl80211: %u-%u @ %u MHz %u mBm%s%s%s%s%s%s%s%s",
2574 			   start, end, max_bw, max_eirp,
2575 			   flags & NL80211_RRF_NO_OFDM ? " (no OFDM)" : "",
2576 			   flags & NL80211_RRF_NO_CCK ? " (no CCK)" : "",
2577 			   flags & NL80211_RRF_NO_INDOOR ? " (no indoor)" : "",
2578 			   flags & NL80211_RRF_NO_OUTDOOR ? " (no outdoor)" :
2579 			   "",
2580 			   flags & NL80211_RRF_DFS ? " (DFS)" : "",
2581 			   flags & NL80211_RRF_PTP_ONLY ? " (PTP only)" : "",
2582 			   flags & NL80211_RRF_PTMP_ONLY ? " (PTMP only)" : "",
2583 			   flags & NL80211_RRF_NO_IR ? " (no IR)" : "");
2584 		if (max_bw >= 40)
2585 			nl80211_reg_rule_ht40(start, end, results);
2586 		if (tb_rule[NL80211_ATTR_POWER_RULE_MAX_EIRP])
2587 			nl80211_reg_rule_max_eirp(start, end, max_eirp,
2588 						  results);
2589 	}
2590 
2591 	nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule)
2592 	{
2593 		nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX,
2594 			  nla_data(nl_rule), nla_len(nl_rule), reg_policy);
2595 		nl80211_reg_rule_sec(tb_rule, results);
2596 	}
2597 
2598 	nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule)
2599 	{
2600 		nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX,
2601 			  nla_data(nl_rule), nla_len(nl_rule), reg_policy);
2602 		nl80211_reg_rule_vht(tb_rule, results);
2603 	}
2604 
2605 	nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule)
2606 	{
2607 		nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX,
2608 			  nla_data(nl_rule), nla_len(nl_rule), reg_policy);
2609 		nl80211_reg_rule_6ghz(tb_rule, results);
2610 	}
2611 
2612 	return NL_SKIP;
2613 }
2614 
2615 
nl80211_set_regulatory_flags(struct wpa_driver_nl80211_data * drv,struct phy_info_arg * results)2616 static int nl80211_set_regulatory_flags(struct wpa_driver_nl80211_data *drv,
2617 					struct phy_info_arg *results)
2618 {
2619 	struct nl_msg *msg;
2620 
2621 	msg = nlmsg_alloc();
2622 	if (!msg)
2623 		return -ENOMEM;
2624 
2625 	nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG);
2626 	if (drv->capa.flags & WPA_DRIVER_FLAGS_SELF_MANAGED_REGULATORY) {
2627 		if (nla_put_u32(msg, NL80211_ATTR_WIPHY, drv->wiphy_idx)) {
2628 			nlmsg_free(msg);
2629 			return -1;
2630 		}
2631 	}
2632 
2633 	return send_and_recv_resp(drv, msg, nl80211_get_reg, results);
2634 }
2635 
2636 
modestr(enum hostapd_hw_mode mode)2637 static const char * modestr(enum hostapd_hw_mode mode)
2638 {
2639 	switch (mode) {
2640 	case HOSTAPD_MODE_IEEE80211B:
2641 		return "802.11b";
2642 	case HOSTAPD_MODE_IEEE80211G:
2643 		return "802.11g";
2644 	case HOSTAPD_MODE_IEEE80211A:
2645 		return "802.11a";
2646 	case HOSTAPD_MODE_IEEE80211AD:
2647 		return "802.11ad";
2648 	default:
2649 		return "?";
2650 	}
2651 }
2652 
2653 
nl80211_dump_chan_list(struct wpa_driver_nl80211_data * drv,struct hostapd_hw_modes * modes,u16 num_modes)2654 static void nl80211_dump_chan_list(struct wpa_driver_nl80211_data *drv,
2655 				   struct hostapd_hw_modes *modes,
2656 				   u16 num_modes)
2657 {
2658 	int i;
2659 
2660 	if (!modes)
2661 		return;
2662 
2663 	for (i = 0; i < num_modes; i++) {
2664 		struct hostapd_hw_modes *mode = &modes[i];
2665 		char str[1000];
2666 		char *pos = str;
2667 		char *end = pos + sizeof(str);
2668 		int j, res;
2669 
2670 		for (j = 0; j < mode->num_channels; j++) {
2671 			struct hostapd_channel_data *chan = &mode->channels[j];
2672 
2673 			if (is_6ghz_freq(chan->freq))
2674 				drv->uses_6ghz = true;
2675 			if (chan->freq >= 900 && chan->freq < 1000)
2676 				drv->uses_s1g = true;
2677 			res = os_snprintf(pos, end - pos, " %d%s%s%s",
2678 					  chan->freq,
2679 					  (chan->flag & HOSTAPD_CHAN_DISABLED) ?
2680 					  "[DISABLED]" : "",
2681 					  (chan->flag & HOSTAPD_CHAN_NO_IR) ?
2682 					  "[NO_IR]" : "",
2683 					  (chan->flag & HOSTAPD_CHAN_RADAR) ?
2684 					  "[RADAR]" : "");
2685 			if (os_snprintf_error(end - pos, res))
2686 				break;
2687 			pos += res;
2688 		}
2689 
2690 		*pos = '\0';
2691 		wpa_printf(MSG_DEBUG, "nl80211: Mode IEEE %s:%s",
2692 			   modestr(mode->mode), str);
2693 	}
2694 }
2695 
2696 
2697 struct hostapd_hw_modes *
nl80211_get_hw_feature_data(void * priv,u16 * num_modes,u16 * flags,u8 * dfs_domain)2698 nl80211_get_hw_feature_data(void *priv, u16 *num_modes, u16 *flags,
2699 			    u8 *dfs_domain)
2700 {
2701 	u32 feat;
2702 	struct i802_bss *bss = priv;
2703 	struct wpa_driver_nl80211_data *drv = bss->drv;
2704 	int nl_flags = 0;
2705 	struct nl_msg *msg;
2706 	struct phy_info_arg result = {
2707 		.num_modes = num_modes,
2708 		.modes = NULL,
2709 		.last_mode = -1,
2710 		.failed = 0,
2711 		.dfs_domain = 0,
2712 	};
2713 
2714 	*num_modes = 0;
2715 	*flags = 0;
2716 	*dfs_domain = 0;
2717 
2718 	feat = get_nl80211_protocol_features(drv);
2719 	if (feat & NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)
2720 		nl_flags = NLM_F_DUMP;
2721 	if (!(msg = nl80211_cmd_msg(bss, nl_flags, NL80211_CMD_GET_WIPHY)) ||
2722 	    nla_put_flag(msg, NL80211_ATTR_SPLIT_WIPHY_DUMP)) {
2723 		nlmsg_free(msg);
2724 		return NULL;
2725 	}
2726 
2727 	if (send_and_recv_resp(drv, msg, phy_info_handler, &result) == 0) {
2728 		struct hostapd_hw_modes *modes;
2729 
2730 		nl80211_set_regulatory_flags(drv, &result);
2731 		if (result.failed) {
2732 			int i;
2733 
2734 			for (i = 0; result.modes && i < *num_modes; i++) {
2735 				os_free(result.modes[i].channels);
2736 				os_free(result.modes[i].rates);
2737 			}
2738 			os_free(result.modes);
2739 			*num_modes = 0;
2740 			return NULL;
2741 		}
2742 
2743 		*dfs_domain = result.dfs_domain;
2744 
2745 		modes = wpa_driver_nl80211_postprocess_modes(result.modes,
2746 							     num_modes);
2747 		nl80211_dump_chan_list(drv, modes, *num_modes);
2748 		return modes;
2749 	}
2750 
2751 	return NULL;
2752 }
2753 
2754 
phy_multi_hw_info_parse(struct hostapd_multi_hw_info * hw_info,struct nlattr * radio_attr)2755 static int phy_multi_hw_info_parse(struct hostapd_multi_hw_info *hw_info,
2756 				   struct nlattr *radio_attr)
2757 {
2758 	struct nlattr *tb_freq[NL80211_WIPHY_RADIO_FREQ_ATTR_MAX + 1];
2759 	int start_freq, end_freq;
2760 
2761 	switch (nla_type(radio_attr)) {
2762 	case NL80211_WIPHY_RADIO_ATTR_INDEX:
2763 		hw_info->hw_idx = nla_get_u32(radio_attr);
2764 		return NL_OK;
2765 	case NL80211_WIPHY_RADIO_ATTR_FREQ_RANGE:
2766 		if (nla_parse_nested(tb_freq, NL80211_WIPHY_RADIO_FREQ_ATTR_MAX,
2767 				     radio_attr, NULL) ||
2768 		    !tb_freq[NL80211_WIPHY_RADIO_FREQ_ATTR_START] ||
2769 		    !tb_freq[NL80211_WIPHY_RADIO_FREQ_ATTR_END])
2770 			return NL_STOP;
2771 
2772 		start_freq = nla_get_u32(
2773 			tb_freq[NL80211_WIPHY_RADIO_FREQ_ATTR_START]);
2774 		end_freq = nla_get_u32(
2775 			tb_freq[NL80211_WIPHY_RADIO_FREQ_ATTR_END]);
2776 
2777 		/* Convert to MHz and store */
2778 		hw_info->start_freq = start_freq / 1000;
2779 		hw_info->end_freq = end_freq / 1000;
2780 		return NL_OK;
2781 	default:
2782 		return NL_OK;
2783 	}
2784 }
2785 
2786 
2787 struct phy_multi_hw_info_arg {
2788 	bool failed;
2789 	unsigned int *num_multi_hws;
2790 	struct hostapd_multi_hw_info *multi_hws;
2791 };
2792 
2793 
phy_multi_hw_info_handler(struct nl_msg * msg,void * arg)2794 static int phy_multi_hw_info_handler(struct nl_msg *msg, void *arg)
2795 {
2796 	struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
2797 	struct phy_multi_hw_info_arg *multi_hw_info = arg;
2798 	struct hostapd_multi_hw_info *multi_hws, hw_info;
2799 	struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
2800 	struct nlattr *nl_hw, *radio_attr;
2801 	int rem_hw, rem_radio_prop, res;
2802 
2803 	nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
2804 		  genlmsg_attrlen(gnlh, 0), NULL);
2805 
2806 	if (!tb_msg[NL80211_ATTR_WIPHY_RADIOS])
2807 		return NL_SKIP;
2808 
2809 	*multi_hw_info->num_multi_hws = 0;
2810 
2811 	nla_for_each_nested(nl_hw, tb_msg[NL80211_ATTR_WIPHY_RADIOS], rem_hw) {
2812 		os_memset(&hw_info, 0, sizeof(hw_info));
2813 
2814 		nla_for_each_nested(radio_attr, nl_hw, rem_radio_prop) {
2815 			res = phy_multi_hw_info_parse(&hw_info, radio_attr);
2816 			if (res != NL_OK)
2817 				goto out;
2818 		}
2819 
2820 		if (hw_info.start_freq == 0 || hw_info.end_freq == 0)
2821 			goto out;
2822 
2823 		multi_hws = os_realloc_array(multi_hw_info->multi_hws,
2824 					     *multi_hw_info->num_multi_hws + 1,
2825 					     sizeof(*multi_hws));
2826 		if (!multi_hws)
2827 			goto out;
2828 
2829 		multi_hw_info->multi_hws = multi_hws;
2830 		os_memcpy(&multi_hws[*(multi_hw_info->num_multi_hws)],
2831 			  &hw_info, sizeof(struct hostapd_multi_hw_info));
2832 		*(multi_hw_info->num_multi_hws) += 1;
2833 	}
2834 
2835 	return NL_OK;
2836 out:
2837 	multi_hw_info->failed = true;
2838 	return NL_STOP;
2839 }
2840 
2841 
2842 struct hostapd_multi_hw_info *
nl80211_get_multi_hw_info(struct i802_bss * bss,unsigned int * num_multi_hws)2843 nl80211_get_multi_hw_info(struct i802_bss *bss, unsigned int *num_multi_hws)
2844 {
2845 	u32 feat;
2846 	struct wpa_driver_nl80211_data *drv = bss->drv;
2847 	int nl_flags = 0;
2848 	struct nl_msg *msg;
2849 	struct phy_multi_hw_info_arg result = {
2850 		.failed = false,
2851 		.num_multi_hws = num_multi_hws,
2852 		.multi_hws = NULL,
2853 	};
2854 
2855 	*num_multi_hws = 0;
2856 
2857 	if (!drv->has_capability || !(drv->capa.flags2 & WPA_DRIVER_FLAGS2_MLO))
2858 		return NULL;
2859 
2860 	feat = get_nl80211_protocol_features(drv);
2861 	if (feat & NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)
2862 		nl_flags = NLM_F_DUMP;
2863 	if (!(msg = nl80211_cmd_msg(bss, nl_flags, NL80211_CMD_GET_WIPHY)) ||
2864 	    nla_put_flag(msg, NL80211_ATTR_SPLIT_WIPHY_DUMP)) {
2865 		nlmsg_free(msg);
2866 		return NULL;
2867 	}
2868 
2869 	if (send_and_recv_resp(drv, msg, phy_multi_hw_info_handler,
2870 			       &result) == 0) {
2871 		if (result.failed) {
2872 			os_free(result.multi_hws);
2873 			*num_multi_hws = 0;
2874 			return NULL;
2875 		}
2876 
2877 		return result.multi_hws;
2878 	}
2879 
2880 	return NULL;
2881 }
2882