• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Driver interaction with Linux nl80211/cfg80211 - Capabilities
3  * Copyright (c) 2002-2015, Jouni Malinen <j@w1.fi>
4  * Copyright (c) 2007, Johannes Berg <johannes@sipsolutions.net>
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 "driver_nl80211.h"
20 
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_msgs(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_802_1X_SHA384:
297 			key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT_802_1X_SHA384;
298 			break;
299 		case RSN_AUTH_KEY_MGMT_CCKM:
300 			key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_CCKM;
301 			break;
302 		case RSN_AUTH_KEY_MGMT_OSEN:
303 			key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_OSEN;
304 			break;
305 		case RSN_AUTH_KEY_MGMT_802_1X_SUITE_B:
306 			key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B;
307 			break;
308 		case RSN_AUTH_KEY_MGMT_802_1X_SUITE_B_192:
309 			key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192;
310 			break;
311 		case RSN_AUTH_KEY_MGMT_OWE:
312 			key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_OWE;
313 			break;
314 		case RSN_AUTH_KEY_MGMT_DPP:
315 			key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_DPP;
316 			break;
317 		case RSN_AUTH_KEY_MGMT_FILS_SHA256:
318 			key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256;
319 			break;
320 		case RSN_AUTH_KEY_MGMT_FILS_SHA384:
321 			key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384;
322 			break;
323 		case RSN_AUTH_KEY_MGMT_FT_FILS_SHA256:
324 			key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA256;
325 			break;
326 		case RSN_AUTH_KEY_MGMT_FT_FILS_SHA384:
327 			key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA384;
328 			break;
329 		case RSN_AUTH_KEY_MGMT_SAE:
330 			key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_SAE;
331 			break;
332 		}
333 	}
334 
335 	return key_mgmt;
336 }
337 
338 
get_iface_akm_suites_info(struct wiphy_info_data * info,struct nlattr * nl_akms)339 static void get_iface_akm_suites_info(struct wiphy_info_data *info,
340 					struct nlattr *nl_akms)
341 {
342 	struct nlattr *tb[NL80211_IFTYPE_AKM_ATTR_MAX + 1];
343 	struct nlattr *nl_iftype;
344 	unsigned int key_mgmt;
345 	int i;
346 
347 	if (!nl_akms)
348 		return;
349 
350 	nla_parse(tb, NL80211_IFTYPE_AKM_ATTR_MAX,
351 		  nla_data(nl_akms), nla_len(nl_akms), NULL);
352 
353 	if (!tb[NL80211_IFTYPE_AKM_ATTR_IFTYPES] ||
354 	    !tb[NL80211_IFTYPE_AKM_ATTR_SUITES])
355 		return;
356 
357 	info->has_key_mgmt_iftype = 1;
358 	key_mgmt = get_akm_suites_info(tb[NL80211_IFTYPE_AKM_ATTR_SUITES]);
359 
360 	nla_for_each_nested(nl_iftype, tb[NL80211_IFTYPE_AKM_ATTR_IFTYPES], i) {
361 		switch (nla_type(nl_iftype)) {
362 		case NL80211_IFTYPE_ADHOC:
363 			info->drv->capa.key_mgmt_iftype[WPA_IF_IBSS] = key_mgmt;
364 			break;
365 		case NL80211_IFTYPE_STATION:
366 			info->drv->capa.key_mgmt_iftype[WPA_IF_STATION] =
367 				key_mgmt;
368 			break;
369 		case NL80211_IFTYPE_AP:
370 			info->drv->capa.key_mgmt_iftype[WPA_IF_AP_BSS] =
371 				key_mgmt;
372 			break;
373 		case NL80211_IFTYPE_AP_VLAN:
374 			info->drv->capa.key_mgmt_iftype[WPA_IF_AP_VLAN] =
375 				key_mgmt;
376 			break;
377 		case NL80211_IFTYPE_MESH_POINT:
378 			info->drv->capa.key_mgmt_iftype[WPA_IF_MESH] = key_mgmt;
379 			break;
380 		case NL80211_IFTYPE_P2P_CLIENT:
381 			info->drv->capa.key_mgmt_iftype[WPA_IF_P2P_CLIENT] =
382 				key_mgmt;
383 			break;
384 		case NL80211_IFTYPE_P2P_GO:
385 			info->drv->capa.key_mgmt_iftype[WPA_IF_P2P_GO] =
386 				key_mgmt;
387 			break;
388 		case NL80211_IFTYPE_P2P_DEVICE:
389 			info->drv->capa.key_mgmt_iftype[WPA_IF_P2P_DEVICE] =
390 				key_mgmt;
391 			break;
392 		case NL80211_IFTYPE_NAN:
393 			info->drv->capa.key_mgmt_iftype[WPA_IF_NAN] = key_mgmt;
394 			break;
395 		}
396 		wpa_printf(MSG_DEBUG, "nl80211: %s supported key_mgmt 0x%x",
397 			   nl80211_iftype_str(nla_type(nl_iftype)),
398 			   key_mgmt);
399 	}
400 }
401 
402 
wiphy_info_iftype_akm_suites(struct wiphy_info_data * info,struct nlattr * tb)403 static void wiphy_info_iftype_akm_suites(struct wiphy_info_data *info,
404 					 struct nlattr *tb)
405 {
406 	struct nlattr *nl_if;
407 	int rem_if;
408 
409 	if (!tb)
410 		return;
411 
412 	nla_for_each_nested(nl_if, tb, rem_if)
413 		get_iface_akm_suites_info(info, nl_if);
414 }
415 
416 
wiphy_info_akm_suites(struct wiphy_info_data * info,struct nlattr * tb)417 static void wiphy_info_akm_suites(struct wiphy_info_data *info,
418 				  struct nlattr *tb)
419 {
420 	if (!tb)
421 		return;
422 
423 	info->has_key_mgmt = 1;
424 	info->capa->key_mgmt = get_akm_suites_info(tb);
425 	wpa_printf(MSG_DEBUG, "nl80211: wiphy supported key_mgmt 0x%x",
426 		   info->capa->key_mgmt);
427 }
428 
429 
wiphy_info_cipher_suites(struct wiphy_info_data * info,struct nlattr * tb)430 static void wiphy_info_cipher_suites(struct wiphy_info_data *info,
431 				     struct nlattr *tb)
432 {
433 	int i, num;
434 	u32 *ciphers;
435 
436 	if (tb == NULL)
437 		return;
438 
439 	num = nla_len(tb) / sizeof(u32);
440 	ciphers = nla_data(tb);
441 	for (i = 0; i < num; i++) {
442 		u32 c = ciphers[i];
443 
444 		wpa_printf(MSG_DEBUG, "nl80211: Supported cipher %02x-%02x-%02x:%d",
445 			   c >> 24, (c >> 16) & 0xff,
446 			   (c >> 8) & 0xff, c & 0xff);
447 		switch (c) {
448 		case RSN_CIPHER_SUITE_CCMP_256:
449 			info->capa->enc |= WPA_DRIVER_CAPA_ENC_CCMP_256;
450 			break;
451 		case RSN_CIPHER_SUITE_GCMP_256:
452 			info->capa->enc |= WPA_DRIVER_CAPA_ENC_GCMP_256;
453 			break;
454 		case RSN_CIPHER_SUITE_CCMP:
455 			info->capa->enc |= WPA_DRIVER_CAPA_ENC_CCMP;
456 			break;
457 		case RSN_CIPHER_SUITE_GCMP:
458 			info->capa->enc |= WPA_DRIVER_CAPA_ENC_GCMP;
459 			break;
460 		case RSN_CIPHER_SUITE_TKIP:
461 			info->capa->enc |= WPA_DRIVER_CAPA_ENC_TKIP;
462 			break;
463 		case RSN_CIPHER_SUITE_WEP104:
464 			info->capa->enc |= WPA_DRIVER_CAPA_ENC_WEP104;
465 			break;
466 		case RSN_CIPHER_SUITE_WEP40:
467 			info->capa->enc |= WPA_DRIVER_CAPA_ENC_WEP40;
468 			break;
469 		case RSN_CIPHER_SUITE_AES_128_CMAC:
470 			info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP;
471 			break;
472 		case RSN_CIPHER_SUITE_BIP_GMAC_128:
473 			info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP_GMAC_128;
474 			break;
475 		case RSN_CIPHER_SUITE_BIP_GMAC_256:
476 			info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP_GMAC_256;
477 			break;
478 		case RSN_CIPHER_SUITE_BIP_CMAC_256:
479 			info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP_CMAC_256;
480 			break;
481 		case RSN_CIPHER_SUITE_NO_GROUP_ADDRESSED:
482 			info->capa->enc |= WPA_DRIVER_CAPA_ENC_GTK_NOT_USED;
483 			break;
484 		}
485 	}
486 }
487 
488 
wiphy_info_max_roc(struct wpa_driver_capa * capa,struct nlattr * tb)489 static void wiphy_info_max_roc(struct wpa_driver_capa *capa,
490 			       struct nlattr *tb)
491 {
492 	if (tb)
493 		capa->max_remain_on_chan = nla_get_u32(tb);
494 }
495 
496 
wiphy_info_tdls(struct wpa_driver_capa * capa,struct nlattr * tdls,struct nlattr * ext_setup)497 static void wiphy_info_tdls(struct wpa_driver_capa *capa, struct nlattr *tdls,
498 			    struct nlattr *ext_setup)
499 {
500 	if (tdls == NULL)
501 		return;
502 
503 	wpa_printf(MSG_DEBUG, "nl80211: TDLS supported");
504 	capa->flags |= WPA_DRIVER_FLAGS_TDLS_SUPPORT;
505 
506 	if (ext_setup) {
507 		wpa_printf(MSG_DEBUG, "nl80211: TDLS external setup");
508 		capa->flags |= WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP;
509 	}
510 }
511 
512 
ext_feature_isset(const u8 * ext_features,int ext_features_len,enum nl80211_ext_feature_index ftidx)513 static int ext_feature_isset(const u8 *ext_features, int ext_features_len,
514 			     enum nl80211_ext_feature_index ftidx)
515 {
516 	u8 ft_byte;
517 
518 	if ((int) ftidx / 8 >= ext_features_len)
519 		return 0;
520 
521 	ft_byte = ext_features[ftidx / 8];
522 	return (ft_byte & BIT(ftidx % 8)) != 0;
523 }
524 
525 
wiphy_info_ext_feature_flags(struct wiphy_info_data * info,struct nlattr * tb)526 static void wiphy_info_ext_feature_flags(struct wiphy_info_data *info,
527 					 struct nlattr *tb)
528 {
529 	struct wpa_driver_capa *capa = info->capa;
530 	u8 *ext_features;
531 	int len;
532 
533 	if (tb == NULL)
534 		return;
535 
536 	ext_features = nla_data(tb);
537 	len = nla_len(tb);
538 
539 	if (ext_feature_isset(ext_features, len, NL80211_EXT_FEATURE_VHT_IBSS))
540 		capa->flags |= WPA_DRIVER_FLAGS_VHT_IBSS;
541 
542 	if (ext_feature_isset(ext_features, len, NL80211_EXT_FEATURE_RRM))
543 		capa->rrm_flags |= WPA_DRIVER_FLAGS_SUPPORT_RRM;
544 
545 	if (ext_feature_isset(ext_features, len, NL80211_EXT_FEATURE_FILS_STA))
546 		capa->flags |= WPA_DRIVER_FLAGS_SUPPORT_FILS;
547 
548 	if (ext_feature_isset(ext_features, len,
549 			      NL80211_EXT_FEATURE_BEACON_RATE_LEGACY))
550 		capa->flags |= WPA_DRIVER_FLAGS_BEACON_RATE_LEGACY;
551 
552 	if (ext_feature_isset(ext_features, len,
553 			      NL80211_EXT_FEATURE_BEACON_RATE_HT))
554 		capa->flags |= WPA_DRIVER_FLAGS_BEACON_RATE_HT;
555 
556 	if (ext_feature_isset(ext_features, len,
557 			      NL80211_EXT_FEATURE_BEACON_RATE_VHT))
558 		capa->flags |= WPA_DRIVER_FLAGS_BEACON_RATE_VHT;
559 
560 	if (ext_feature_isset(ext_features, len,
561 			      NL80211_EXT_FEATURE_SET_SCAN_DWELL))
562 		capa->rrm_flags |= WPA_DRIVER_FLAGS_SUPPORT_SET_SCAN_DWELL;
563 
564 	if (ext_feature_isset(ext_features, len,
565 			      NL80211_EXT_FEATURE_SCAN_START_TIME) &&
566 	    ext_feature_isset(ext_features, len,
567 			      NL80211_EXT_FEATURE_BSS_PARENT_TSF) &&
568 	    ext_feature_isset(ext_features, len,
569 			      NL80211_EXT_FEATURE_SET_SCAN_DWELL))
570 		capa->rrm_flags |= WPA_DRIVER_FLAGS_SUPPORT_BEACON_REPORT;
571 	if (ext_feature_isset(ext_features, len,
572 			      NL80211_EXT_FEATURE_MGMT_TX_RANDOM_TA))
573 		capa->flags |= WPA_DRIVER_FLAGS_MGMT_TX_RANDOM_TA;
574 	if (ext_feature_isset(ext_features, len,
575 			      NL80211_EXT_FEATURE_MGMT_TX_RANDOM_TA_CONNECTED))
576 		capa->flags |= WPA_DRIVER_FLAGS_MGMT_TX_RANDOM_TA_CONNECTED;
577 	if (ext_feature_isset(ext_features, len,
578 			      NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI))
579 		capa->flags |= WPA_DRIVER_FLAGS_SCHED_SCAN_RELATIVE_RSSI;
580 	if (ext_feature_isset(ext_features, len,
581 			      NL80211_EXT_FEATURE_FILS_SK_OFFLOAD))
582 		capa->flags |= WPA_DRIVER_FLAGS_FILS_SK_OFFLOAD;
583 
584 	if (ext_feature_isset(ext_features, len,
585 			      NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK))
586 		capa->flags |= WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK;
587 	if (ext_feature_isset(ext_features, len,
588 			      NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
589 		capa->flags |= WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X;
590 
591 	if (ext_feature_isset(ext_features, len,
592 			      NL80211_EXT_FEATURE_MFP_OPTIONAL))
593 		capa->flags |= WPA_DRIVER_FLAGS_MFP_OPTIONAL;
594 
595 	if (ext_feature_isset(ext_features, len,
596 			      NL80211_EXT_FEATURE_DFS_OFFLOAD))
597 		capa->flags |= WPA_DRIVER_FLAGS_DFS_OFFLOAD;
598 
599 #ifdef CONFIG_MBO
600 	if (ext_feature_isset(ext_features, len,
601 			      NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME) &&
602 	    ext_feature_isset(ext_features, len,
603 			      NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP) &&
604 	    ext_feature_isset(ext_features, len,
605 			      NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE) &&
606 	    ext_feature_isset(
607 		    ext_features, len,
608 		    NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION))
609 		capa->flags |= WPA_DRIVER_FLAGS_OCE_STA;
610 #endif /* CONFIG_MBO */
611 
612 	if (ext_feature_isset(ext_features, len,
613 			      NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER))
614 		capa->flags |= WPA_DRIVER_FLAGS_FTM_RESPONDER;
615 
616 	if (ext_feature_isset(ext_features, len,
617 			      NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211))
618 		capa->flags |= WPA_DRIVER_FLAGS_CONTROL_PORT;
619 	if (ext_feature_isset(ext_features, len,
620 			      NL80211_EXT_FEATURE_CONTROL_PORT_NO_PREAUTH))
621 		capa->flags2 |= WPA_DRIVER_FLAGS2_CONTROL_PORT_RX;
622 
623 	if (ext_feature_isset(ext_features, len,
624 			      NL80211_EXT_FEATURE_VLAN_OFFLOAD))
625 		capa->flags |= WPA_DRIVER_FLAGS_VLAN_OFFLOAD;
626 
627 	if (ext_feature_isset(ext_features, len,
628 			      NL80211_EXT_FEATURE_CAN_REPLACE_PTK0))
629 		capa->flags |= WPA_DRIVER_FLAGS_SAFE_PTK0_REKEYS;
630 
631 	if (ext_feature_isset(ext_features, len,
632 			      NL80211_EXT_FEATURE_BEACON_PROTECTION))
633 		capa->flags |= WPA_DRIVER_FLAGS_BEACON_PROTECTION;
634 
635 	if (ext_feature_isset(ext_features, len,
636 			      NL80211_EXT_FEATURE_EXT_KEY_ID))
637 		capa->flags |= WPA_DRIVER_FLAGS_EXTENDED_KEY_ID;
638 
639 	if (ext_feature_isset(ext_features, len,
640 			      NL80211_EXT_FEATURE_MULTICAST_REGISTRATIONS))
641 		info->drv->multicast_registrations = 1;
642 }
643 
644 
wiphy_info_feature_flags(struct wiphy_info_data * info,struct nlattr * tb)645 static void wiphy_info_feature_flags(struct wiphy_info_data *info,
646 				     struct nlattr *tb)
647 {
648 	u32 flags;
649 	struct wpa_driver_capa *capa = info->capa;
650 
651 	if (tb == NULL)
652 		return;
653 
654 	flags = nla_get_u32(tb);
655 
656 	if (flags & NL80211_FEATURE_SK_TX_STATUS)
657 		info->data_tx_status = 1;
658 
659 	if (flags & NL80211_FEATURE_INACTIVITY_TIMER)
660 		capa->flags |= WPA_DRIVER_FLAGS_INACTIVITY_TIMER;
661 
662 	if (flags & NL80211_FEATURE_SAE)
663 		capa->flags |= WPA_DRIVER_FLAGS_SAE;
664 
665 	if (flags & NL80211_FEATURE_NEED_OBSS_SCAN)
666 		capa->flags |= WPA_DRIVER_FLAGS_OBSS_SCAN;
667 
668 	if (flags & NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)
669 		capa->flags |= WPA_DRIVER_FLAGS_HT_2040_COEX;
670 
671 	if (flags & NL80211_FEATURE_TDLS_CHANNEL_SWITCH) {
672 		wpa_printf(MSG_DEBUG, "nl80211: TDLS channel switch");
673 		capa->flags |= WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH;
674 	}
675 
676 	if (flags & NL80211_FEATURE_P2P_GO_CTWIN)
677 		info->p2p_go_ctwindow_supported = 1;
678 
679 	if (flags & NL80211_FEATURE_LOW_PRIORITY_SCAN)
680 		info->have_low_prio_scan = 1;
681 
682 	if (flags & NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)
683 		info->mac_addr_rand_scan_supported = 1;
684 
685 	if (flags & NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR)
686 		info->mac_addr_rand_sched_scan_supported = 1;
687 
688 	if (flags & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
689 		info->wmm_ac_supported = 1;
690 
691 	if (flags & NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES)
692 		capa->rrm_flags |= WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES;
693 
694 	if (flags & NL80211_FEATURE_WFA_TPC_IE_IN_PROBES)
695 		capa->rrm_flags |= WPA_DRIVER_FLAGS_WFA_TPC_IE_IN_PROBES;
696 
697 	if (flags & NL80211_FEATURE_QUIET)
698 		capa->rrm_flags |= WPA_DRIVER_FLAGS_QUIET;
699 
700 	if (flags & NL80211_FEATURE_TX_POWER_INSERTION)
701 		capa->rrm_flags |= WPA_DRIVER_FLAGS_TX_POWER_INSERTION;
702 
703 	if (flags & NL80211_FEATURE_HT_IBSS)
704 		capa->flags |= WPA_DRIVER_FLAGS_HT_IBSS;
705 
706 	if (flags & NL80211_FEATURE_FULL_AP_CLIENT_STATE)
707 		capa->flags |= WPA_DRIVER_FLAGS_FULL_AP_CLIENT_STATE;
708 }
709 
710 
wiphy_info_probe_resp_offload(struct wpa_driver_capa * capa,struct nlattr * tb)711 static void wiphy_info_probe_resp_offload(struct wpa_driver_capa *capa,
712 					  struct nlattr *tb)
713 {
714 	u32 protocols;
715 
716 	if (tb == NULL)
717 		return;
718 
719 	protocols = nla_get_u32(tb);
720 	wpa_printf(MSG_DEBUG, "nl80211: Supports Probe Response offload in AP "
721 		   "mode");
722 	capa->flags |= WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD;
723 	capa->probe_resp_offloads = probe_resp_offload_support(protocols);
724 }
725 
726 
wiphy_info_wowlan_triggers(struct wpa_driver_capa * capa,struct nlattr * tb)727 static void wiphy_info_wowlan_triggers(struct wpa_driver_capa *capa,
728 				       struct nlattr *tb)
729 {
730 	struct nlattr *triggers[MAX_NL80211_WOWLAN_TRIG + 1];
731 
732 	if (tb == NULL)
733 		return;
734 
735 	if (nla_parse_nested(triggers, MAX_NL80211_WOWLAN_TRIG,
736 			     tb, NULL))
737 		return;
738 
739 	if (triggers[NL80211_WOWLAN_TRIG_ANY])
740 		capa->wowlan_triggers.any = 1;
741 	if (triggers[NL80211_WOWLAN_TRIG_DISCONNECT])
742 		capa->wowlan_triggers.disconnect = 1;
743 	if (triggers[NL80211_WOWLAN_TRIG_MAGIC_PKT])
744 		capa->wowlan_triggers.magic_pkt = 1;
745 	if (triggers[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE])
746 		capa->wowlan_triggers.gtk_rekey_failure = 1;
747 	if (triggers[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST])
748 		capa->wowlan_triggers.eap_identity_req = 1;
749 	if (triggers[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE])
750 		capa->wowlan_triggers.four_way_handshake = 1;
751 	if (triggers[NL80211_WOWLAN_TRIG_RFKILL_RELEASE])
752 		capa->wowlan_triggers.rfkill_release = 1;
753 }
754 
755 
wiphy_info_extended_capab(struct wpa_driver_nl80211_data * drv,struct nlattr * tb)756 static void wiphy_info_extended_capab(struct wpa_driver_nl80211_data *drv,
757 				      struct nlattr *tb)
758 {
759 	int rem = 0, i;
760 	struct nlattr *tb1[NL80211_ATTR_MAX + 1], *attr;
761 
762 	if (!tb || drv->num_iface_ext_capa == NL80211_IFTYPE_MAX)
763 		return;
764 
765 	nla_for_each_nested(attr, tb, rem) {
766 		unsigned int len;
767 		struct drv_nl80211_ext_capa *capa;
768 
769 		nla_parse(tb1, NL80211_ATTR_MAX, nla_data(attr),
770 			  nla_len(attr), NULL);
771 
772 		if (!tb1[NL80211_ATTR_IFTYPE] ||
773 		    !tb1[NL80211_ATTR_EXT_CAPA] ||
774 		    !tb1[NL80211_ATTR_EXT_CAPA_MASK])
775 			continue;
776 
777 		capa = &drv->iface_ext_capa[drv->num_iface_ext_capa];
778 		capa->iftype = nla_get_u32(tb1[NL80211_ATTR_IFTYPE]);
779 		wpa_printf(MSG_DEBUG,
780 			   "nl80211: Driver-advertised extended capabilities for interface type %s",
781 			   nl80211_iftype_str(capa->iftype));
782 
783 		len = nla_len(tb1[NL80211_ATTR_EXT_CAPA]);
784 		capa->ext_capa = os_memdup(nla_data(tb1[NL80211_ATTR_EXT_CAPA]),
785 					   len);
786 		if (!capa->ext_capa)
787 			goto err;
788 
789 		capa->ext_capa_len = len;
790 		wpa_hexdump(MSG_DEBUG, "nl80211: Extended capabilities",
791 			    capa->ext_capa, capa->ext_capa_len);
792 
793 		len = nla_len(tb1[NL80211_ATTR_EXT_CAPA_MASK]);
794 		capa->ext_capa_mask =
795 			os_memdup(nla_data(tb1[NL80211_ATTR_EXT_CAPA_MASK]),
796 				  len);
797 		if (!capa->ext_capa_mask)
798 			goto err;
799 
800 		wpa_hexdump(MSG_DEBUG, "nl80211: Extended capabilities mask",
801 			    capa->ext_capa_mask, capa->ext_capa_len);
802 
803 		drv->num_iface_ext_capa++;
804 		if (drv->num_iface_ext_capa == NL80211_IFTYPE_MAX)
805 			break;
806 	}
807 
808 	return;
809 
810 err:
811 	/* Cleanup allocated memory on error */
812 	for (i = 0; i < NL80211_IFTYPE_MAX; i++) {
813 		os_free(drv->iface_ext_capa[i].ext_capa);
814 		drv->iface_ext_capa[i].ext_capa = NULL;
815 		os_free(drv->iface_ext_capa[i].ext_capa_mask);
816 		drv->iface_ext_capa[i].ext_capa_mask = NULL;
817 		drv->iface_ext_capa[i].ext_capa_len = 0;
818 	}
819 	drv->num_iface_ext_capa = 0;
820 }
821 
822 
wiphy_info_handler(struct nl_msg * msg,void * arg)823 static int wiphy_info_handler(struct nl_msg *msg, void *arg)
824 {
825 	struct nlattr *tb[NL80211_ATTR_MAX + 1];
826 	struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
827 	struct wiphy_info_data *info = arg;
828 	struct wpa_driver_capa *capa = info->capa;
829 	struct wpa_driver_nl80211_data *drv = info->drv;
830 
831 	nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
832 		  genlmsg_attrlen(gnlh, 0), NULL);
833 
834 	if (tb[NL80211_ATTR_WIPHY])
835 		drv->wiphy_idx = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
836 
837 	if (tb[NL80211_ATTR_WIPHY_NAME])
838 		os_strlcpy(drv->phyname,
839 			   nla_get_string(tb[NL80211_ATTR_WIPHY_NAME]),
840 			   sizeof(drv->phyname));
841 	if (tb[NL80211_ATTR_MAX_NUM_SCAN_SSIDS])
842 		capa->max_scan_ssids =
843 			nla_get_u8(tb[NL80211_ATTR_MAX_NUM_SCAN_SSIDS]);
844 
845 	if (tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS])
846 		capa->max_sched_scan_ssids =
847 			nla_get_u8(tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS]);
848 
849 	if (tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS] &&
850 	    tb[NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL] &&
851 	    tb[NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS]) {
852 		capa->max_sched_scan_plans =
853 			nla_get_u32(tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS]);
854 
855 		capa->max_sched_scan_plan_interval =
856 			nla_get_u32(tb[NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL]);
857 
858 		capa->max_sched_scan_plan_iterations =
859 			nla_get_u32(tb[NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS]);
860 	}
861 
862 	if (tb[NL80211_ATTR_MAX_MATCH_SETS])
863 		capa->max_match_sets =
864 			nla_get_u8(tb[NL80211_ATTR_MAX_MATCH_SETS]);
865 
866 	if (tb[NL80211_ATTR_MAC_ACL_MAX])
867 		capa->max_acl_mac_addrs =
868 			nla_get_u8(tb[NL80211_ATTR_MAC_ACL_MAX]);
869 
870 	wiphy_info_supported_iftypes(info, tb[NL80211_ATTR_SUPPORTED_IFTYPES]);
871 	wiphy_info_iface_comb(info, tb[NL80211_ATTR_INTERFACE_COMBINATIONS]);
872 	wiphy_info_supp_cmds(info, tb[NL80211_ATTR_SUPPORTED_COMMANDS]);
873 	wiphy_info_cipher_suites(info, tb[NL80211_ATTR_CIPHER_SUITES]);
874 	wiphy_info_akm_suites(info, tb[NL80211_ATTR_AKM_SUITES]);
875 	wiphy_info_iftype_akm_suites(info, tb[NL80211_ATTR_IFTYPE_AKM_SUITES]);
876 
877 	if (tb[NL80211_ATTR_OFFCHANNEL_TX_OK]) {
878 		wpa_printf(MSG_DEBUG, "nl80211: Using driver-based "
879 			   "off-channel TX");
880 		capa->flags |= WPA_DRIVER_FLAGS_OFFCHANNEL_TX;
881 	}
882 
883 	if (tb[NL80211_ATTR_ROAM_SUPPORT]) {
884 		wpa_printf(MSG_DEBUG, "nl80211: Using driver-based roaming");
885 		capa->flags |= WPA_DRIVER_FLAGS_BSS_SELECTION;
886 	}
887 
888 	wiphy_info_max_roc(capa,
889 			   tb[NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION]);
890 
891 	if (tb[NL80211_ATTR_SUPPORT_AP_UAPSD])
892 		capa->flags |= WPA_DRIVER_FLAGS_AP_UAPSD;
893 
894 	wiphy_info_tdls(capa, tb[NL80211_ATTR_TDLS_SUPPORT],
895 			tb[NL80211_ATTR_TDLS_EXTERNAL_SETUP]);
896 
897 	if (tb[NL80211_ATTR_DEVICE_AP_SME])
898 		info->device_ap_sme = 1;
899 
900 	wiphy_info_feature_flags(info, tb[NL80211_ATTR_FEATURE_FLAGS]);
901 	wiphy_info_ext_feature_flags(info, tb[NL80211_ATTR_EXT_FEATURES]);
902 	wiphy_info_probe_resp_offload(capa,
903 				      tb[NL80211_ATTR_PROBE_RESP_OFFLOAD]);
904 
905 	if (tb[NL80211_ATTR_EXT_CAPA] && tb[NL80211_ATTR_EXT_CAPA_MASK] &&
906 	    drv->extended_capa == NULL) {
907 		drv->extended_capa =
908 			os_malloc(nla_len(tb[NL80211_ATTR_EXT_CAPA]));
909 		if (drv->extended_capa) {
910 			os_memcpy(drv->extended_capa,
911 				  nla_data(tb[NL80211_ATTR_EXT_CAPA]),
912 				  nla_len(tb[NL80211_ATTR_EXT_CAPA]));
913 			drv->extended_capa_len =
914 				nla_len(tb[NL80211_ATTR_EXT_CAPA]);
915 			wpa_hexdump(MSG_DEBUG,
916 				    "nl80211: Driver-advertised extended capabilities (default)",
917 				    drv->extended_capa, drv->extended_capa_len);
918 		}
919 		drv->extended_capa_mask =
920 			os_malloc(nla_len(tb[NL80211_ATTR_EXT_CAPA_MASK]));
921 		if (drv->extended_capa_mask) {
922 			os_memcpy(drv->extended_capa_mask,
923 				  nla_data(tb[NL80211_ATTR_EXT_CAPA_MASK]),
924 				  nla_len(tb[NL80211_ATTR_EXT_CAPA_MASK]));
925 			wpa_hexdump(MSG_DEBUG,
926 				    "nl80211: Driver-advertised extended capabilities mask (default)",
927 				    drv->extended_capa_mask,
928 				    drv->extended_capa_len);
929 		} else {
930 			os_free(drv->extended_capa);
931 			drv->extended_capa = NULL;
932 			drv->extended_capa_len = 0;
933 		}
934 	}
935 
936 	wiphy_info_extended_capab(drv, tb[NL80211_ATTR_IFTYPE_EXT_CAPA]);
937 
938 	if (tb[NL80211_ATTR_VENDOR_DATA]) {
939 		struct nlattr *nl;
940 		int rem;
941 
942 		nla_for_each_nested(nl, tb[NL80211_ATTR_VENDOR_DATA], rem) {
943 			struct nl80211_vendor_cmd_info *vinfo;
944 			if (nla_len(nl) != sizeof(*vinfo)) {
945 				wpa_printf(MSG_DEBUG, "nl80211: Unexpected vendor data info");
946 				continue;
947 			}
948 			vinfo = nla_data(nl);
949 			if (vinfo->vendor_id == OUI_QCA) {
950 				switch (vinfo->subcmd) {
951 				case QCA_NL80211_VENDOR_SUBCMD_TEST:
952 					drv->vendor_cmd_test_avail = 1;
953 					break;
954 #ifdef CONFIG_DRIVER_NL80211_QCA
955 				case QCA_NL80211_VENDOR_SUBCMD_ROAMING:
956 					drv->roaming_vendor_cmd_avail = 1;
957 					break;
958 				case QCA_NL80211_VENDOR_SUBCMD_DFS_CAPABILITY:
959 					drv->dfs_vendor_cmd_avail = 1;
960 					break;
961 				case QCA_NL80211_VENDOR_SUBCMD_GET_FEATURES:
962 					drv->get_features_vendor_cmd_avail = 1;
963 					break;
964 				case QCA_NL80211_VENDOR_SUBCMD_GET_PREFERRED_FREQ_LIST:
965 					drv->get_pref_freq_list = 1;
966 					break;
967 				case QCA_NL80211_VENDOR_SUBCMD_SET_PROBABLE_OPER_CHANNEL:
968 					drv->set_prob_oper_freq = 1;
969 					break;
970 				case QCA_NL80211_VENDOR_SUBCMD_DO_ACS:
971 					drv->capa.flags |=
972 						WPA_DRIVER_FLAGS_ACS_OFFLOAD;
973 					break;
974 				case QCA_NL80211_VENDOR_SUBCMD_SETBAND:
975 					drv->setband_vendor_cmd_avail = 1;
976 					break;
977 				case QCA_NL80211_VENDOR_SUBCMD_TRIGGER_SCAN:
978 					drv->scan_vendor_cmd_avail = 1;
979 					break;
980 				case QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION:
981 					drv->set_wifi_conf_vendor_cmd_avail = 1;
982 					break;
983 				case QCA_NL80211_VENDOR_SUBCMD_FETCH_BSS_TRANSITION_STATUS:
984 					drv->fetch_bss_trans_status = 1;
985 					break;
986 				case QCA_NL80211_VENDOR_SUBCMD_ROAM:
987 					drv->roam_vendor_cmd_avail = 1;
988 					break;
989 				case QCA_NL80211_VENDOR_SUBCMD_ADD_STA_NODE:
990 					drv->add_sta_node_vendor_cmd_avail = 1;
991 					break;
992 #endif /* CONFIG_DRIVER_NL80211_QCA */
993 				}
994 			}
995 
996 			wpa_printf(MSG_DEBUG, "nl80211: Supported vendor command: vendor_id=0x%x subcmd=%u",
997 				   vinfo->vendor_id, vinfo->subcmd);
998 		}
999 	}
1000 
1001 	if (tb[NL80211_ATTR_VENDOR_EVENTS]) {
1002 		struct nlattr *nl;
1003 		int rem;
1004 
1005 		nla_for_each_nested(nl, tb[NL80211_ATTR_VENDOR_EVENTS], rem) {
1006 			struct nl80211_vendor_cmd_info *vinfo;
1007 			if (nla_len(nl) != sizeof(*vinfo)) {
1008 				wpa_printf(MSG_DEBUG, "nl80211: Unexpected vendor data info");
1009 				continue;
1010 			}
1011 			vinfo = nla_data(nl);
1012 			wpa_printf(MSG_DEBUG, "nl80211: Supported vendor event: vendor_id=0x%x subcmd=%u",
1013 				   vinfo->vendor_id, vinfo->subcmd);
1014 		}
1015 	}
1016 
1017 	wiphy_info_wowlan_triggers(capa,
1018 				   tb[NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED]);
1019 
1020 	if (tb[NL80211_ATTR_MAX_AP_ASSOC_STA])
1021 		capa->max_stations =
1022 			nla_get_u32(tb[NL80211_ATTR_MAX_AP_ASSOC_STA]);
1023 
1024 	if (tb[NL80211_ATTR_MAX_CSA_COUNTERS])
1025 		capa->max_csa_counters =
1026 			nla_get_u8(tb[NL80211_ATTR_MAX_CSA_COUNTERS]);
1027 
1028 	if (tb[NL80211_ATTR_WIPHY_SELF_MANAGED_REG])
1029 		capa->flags |= WPA_DRIVER_FLAGS_SELF_MANAGED_REGULATORY;
1030 
1031 	return NL_SKIP;
1032 }
1033 
1034 
wpa_driver_nl80211_get_info(struct wpa_driver_nl80211_data * drv,struct wiphy_info_data * info)1035 static int wpa_driver_nl80211_get_info(struct wpa_driver_nl80211_data *drv,
1036 				       struct wiphy_info_data *info)
1037 {
1038 	u32 feat;
1039 	struct nl_msg *msg;
1040 	int flags = 0;
1041 
1042 	os_memset(info, 0, sizeof(*info));
1043 	info->capa = &drv->capa;
1044 	info->drv = drv;
1045 
1046 	feat = get_nl80211_protocol_features(drv);
1047 	if (feat & NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)
1048 		flags = NLM_F_DUMP;
1049 	msg = nl80211_cmd_msg(drv->first_bss, flags, NL80211_CMD_GET_WIPHY);
1050 	if (!msg || nla_put_flag(msg, NL80211_ATTR_SPLIT_WIPHY_DUMP)) {
1051 		nlmsg_free(msg);
1052 		return -1;
1053 	}
1054 
1055 	if (send_and_recv_msgs(drv, msg, wiphy_info_handler, info))
1056 		return -1;
1057 
1058 	if (info->auth_supported)
1059 		drv->capa.flags |= WPA_DRIVER_FLAGS_SME;
1060 	else if (!info->connect_supported) {
1061 		wpa_printf(MSG_INFO, "nl80211: Driver does not support "
1062 			   "authentication/association or connect commands");
1063 		info->error = 1;
1064 	}
1065 
1066 	if (info->p2p_go_supported && info->p2p_client_supported)
1067 		drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CAPABLE;
1068 	if (info->p2p_concurrent) {
1069 		wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group "
1070 			   "interface (driver advertised support)");
1071 		drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT;
1072 		drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P;
1073 	}
1074 	if (info->num_multichan_concurrent > 1) {
1075 		wpa_printf(MSG_DEBUG, "nl80211: Enable multi-channel "
1076 			   "concurrent (driver advertised support)");
1077 		drv->capa.num_multichan_concurrent =
1078 			info->num_multichan_concurrent;
1079 	}
1080 	if (drv->capa.flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)
1081 		wpa_printf(MSG_DEBUG, "nl80211: use P2P_DEVICE support");
1082 
1083 	/* default to 5000 since early versions of mac80211 don't set it */
1084 	if (!drv->capa.max_remain_on_chan)
1085 		drv->capa.max_remain_on_chan = 5000;
1086 
1087 	drv->capa.wmm_ac_supported = info->wmm_ac_supported;
1088 
1089 	drv->capa.mac_addr_rand_sched_scan_supported =
1090 		info->mac_addr_rand_sched_scan_supported;
1091 	drv->capa.mac_addr_rand_scan_supported =
1092 		info->mac_addr_rand_scan_supported;
1093 
1094 	if (info->channel_switch_supported) {
1095 		drv->capa.flags |= WPA_DRIVER_FLAGS_AP_CSA;
1096 		if (!drv->capa.max_csa_counters)
1097 			drv->capa.max_csa_counters = 1;
1098 	}
1099 
1100 	if (!drv->capa.max_sched_scan_plans) {
1101 		drv->capa.max_sched_scan_plans = 1;
1102 		drv->capa.max_sched_scan_plan_interval = UINT32_MAX;
1103 		drv->capa.max_sched_scan_plan_iterations = 0;
1104 	}
1105 
1106 	if (info->update_ft_ies_supported)
1107 		drv->capa.flags |= WPA_DRIVER_FLAGS_UPDATE_FT_IES;
1108 
1109 	return 0;
1110 }
1111 
1112 
1113 #ifdef CONFIG_DRIVER_NL80211_QCA
1114 
dfs_info_handler(struct nl_msg * msg,void * arg)1115 static int dfs_info_handler(struct nl_msg *msg, void *arg)
1116 {
1117 	struct nlattr *tb[NL80211_ATTR_MAX + 1];
1118 	struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1119 	int *dfs_capability_ptr = arg;
1120 
1121 	nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1122 		  genlmsg_attrlen(gnlh, 0), NULL);
1123 
1124 	if (tb[NL80211_ATTR_VENDOR_DATA]) {
1125 		struct nlattr *nl_vend = tb[NL80211_ATTR_VENDOR_DATA];
1126 		struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1];
1127 
1128 		nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX,
1129 			  nla_data(nl_vend), nla_len(nl_vend), NULL);
1130 
1131 		if (tb_vendor[QCA_WLAN_VENDOR_ATTR_DFS]) {
1132 			u32 val;
1133 			val = nla_get_u32(tb_vendor[QCA_WLAN_VENDOR_ATTR_DFS]);
1134 			wpa_printf(MSG_DEBUG, "nl80211: DFS offload capability: %u",
1135 				   val);
1136 			*dfs_capability_ptr = val;
1137 		}
1138 	}
1139 
1140 	return NL_SKIP;
1141 }
1142 
1143 
qca_nl80211_check_dfs_capa(struct wpa_driver_nl80211_data * drv)1144 static void qca_nl80211_check_dfs_capa(struct wpa_driver_nl80211_data *drv)
1145 {
1146 	struct nl_msg *msg;
1147 	int dfs_capability = 0;
1148 	int ret;
1149 
1150 	if (!drv->dfs_vendor_cmd_avail)
1151 		return;
1152 
1153 	if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
1154 	    nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
1155 	    nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
1156 			QCA_NL80211_VENDOR_SUBCMD_DFS_CAPABILITY)) {
1157 		nlmsg_free(msg);
1158 		return;
1159 	}
1160 
1161 	ret = send_and_recv_msgs(drv, msg, dfs_info_handler, &dfs_capability);
1162 	if (!ret && dfs_capability)
1163 		drv->capa.flags |= WPA_DRIVER_FLAGS_DFS_OFFLOAD;
1164 }
1165 
1166 
1167 struct features_info {
1168 	u8 *flags;
1169 	size_t flags_len;
1170 	struct wpa_driver_capa *capa;
1171 };
1172 
1173 
features_info_handler(struct nl_msg * msg,void * arg)1174 static int features_info_handler(struct nl_msg *msg, void *arg)
1175 {
1176 	struct nlattr *tb[NL80211_ATTR_MAX + 1];
1177 	struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1178 	struct features_info *info = arg;
1179 	struct nlattr *nl_vend, *attr;
1180 
1181 	nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1182 		  genlmsg_attrlen(gnlh, 0), NULL);
1183 
1184 	nl_vend = tb[NL80211_ATTR_VENDOR_DATA];
1185 	if (nl_vend) {
1186 		struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1];
1187 
1188 		nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX,
1189 			  nla_data(nl_vend), nla_len(nl_vend), NULL);
1190 
1191 		attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_FEATURE_FLAGS];
1192 		if (attr) {
1193 			int len = nla_len(attr);
1194 			info->flags = os_malloc(len);
1195 			if (info->flags != NULL) {
1196 				os_memcpy(info->flags, nla_data(attr), len);
1197 				info->flags_len = len;
1198 			}
1199 		}
1200 		attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_CONCURRENCY_CAPA];
1201 		if (attr)
1202 			info->capa->conc_capab = nla_get_u32(attr);
1203 
1204 		attr = tb_vendor[
1205 			QCA_WLAN_VENDOR_ATTR_MAX_CONCURRENT_CHANNELS_2_4_BAND];
1206 		if (attr)
1207 			info->capa->max_conc_chan_2_4 = nla_get_u32(attr);
1208 
1209 		attr = tb_vendor[
1210 			QCA_WLAN_VENDOR_ATTR_MAX_CONCURRENT_CHANNELS_5_0_BAND];
1211 		if (attr)
1212 			info->capa->max_conc_chan_5_0 = nla_get_u32(attr);
1213 	}
1214 
1215 	return NL_SKIP;
1216 }
1217 
1218 
check_feature(enum qca_wlan_vendor_features feature,struct features_info * info)1219 static int check_feature(enum qca_wlan_vendor_features feature,
1220 			 struct features_info *info)
1221 {
1222 	size_t idx = feature / 8;
1223 
1224 	return (idx < info->flags_len) &&
1225 		(info->flags[idx] & BIT(feature % 8));
1226 }
1227 
1228 
qca_nl80211_get_features(struct wpa_driver_nl80211_data * drv)1229 static void qca_nl80211_get_features(struct wpa_driver_nl80211_data *drv)
1230 {
1231 	struct nl_msg *msg;
1232 	struct features_info info;
1233 	int ret;
1234 
1235 	if (!drv->get_features_vendor_cmd_avail)
1236 		return;
1237 
1238 	if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
1239 	    nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
1240 	    nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
1241 			QCA_NL80211_VENDOR_SUBCMD_GET_FEATURES)) {
1242 		nlmsg_free(msg);
1243 		return;
1244 	}
1245 
1246 	os_memset(&info, 0, sizeof(info));
1247 	info.capa = &drv->capa;
1248 	ret = send_and_recv_msgs(drv, msg, features_info_handler, &info);
1249 	if (ret || !info.flags)
1250 		return;
1251 
1252 	if (check_feature(QCA_WLAN_VENDOR_FEATURE_KEY_MGMT_OFFLOAD, &info))
1253 		drv->capa.flags |= WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD;
1254 
1255 	if (check_feature(QCA_WLAN_VENDOR_FEATURE_SUPPORT_HW_MODE_ANY, &info))
1256 		drv->capa.flags |= WPA_DRIVER_FLAGS_SUPPORT_HW_MODE_ANY;
1257 
1258 	if (check_feature(QCA_WLAN_VENDOR_FEATURE_OFFCHANNEL_SIMULTANEOUS,
1259 			  &info))
1260 		drv->capa.flags |= WPA_DRIVER_FLAGS_OFFCHANNEL_SIMULTANEOUS;
1261 	if (check_feature(QCA_WLAN_VENDOR_FEATURE_P2P_LISTEN_OFFLOAD, &info))
1262 		drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD;
1263 	if (check_feature(QCA_WLAN_VENDOR_FEATURE_OCE_STA, &info))
1264 		drv->capa.flags |= WPA_DRIVER_FLAGS_OCE_STA;
1265 	if (check_feature(QCA_WLAN_VENDOR_FEATURE_OCE_AP, &info))
1266 		drv->capa.flags |= WPA_DRIVER_FLAGS_OCE_AP;
1267 	if (check_feature(QCA_WLAN_VENDOR_FEATURE_OCE_STA_CFON, &info))
1268 		drv->capa.flags |= WPA_DRIVER_FLAGS_OCE_STA_CFON;
1269 	os_free(info.flags);
1270 }
1271 
1272 #endif /* CONFIG_DRIVER_NL80211_QCA */
1273 
1274 
wpa_driver_nl80211_capa(struct wpa_driver_nl80211_data * drv)1275 int wpa_driver_nl80211_capa(struct wpa_driver_nl80211_data *drv)
1276 {
1277 	struct wiphy_info_data info;
1278 	int i;
1279 
1280 	if (wpa_driver_nl80211_get_info(drv, &info))
1281 		return -1;
1282 
1283 	if (info.error)
1284 		return -1;
1285 
1286 	drv->has_capability = 1;
1287 	drv->has_driver_key_mgmt = info.has_key_mgmt | info.has_key_mgmt_iftype;
1288 
1289 	/* Fallback to hardcoded defaults if the driver does nott advertize any
1290 	 * AKM capabilities. */
1291 	if (!drv->has_driver_key_mgmt) {
1292 		drv->capa.key_mgmt = WPA_DRIVER_CAPA_KEY_MGMT_WPA |
1293 			WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
1294 			WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
1295 			WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK |
1296 			WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B |
1297 			WPA_DRIVER_CAPA_KEY_MGMT_OWE |
1298 			WPA_DRIVER_CAPA_KEY_MGMT_DPP;
1299 
1300 		if (drv->capa.enc & (WPA_DRIVER_CAPA_ENC_CCMP_256 |
1301 				     WPA_DRIVER_CAPA_ENC_GCMP_256))
1302 			drv->capa.key_mgmt |=
1303 				WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192;
1304 
1305 		if (drv->capa.flags & WPA_DRIVER_FLAGS_SME)
1306 			drv->capa.key_mgmt |=
1307 				WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256 |
1308 				WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384 |
1309 				WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA256 |
1310 				WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA384 |
1311 				WPA_DRIVER_CAPA_KEY_MGMT_SAE;
1312 		else if (drv->capa.flags & WPA_DRIVER_FLAGS_FILS_SK_OFFLOAD)
1313 			drv->capa.key_mgmt |=
1314 				WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256 |
1315 				WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384;
1316 	}
1317 
1318 	if (!info.has_key_mgmt_iftype) {
1319 		/* If the driver does not advertize per interface AKM
1320 		 * capabilities, consider all interfaces to support default AKMs
1321 		 * in key_mgmt. */
1322 		for (i = 0; i < WPA_IF_MAX; i++)
1323 			drv->capa.key_mgmt_iftype[i] = drv->capa.key_mgmt;
1324 	} else if (info.has_key_mgmt_iftype && !info.has_key_mgmt) {
1325 		/* If the driver advertizes only per interface supported AKMs
1326 		 * but does not advertize per wiphy AKM capabilities, consider
1327 		 * the default key_mgmt as a mask of per interface supported
1328 		 * AKMs. */
1329 		drv->capa.key_mgmt = 0;
1330 		for (i = 0; i < WPA_IF_MAX; i++)
1331 			drv->capa.key_mgmt |= drv->capa.key_mgmt_iftype[i];
1332 	} else if (info.has_key_mgmt_iftype && info.has_key_mgmt) {
1333 		/* If the driver advertizes AKM capabilities both per wiphy and
1334 		 * per interface, consider the interfaces for which per
1335 		 * interface AKM capabilities were not received to support the
1336 		 * default key_mgmt capabilities.
1337 		 */
1338 		for (i = 0; i < WPA_IF_MAX; i++)
1339 			if (!drv->capa.key_mgmt_iftype[i])
1340 				drv->capa.key_mgmt_iftype[i] =
1341 					drv->capa.key_mgmt;
1342 	}
1343 
1344 	drv->capa.auth = WPA_DRIVER_AUTH_OPEN |
1345 		WPA_DRIVER_AUTH_SHARED |
1346 		WPA_DRIVER_AUTH_LEAP;
1347 
1348 	drv->capa.flags |= WPA_DRIVER_FLAGS_SANE_ERROR_CODES;
1349 	drv->capa.flags |= WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE;
1350 	drv->capa.flags |= WPA_DRIVER_FLAGS_EAPOL_TX_STATUS;
1351 
1352 	/*
1353 	 * As all cfg80211 drivers must support cases where the AP interface is
1354 	 * removed without the knowledge of wpa_supplicant/hostapd, e.g., in
1355 	 * case that the user space daemon has crashed, they must be able to
1356 	 * cleanup all stations and key entries in the AP tear down flow. Thus,
1357 	 * this flag can/should always be set for cfg80211 drivers.
1358 	 */
1359 	drv->capa.flags |= WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT;
1360 
1361 	if (!info.device_ap_sme) {
1362 		drv->capa.flags |= WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS;
1363 
1364 		/*
1365 		 * No AP SME is currently assumed to also indicate no AP MLME
1366 		 * in the driver/firmware.
1367 		 */
1368 		drv->capa.flags |= WPA_DRIVER_FLAGS_AP_MLME;
1369 	}
1370 
1371 	drv->device_ap_sme = info.device_ap_sme;
1372 	drv->poll_command_supported = info.poll_command_supported;
1373 	drv->data_tx_status = info.data_tx_status;
1374 	drv->p2p_go_ctwindow_supported = info.p2p_go_ctwindow_supported;
1375 	if (info.set_qos_map_supported)
1376 		drv->capa.flags |= WPA_DRIVER_FLAGS_QOS_MAPPING;
1377 	drv->have_low_prio_scan = info.have_low_prio_scan;
1378 
1379 	/*
1380 	 * If poll command and tx status are supported, mac80211 is new enough
1381 	 * to have everything we need to not need monitor interfaces.
1382 	 */
1383 	drv->use_monitor = !info.device_ap_sme &&
1384 		(!info.poll_command_supported || !info.data_tx_status);
1385 
1386 	/*
1387 	 * If we aren't going to use monitor interfaces, but the
1388 	 * driver doesn't support data TX status, we won't get TX
1389 	 * status for EAPOL frames.
1390 	 */
1391 	if (!drv->use_monitor && !info.data_tx_status)
1392 		drv->capa.flags &= ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS;
1393 
1394 #ifdef CONFIG_DRIVER_NL80211_QCA
1395 	if (!(info.capa->flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD))
1396 		qca_nl80211_check_dfs_capa(drv);
1397 	qca_nl80211_get_features(drv);
1398 
1399 	/*
1400 	 * To enable offchannel simultaneous support in wpa_supplicant, the
1401 	 * underlying driver needs to support the same along with offchannel TX.
1402 	 * Offchannel TX support is needed since remain_on_channel and
1403 	 * action_tx use some common data structures and hence cannot be
1404 	 * scheduled simultaneously.
1405 	 */
1406 	if (!(drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX))
1407 		drv->capa.flags &= ~WPA_DRIVER_FLAGS_OFFCHANNEL_SIMULTANEOUS;
1408 #endif /* CONFIG_DRIVER_NL80211_QCA */
1409 
1410 	wpa_printf(MSG_DEBUG,
1411 		   "nl80211: key_mgmt=0x%x enc=0x%x auth=0x%x flags=0x%llx rrm_flags=0x%x probe_resp_offloads=0x%x max_stations=%u max_remain_on_chan=%u max_scan_ssids=%d",
1412 		   drv->capa.key_mgmt, drv->capa.enc, drv->capa.auth,
1413 		   (unsigned long long) drv->capa.flags, drv->capa.rrm_flags,
1414 		   drv->capa.probe_resp_offloads, drv->capa.max_stations,
1415 		   drv->capa.max_remain_on_chan, drv->capa.max_scan_ssids);
1416 	return 0;
1417 }
1418 
1419 
1420 struct phy_info_arg {
1421 	u16 *num_modes;
1422 	struct hostapd_hw_modes *modes;
1423 	int last_mode, last_chan_idx;
1424 	int failed;
1425 	u8 dfs_domain;
1426 };
1427 
phy_info_ht_capa(struct hostapd_hw_modes * mode,struct nlattr * capa,struct nlattr * ampdu_factor,struct nlattr * ampdu_density,struct nlattr * mcs_set)1428 static void phy_info_ht_capa(struct hostapd_hw_modes *mode, struct nlattr *capa,
1429 			     struct nlattr *ampdu_factor,
1430 			     struct nlattr *ampdu_density,
1431 			     struct nlattr *mcs_set)
1432 {
1433 	if (capa)
1434 		mode->ht_capab = nla_get_u16(capa);
1435 
1436 	if (ampdu_factor)
1437 		mode->a_mpdu_params |= nla_get_u8(ampdu_factor) & 0x03;
1438 
1439 	if (ampdu_density)
1440 		mode->a_mpdu_params |= nla_get_u8(ampdu_density) << 2;
1441 
1442 	if (mcs_set && nla_len(mcs_set) >= 16) {
1443 		u8 *mcs;
1444 		mcs = nla_data(mcs_set);
1445 		os_memcpy(mode->mcs_set, mcs, 16);
1446 	}
1447 }
1448 
1449 
phy_info_vht_capa(struct hostapd_hw_modes * mode,struct nlattr * capa,struct nlattr * mcs_set)1450 static void phy_info_vht_capa(struct hostapd_hw_modes *mode,
1451 			      struct nlattr *capa,
1452 			      struct nlattr *mcs_set)
1453 {
1454 	if (capa)
1455 		mode->vht_capab = nla_get_u32(capa);
1456 
1457 	if (mcs_set && nla_len(mcs_set) >= 8) {
1458 		u8 *mcs;
1459 		mcs = nla_data(mcs_set);
1460 		os_memcpy(mode->vht_mcs_set, mcs, 8);
1461 	}
1462 }
1463 
1464 
phy_info_edmg_capa(struct hostapd_hw_modes * mode,struct nlattr * bw_config,struct nlattr * channels)1465 static int phy_info_edmg_capa(struct hostapd_hw_modes *mode,
1466 			      struct nlattr *bw_config,
1467 			      struct nlattr *channels)
1468 {
1469 	if (!bw_config || !channels)
1470 		return NL_OK;
1471 
1472 	mode->edmg.bw_config = nla_get_u8(bw_config);
1473 	mode->edmg.channels = nla_get_u8(channels);
1474 
1475 	if (!mode->edmg.channels || !mode->edmg.bw_config)
1476 		return NL_STOP;
1477 
1478 	return NL_OK;
1479 }
1480 
1481 
cw2ecw(unsigned int cw)1482 static int cw2ecw(unsigned int cw)
1483 {
1484 	int bit;
1485 
1486 	if (cw == 0)
1487 		return 0;
1488 
1489 	for (bit = 1; cw != 1; bit++)
1490 		cw >>= 1;
1491 
1492 	return bit;
1493 }
1494 
1495 
phy_info_freq(struct hostapd_hw_modes * mode,struct hostapd_channel_data * chan,struct nlattr * tb_freq[])1496 static void phy_info_freq(struct hostapd_hw_modes *mode,
1497 			  struct hostapd_channel_data *chan,
1498 			  struct nlattr *tb_freq[])
1499 {
1500 	u8 channel;
1501 
1502 	os_memset(chan, 0, sizeof(*chan));
1503 	chan->freq = nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_FREQ]);
1504 	chan->flag = 0;
1505 	chan->allowed_bw = ~0;
1506 	chan->dfs_cac_ms = 0;
1507 	if (ieee80211_freq_to_chan(chan->freq, &channel) != NUM_HOSTAPD_MODES)
1508 		chan->chan = channel;
1509 	else
1510 		wpa_printf(MSG_DEBUG,
1511 			   "nl80211: No channel number found for frequency %u MHz",
1512 			   chan->freq);
1513 
1514 	if (tb_freq[NL80211_FREQUENCY_ATTR_DISABLED])
1515 		chan->flag |= HOSTAPD_CHAN_DISABLED;
1516 	if (tb_freq[NL80211_FREQUENCY_ATTR_NO_IR])
1517 		chan->flag |= HOSTAPD_CHAN_NO_IR;
1518 	if (tb_freq[NL80211_FREQUENCY_ATTR_RADAR])
1519 		chan->flag |= HOSTAPD_CHAN_RADAR;
1520 	if (tb_freq[NL80211_FREQUENCY_ATTR_INDOOR_ONLY])
1521 		chan->flag |= HOSTAPD_CHAN_INDOOR_ONLY;
1522 	if (tb_freq[NL80211_FREQUENCY_ATTR_GO_CONCURRENT])
1523 		chan->flag |= HOSTAPD_CHAN_GO_CONCURRENT;
1524 
1525 	if (tb_freq[NL80211_FREQUENCY_ATTR_NO_10MHZ])
1526 		chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_10;
1527 	if (tb_freq[NL80211_FREQUENCY_ATTR_NO_20MHZ])
1528 		chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_20;
1529 	if (tb_freq[NL80211_FREQUENCY_ATTR_NO_HT40_PLUS])
1530 		chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_40P;
1531 	if (tb_freq[NL80211_FREQUENCY_ATTR_NO_HT40_MINUS])
1532 		chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_40M;
1533 	if (tb_freq[NL80211_FREQUENCY_ATTR_NO_80MHZ])
1534 		chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_80;
1535 	if (tb_freq[NL80211_FREQUENCY_ATTR_NO_160MHZ])
1536 		chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_160;
1537 
1538 	if (tb_freq[NL80211_FREQUENCY_ATTR_DFS_STATE]) {
1539 		enum nl80211_dfs_state state =
1540 			nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_DFS_STATE]);
1541 
1542 		switch (state) {
1543 		case NL80211_DFS_USABLE:
1544 			chan->flag |= HOSTAPD_CHAN_DFS_USABLE;
1545 			break;
1546 		case NL80211_DFS_AVAILABLE:
1547 			chan->flag |= HOSTAPD_CHAN_DFS_AVAILABLE;
1548 			break;
1549 		case NL80211_DFS_UNAVAILABLE:
1550 			chan->flag |= HOSTAPD_CHAN_DFS_UNAVAILABLE;
1551 			break;
1552 		}
1553 	}
1554 
1555 	if (tb_freq[NL80211_FREQUENCY_ATTR_DFS_CAC_TIME]) {
1556 		chan->dfs_cac_ms = nla_get_u32(
1557 			tb_freq[NL80211_FREQUENCY_ATTR_DFS_CAC_TIME]);
1558 	}
1559 
1560 	chan->wmm_rules_valid = 0;
1561 	if (tb_freq[NL80211_FREQUENCY_ATTR_WMM]) {
1562 		static struct nla_policy wmm_policy[NL80211_WMMR_MAX + 1] = {
1563 			[NL80211_WMMR_CW_MIN] = { .type = NLA_U16 },
1564 			[NL80211_WMMR_CW_MAX] = { .type = NLA_U16 },
1565 			[NL80211_WMMR_AIFSN] = { .type = NLA_U8 },
1566 			[NL80211_WMMR_TXOP] = { .type = NLA_U16 },
1567 		};
1568 		static const u8 wmm_map[4] = {
1569 			[NL80211_AC_BE] = WMM_AC_BE,
1570 			[NL80211_AC_BK] = WMM_AC_BK,
1571 			[NL80211_AC_VI] = WMM_AC_VI,
1572 			[NL80211_AC_VO] = WMM_AC_VO,
1573 		};
1574 		struct nlattr *nl_wmm;
1575 		struct nlattr *tb_wmm[NL80211_WMMR_MAX + 1];
1576 		int rem_wmm, ac, count = 0;
1577 
1578 		nla_for_each_nested(nl_wmm, tb_freq[NL80211_FREQUENCY_ATTR_WMM],
1579 				    rem_wmm) {
1580 			if (nla_parse_nested(tb_wmm, NL80211_WMMR_MAX, nl_wmm,
1581 					     wmm_policy)) {
1582 				wpa_printf(MSG_DEBUG,
1583 					   "nl80211: Failed to parse WMM rules attribute");
1584 				return;
1585 			}
1586 			if (!tb_wmm[NL80211_WMMR_CW_MIN] ||
1587 			    !tb_wmm[NL80211_WMMR_CW_MAX] ||
1588 			    !tb_wmm[NL80211_WMMR_AIFSN] ||
1589 			    !tb_wmm[NL80211_WMMR_TXOP]) {
1590 				wpa_printf(MSG_DEBUG,
1591 					   "nl80211: Channel is missing WMM rule attribute");
1592 				return;
1593 			}
1594 			ac = nl_wmm->nla_type;
1595 			if ((unsigned int) ac >= ARRAY_SIZE(wmm_map)) {
1596 				wpa_printf(MSG_DEBUG,
1597 					   "nl80211: Invalid AC value %d", ac);
1598 				return;
1599 			}
1600 
1601 			ac = wmm_map[ac];
1602 			chan->wmm_rules[ac].min_cwmin =
1603 				cw2ecw(nla_get_u16(
1604 					       tb_wmm[NL80211_WMMR_CW_MIN]));
1605 			chan->wmm_rules[ac].min_cwmax =
1606 				cw2ecw(nla_get_u16(
1607 					       tb_wmm[NL80211_WMMR_CW_MAX]));
1608 			chan->wmm_rules[ac].min_aifs =
1609 				nla_get_u8(tb_wmm[NL80211_WMMR_AIFSN]);
1610 			chan->wmm_rules[ac].max_txop =
1611 				nla_get_u16(tb_wmm[NL80211_WMMR_TXOP]) / 32;
1612 			count++;
1613 		}
1614 
1615 		/* Set valid flag if all the AC rules are present */
1616 		if (count == WMM_AC_NUM)
1617 			chan->wmm_rules_valid = 1;
1618 	}
1619 }
1620 
1621 
phy_info_freqs(struct phy_info_arg * phy_info,struct hostapd_hw_modes * mode,struct nlattr * tb)1622 static int phy_info_freqs(struct phy_info_arg *phy_info,
1623 			  struct hostapd_hw_modes *mode, struct nlattr *tb)
1624 {
1625 	static struct nla_policy freq_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = {
1626 		[NL80211_FREQUENCY_ATTR_FREQ] = { .type = NLA_U32 },
1627 		[NL80211_FREQUENCY_ATTR_DISABLED] = { .type = NLA_FLAG },
1628 		[NL80211_FREQUENCY_ATTR_NO_IR] = { .type = NLA_FLAG },
1629 		[NL80211_FREQUENCY_ATTR_RADAR] = { .type = NLA_FLAG },
1630 		[NL80211_FREQUENCY_ATTR_MAX_TX_POWER] = { .type = NLA_U32 },
1631 		[NL80211_FREQUENCY_ATTR_DFS_STATE] = { .type = NLA_U32 },
1632 		[NL80211_FREQUENCY_ATTR_NO_10MHZ] = { .type = NLA_FLAG },
1633 		[NL80211_FREQUENCY_ATTR_NO_20MHZ] = { .type = NLA_FLAG },
1634 		[NL80211_FREQUENCY_ATTR_NO_HT40_PLUS] = { .type = NLA_FLAG },
1635 		[NL80211_FREQUENCY_ATTR_NO_HT40_MINUS] = { .type = NLA_FLAG },
1636 		[NL80211_FREQUENCY_ATTR_NO_80MHZ] = { .type = NLA_FLAG },
1637 		[NL80211_FREQUENCY_ATTR_NO_160MHZ] = { .type = NLA_FLAG },
1638 	};
1639 	int new_channels = 0;
1640 	struct hostapd_channel_data *channel;
1641 	struct nlattr *tb_freq[NL80211_FREQUENCY_ATTR_MAX + 1];
1642 	struct nlattr *nl_freq;
1643 	int rem_freq, idx;
1644 
1645 	if (tb == NULL)
1646 		return NL_OK;
1647 
1648 	nla_for_each_nested(nl_freq, tb, rem_freq) {
1649 		nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX,
1650 			  nla_data(nl_freq), nla_len(nl_freq), freq_policy);
1651 		if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ])
1652 			continue;
1653 		new_channels++;
1654 	}
1655 
1656 	channel = os_realloc_array(mode->channels,
1657 				   mode->num_channels + new_channels,
1658 				   sizeof(struct hostapd_channel_data));
1659 	if (!channel)
1660 		return NL_STOP;
1661 
1662 	mode->channels = channel;
1663 	mode->num_channels += new_channels;
1664 
1665 	idx = phy_info->last_chan_idx;
1666 
1667 	nla_for_each_nested(nl_freq, tb, rem_freq) {
1668 		nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX,
1669 			  nla_data(nl_freq), nla_len(nl_freq), freq_policy);
1670 		if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ])
1671 			continue;
1672 		phy_info_freq(mode, &mode->channels[idx], tb_freq);
1673 		idx++;
1674 	}
1675 	phy_info->last_chan_idx = idx;
1676 
1677 	return NL_OK;
1678 }
1679 
1680 
phy_info_rates(struct hostapd_hw_modes * mode,struct nlattr * tb)1681 static int phy_info_rates(struct hostapd_hw_modes *mode, struct nlattr *tb)
1682 {
1683 	static struct nla_policy rate_policy[NL80211_BITRATE_ATTR_MAX + 1] = {
1684 		[NL80211_BITRATE_ATTR_RATE] = { .type = NLA_U32 },
1685 		[NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE] =
1686 		{ .type = NLA_FLAG },
1687 	};
1688 	struct nlattr *tb_rate[NL80211_BITRATE_ATTR_MAX + 1];
1689 	struct nlattr *nl_rate;
1690 	int rem_rate, idx;
1691 
1692 	if (tb == NULL)
1693 		return NL_OK;
1694 
1695 	nla_for_each_nested(nl_rate, tb, rem_rate) {
1696 		nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX,
1697 			  nla_data(nl_rate), nla_len(nl_rate),
1698 			  rate_policy);
1699 		if (!tb_rate[NL80211_BITRATE_ATTR_RATE])
1700 			continue;
1701 		mode->num_rates++;
1702 	}
1703 
1704 	mode->rates = os_calloc(mode->num_rates, sizeof(int));
1705 	if (!mode->rates)
1706 		return NL_STOP;
1707 
1708 	idx = 0;
1709 
1710 	nla_for_each_nested(nl_rate, tb, rem_rate) {
1711 		nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX,
1712 			  nla_data(nl_rate), nla_len(nl_rate),
1713 			  rate_policy);
1714 		if (!tb_rate[NL80211_BITRATE_ATTR_RATE])
1715 			continue;
1716 		mode->rates[idx] = nla_get_u32(
1717 			tb_rate[NL80211_BITRATE_ATTR_RATE]);
1718 		idx++;
1719 	}
1720 
1721 	return NL_OK;
1722 }
1723 
1724 
phy_info_iftype_copy(struct he_capabilities * he_capab,enum ieee80211_op_mode opmode,struct nlattr ** tb,struct nlattr ** tb_flags)1725 static void phy_info_iftype_copy(struct he_capabilities *he_capab,
1726 				 enum ieee80211_op_mode opmode,
1727 				 struct nlattr **tb, struct nlattr **tb_flags)
1728 {
1729 	enum nl80211_iftype iftype;
1730 	size_t len;
1731 
1732 	switch (opmode) {
1733 	case IEEE80211_MODE_INFRA:
1734 		iftype = NL80211_IFTYPE_STATION;
1735 		break;
1736 	case IEEE80211_MODE_IBSS:
1737 		iftype = NL80211_IFTYPE_ADHOC;
1738 		break;
1739 	case IEEE80211_MODE_AP:
1740 		iftype = NL80211_IFTYPE_AP;
1741 		break;
1742 	case IEEE80211_MODE_MESH:
1743 		iftype = NL80211_IFTYPE_MESH_POINT;
1744 		break;
1745 	default:
1746 		return;
1747 	}
1748 
1749 	if (!nla_get_flag(tb_flags[iftype]))
1750 		return;
1751 
1752 	he_capab->he_supported = 1;
1753 
1754 	if (tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY]) {
1755 		len = nla_len(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY]);
1756 
1757 		if (len > sizeof(he_capab->phy_cap))
1758 			len = sizeof(he_capab->phy_cap);
1759 		os_memcpy(he_capab->phy_cap,
1760 			  nla_data(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY]),
1761 			  len);
1762 	}
1763 
1764 	if (tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC]) {
1765 		len = nla_len(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC]);
1766 
1767 		if (len > sizeof(he_capab->mac_cap))
1768 			len = sizeof(he_capab->mac_cap);
1769 		os_memcpy(he_capab->mac_cap,
1770 			  nla_data(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC]),
1771 			  len);
1772 	}
1773 
1774 	if (tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET]) {
1775 		len = nla_len(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET]);
1776 
1777 		if (len > sizeof(he_capab->mcs))
1778 			len = sizeof(he_capab->mcs);
1779 		os_memcpy(he_capab->mcs,
1780 			  nla_data(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET]),
1781 			  len);
1782 	}
1783 
1784 	if (tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE]) {
1785 		len = nla_len(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE]);
1786 
1787 		if (len > sizeof(he_capab->ppet))
1788 			len = sizeof(he_capab->ppet);
1789 		os_memcpy(&he_capab->ppet,
1790 			  nla_data(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE]),
1791 			  len);
1792 	}
1793 }
1794 
1795 
phy_info_iftype(struct hostapd_hw_modes * mode,struct nlattr * nl_iftype)1796 static int phy_info_iftype(struct hostapd_hw_modes *mode,
1797 			   struct nlattr *nl_iftype)
1798 {
1799 	struct nlattr *tb[NL80211_BAND_IFTYPE_ATTR_MAX + 1];
1800 	struct nlattr *tb_flags[NL80211_IFTYPE_MAX + 1];
1801 	unsigned int i;
1802 
1803 	nla_parse(tb, NL80211_BAND_IFTYPE_ATTR_MAX,
1804 		  nla_data(nl_iftype), nla_len(nl_iftype), NULL);
1805 
1806 	if (!tb[NL80211_BAND_IFTYPE_ATTR_IFTYPES])
1807 		return NL_STOP;
1808 
1809 	if (nla_parse_nested(tb_flags, NL80211_IFTYPE_MAX,
1810 			     tb[NL80211_BAND_IFTYPE_ATTR_IFTYPES], NULL))
1811 		return NL_STOP;
1812 
1813 	for (i = 0; i < IEEE80211_MODE_NUM; i++)
1814 		phy_info_iftype_copy(&mode->he_capab[i], i, tb, tb_flags);
1815 
1816 	return NL_OK;
1817 }
1818 
1819 
phy_info_band(struct phy_info_arg * phy_info,struct nlattr * nl_band)1820 static int phy_info_band(struct phy_info_arg *phy_info, struct nlattr *nl_band)
1821 {
1822 	struct nlattr *tb_band[NL80211_BAND_ATTR_MAX + 1];
1823 	struct hostapd_hw_modes *mode;
1824 	int ret;
1825 
1826 	if (phy_info->last_mode != nl_band->nla_type) {
1827 		mode = os_realloc_array(phy_info->modes,
1828 					*phy_info->num_modes + 1,
1829 					sizeof(*mode));
1830 		if (!mode) {
1831 			phy_info->failed = 1;
1832 			return NL_STOP;
1833 		}
1834 		phy_info->modes = mode;
1835 
1836 		mode = &phy_info->modes[*(phy_info->num_modes)];
1837 		os_memset(mode, 0, sizeof(*mode));
1838 		mode->mode = NUM_HOSTAPD_MODES;
1839 		mode->flags = HOSTAPD_MODE_FLAG_HT_INFO_KNOWN |
1840 			HOSTAPD_MODE_FLAG_VHT_INFO_KNOWN;
1841 
1842 		/*
1843 		 * Unsupported VHT MCS stream is defined as value 3, so the VHT
1844 		 * MCS RX/TX map must be initialized with 0xffff to mark all 8
1845 		 * possible streams as unsupported. This will be overridden if
1846 		 * driver advertises VHT support.
1847 		 */
1848 		mode->vht_mcs_set[0] = 0xff;
1849 		mode->vht_mcs_set[1] = 0xff;
1850 		mode->vht_mcs_set[4] = 0xff;
1851 		mode->vht_mcs_set[5] = 0xff;
1852 
1853 		*(phy_info->num_modes) += 1;
1854 		phy_info->last_mode = nl_band->nla_type;
1855 		phy_info->last_chan_idx = 0;
1856 	} else
1857 		mode = &phy_info->modes[*(phy_info->num_modes) - 1];
1858 
1859 	nla_parse(tb_band, NL80211_BAND_ATTR_MAX, nla_data(nl_band),
1860 		  nla_len(nl_band), NULL);
1861 
1862 	phy_info_ht_capa(mode, tb_band[NL80211_BAND_ATTR_HT_CAPA],
1863 			 tb_band[NL80211_BAND_ATTR_HT_AMPDU_FACTOR],
1864 			 tb_band[NL80211_BAND_ATTR_HT_AMPDU_DENSITY],
1865 			 tb_band[NL80211_BAND_ATTR_HT_MCS_SET]);
1866 	phy_info_vht_capa(mode, tb_band[NL80211_BAND_ATTR_VHT_CAPA],
1867 			  tb_band[NL80211_BAND_ATTR_VHT_MCS_SET]);
1868 	ret = phy_info_edmg_capa(mode,
1869 				 tb_band[NL80211_BAND_ATTR_EDMG_BW_CONFIG],
1870 				 tb_band[NL80211_BAND_ATTR_EDMG_CHANNELS]);
1871 	if (ret == NL_OK)
1872 		ret = phy_info_freqs(phy_info, mode,
1873 				     tb_band[NL80211_BAND_ATTR_FREQS]);
1874 	if (ret == NL_OK)
1875 		ret = phy_info_rates(mode, tb_band[NL80211_BAND_ATTR_RATES]);
1876 	if (ret != NL_OK) {
1877 		phy_info->failed = 1;
1878 		return ret;
1879 	}
1880 
1881 	if (tb_band[NL80211_BAND_ATTR_IFTYPE_DATA]) {
1882 		struct nlattr *nl_iftype;
1883 		int rem_band;
1884 
1885 		nla_for_each_nested(nl_iftype,
1886 				    tb_band[NL80211_BAND_ATTR_IFTYPE_DATA],
1887 				    rem_band) {
1888 			ret = phy_info_iftype(mode, nl_iftype);
1889 			if (ret != NL_OK)
1890 				return ret;
1891 		}
1892 	}
1893 
1894 	return NL_OK;
1895 }
1896 
1897 
phy_info_handler(struct nl_msg * msg,void * arg)1898 static int phy_info_handler(struct nl_msg *msg, void *arg)
1899 {
1900 	struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
1901 	struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1902 	struct phy_info_arg *phy_info = arg;
1903 	struct nlattr *nl_band;
1904 	int rem_band;
1905 
1906 	nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1907 		  genlmsg_attrlen(gnlh, 0), NULL);
1908 
1909 	if (!tb_msg[NL80211_ATTR_WIPHY_BANDS])
1910 		return NL_SKIP;
1911 
1912 	nla_for_each_nested(nl_band, tb_msg[NL80211_ATTR_WIPHY_BANDS], rem_band)
1913 	{
1914 		int res = phy_info_band(phy_info, nl_band);
1915 		if (res != NL_OK)
1916 			return res;
1917 	}
1918 
1919 	return NL_SKIP;
1920 }
1921 
1922 
1923 static struct hostapd_hw_modes *
wpa_driver_nl80211_postprocess_modes(struct hostapd_hw_modes * modes,u16 * num_modes)1924 wpa_driver_nl80211_postprocess_modes(struct hostapd_hw_modes *modes,
1925 				     u16 *num_modes)
1926 {
1927 	u16 m;
1928 	struct hostapd_hw_modes *mode11g = NULL, *nmodes, *mode;
1929 	int i, mode11g_idx = -1;
1930 
1931 	/* heuristic to set up modes */
1932 	for (m = 0; m < *num_modes; m++) {
1933 		if (!modes[m].num_channels)
1934 			continue;
1935 		if (modes[m].channels[0].freq < 4000) {
1936 			modes[m].mode = HOSTAPD_MODE_IEEE80211B;
1937 			for (i = 0; i < modes[m].num_rates; i++) {
1938 				if (modes[m].rates[i] > 200) {
1939 					modes[m].mode = HOSTAPD_MODE_IEEE80211G;
1940 					break;
1941 				}
1942 			}
1943 		} else if (modes[m].channels[0].freq > 50000)
1944 			modes[m].mode = HOSTAPD_MODE_IEEE80211AD;
1945 		else
1946 			modes[m].mode = HOSTAPD_MODE_IEEE80211A;
1947 	}
1948 
1949 	/* If only 802.11g mode is included, use it to construct matching
1950 	 * 802.11b mode data. */
1951 
1952 	for (m = 0; m < *num_modes; m++) {
1953 		if (modes[m].mode == HOSTAPD_MODE_IEEE80211B)
1954 			return modes; /* 802.11b already included */
1955 		if (modes[m].mode == HOSTAPD_MODE_IEEE80211G)
1956 			mode11g_idx = m;
1957 	}
1958 
1959 	if (mode11g_idx < 0)
1960 		return modes; /* 2.4 GHz band not supported at all */
1961 
1962 	nmodes = os_realloc_array(modes, *num_modes + 1, sizeof(*nmodes));
1963 	if (nmodes == NULL)
1964 		return modes; /* Could not add 802.11b mode */
1965 
1966 	mode = &nmodes[*num_modes];
1967 	os_memset(mode, 0, sizeof(*mode));
1968 	(*num_modes)++;
1969 	modes = nmodes;
1970 
1971 	mode->mode = HOSTAPD_MODE_IEEE80211B;
1972 
1973 	mode11g = &modes[mode11g_idx];
1974 	mode->num_channels = mode11g->num_channels;
1975 	mode->channels = os_memdup(mode11g->channels,
1976 				   mode11g->num_channels *
1977 				   sizeof(struct hostapd_channel_data));
1978 	if (mode->channels == NULL) {
1979 		(*num_modes)--;
1980 		return modes; /* Could not add 802.11b mode */
1981 	}
1982 
1983 	mode->num_rates = 0;
1984 	mode->rates = os_malloc(4 * sizeof(int));
1985 	if (mode->rates == NULL) {
1986 		os_free(mode->channels);
1987 		(*num_modes)--;
1988 		return modes; /* Could not add 802.11b mode */
1989 	}
1990 
1991 	for (i = 0; i < mode11g->num_rates; i++) {
1992 		if (mode11g->rates[i] != 10 && mode11g->rates[i] != 20 &&
1993 		    mode11g->rates[i] != 55 && mode11g->rates[i] != 110)
1994 			continue;
1995 		mode->rates[mode->num_rates] = mode11g->rates[i];
1996 		mode->num_rates++;
1997 		if (mode->num_rates == 4)
1998 			break;
1999 	}
2000 
2001 	if (mode->num_rates == 0) {
2002 		os_free(mode->channels);
2003 		os_free(mode->rates);
2004 		(*num_modes)--;
2005 		return modes; /* No 802.11b rates */
2006 	}
2007 
2008 	wpa_printf(MSG_DEBUG, "nl80211: Added 802.11b mode based on 802.11g "
2009 		   "information");
2010 
2011 	return modes;
2012 }
2013 
2014 
nl80211_set_ht40_mode(struct hostapd_hw_modes * mode,int start,int end)2015 static void nl80211_set_ht40_mode(struct hostapd_hw_modes *mode, int start,
2016 				  int end)
2017 {
2018 	int c;
2019 
2020 	for (c = 0; c < mode->num_channels; c++) {
2021 		struct hostapd_channel_data *chan = &mode->channels[c];
2022 		if (chan->freq - 10 >= start && chan->freq + 10 <= end)
2023 			chan->flag |= HOSTAPD_CHAN_HT40;
2024 	}
2025 }
2026 
2027 
nl80211_set_ht40_mode_sec(struct hostapd_hw_modes * mode,int start,int end)2028 static void nl80211_set_ht40_mode_sec(struct hostapd_hw_modes *mode, int start,
2029 				      int end)
2030 {
2031 	int c;
2032 
2033 	for (c = 0; c < mode->num_channels; c++) {
2034 		struct hostapd_channel_data *chan = &mode->channels[c];
2035 		if (!(chan->flag & HOSTAPD_CHAN_HT40))
2036 			continue;
2037 		if (chan->freq - 30 >= start && chan->freq - 10 <= end)
2038 			chan->flag |= HOSTAPD_CHAN_HT40MINUS;
2039 		if (chan->freq + 10 >= start && chan->freq + 30 <= end)
2040 			chan->flag |= HOSTAPD_CHAN_HT40PLUS;
2041 	}
2042 }
2043 
2044 
nl80211_reg_rule_max_eirp(u32 start,u32 end,u32 max_eirp,struct phy_info_arg * results)2045 static void nl80211_reg_rule_max_eirp(u32 start, u32 end, u32 max_eirp,
2046 				      struct phy_info_arg *results)
2047 {
2048 	u16 m;
2049 
2050 	for (m = 0; m < *results->num_modes; m++) {
2051 		int c;
2052 		struct hostapd_hw_modes *mode = &results->modes[m];
2053 
2054 		for (c = 0; c < mode->num_channels; c++) {
2055 			struct hostapd_channel_data *chan = &mode->channels[c];
2056 			if ((u32) chan->freq - 10 >= start &&
2057 			    (u32) chan->freq + 10 <= end)
2058 				chan->max_tx_power = max_eirp;
2059 		}
2060 	}
2061 }
2062 
2063 
nl80211_reg_rule_ht40(u32 start,u32 end,struct phy_info_arg * results)2064 static void nl80211_reg_rule_ht40(u32 start, u32 end,
2065 				  struct phy_info_arg *results)
2066 {
2067 	u16 m;
2068 
2069 	for (m = 0; m < *results->num_modes; m++) {
2070 		if (!(results->modes[m].ht_capab &
2071 		      HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET))
2072 			continue;
2073 		nl80211_set_ht40_mode(&results->modes[m], start, end);
2074 	}
2075 }
2076 
2077 
nl80211_reg_rule_sec(struct nlattr * tb[],struct phy_info_arg * results)2078 static void nl80211_reg_rule_sec(struct nlattr *tb[],
2079 				 struct phy_info_arg *results)
2080 {
2081 	u32 start, end, max_bw;
2082 	u16 m;
2083 
2084 	if (tb[NL80211_ATTR_FREQ_RANGE_START] == NULL ||
2085 	    tb[NL80211_ATTR_FREQ_RANGE_END] == NULL ||
2086 	    tb[NL80211_ATTR_FREQ_RANGE_MAX_BW] == NULL)
2087 		return;
2088 
2089 	start = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]) / 1000;
2090 	end = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]) / 1000;
2091 	max_bw = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) / 1000;
2092 
2093 	if (max_bw < 20)
2094 		return;
2095 
2096 	for (m = 0; m < *results->num_modes; m++) {
2097 		if (!(results->modes[m].ht_capab &
2098 		      HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET))
2099 			continue;
2100 		nl80211_set_ht40_mode_sec(&results->modes[m], start, end);
2101 	}
2102 }
2103 
2104 
nl80211_set_vht_mode(struct hostapd_hw_modes * mode,int start,int end,int max_bw)2105 static void nl80211_set_vht_mode(struct hostapd_hw_modes *mode, int start,
2106 				 int end, int max_bw)
2107 {
2108 	int c;
2109 
2110 	for (c = 0; c < mode->num_channels; c++) {
2111 		struct hostapd_channel_data *chan = &mode->channels[c];
2112 		if (chan->freq - 10 >= start && chan->freq + 70 <= end)
2113 			chan->flag |= HOSTAPD_CHAN_VHT_10_70;
2114 
2115 		if (chan->freq - 30 >= start && chan->freq + 50 <= end)
2116 			chan->flag |= HOSTAPD_CHAN_VHT_30_50;
2117 
2118 		if (chan->freq - 50 >= start && chan->freq + 30 <= end)
2119 			chan->flag |= HOSTAPD_CHAN_VHT_50_30;
2120 
2121 		if (chan->freq - 70 >= start && chan->freq + 10 <= end)
2122 			chan->flag |= HOSTAPD_CHAN_VHT_70_10;
2123 
2124 		if (max_bw >= 160) {
2125 			if (chan->freq - 10 >= start && chan->freq + 150 <= end)
2126 				chan->flag |= HOSTAPD_CHAN_VHT_10_150;
2127 
2128 			if (chan->freq - 30 >= start && chan->freq + 130 <= end)
2129 				chan->flag |= HOSTAPD_CHAN_VHT_30_130;
2130 
2131 			if (chan->freq - 50 >= start && chan->freq + 110 <= end)
2132 				chan->flag |= HOSTAPD_CHAN_VHT_50_110;
2133 
2134 			if (chan->freq - 70 >= start && chan->freq + 90 <= end)
2135 				chan->flag |= HOSTAPD_CHAN_VHT_70_90;
2136 
2137 			if (chan->freq - 90 >= start && chan->freq + 70 <= end)
2138 				chan->flag |= HOSTAPD_CHAN_VHT_90_70;
2139 
2140 			if (chan->freq - 110 >= start && chan->freq + 50 <= end)
2141 				chan->flag |= HOSTAPD_CHAN_VHT_110_50;
2142 
2143 			if (chan->freq - 130 >= start && chan->freq + 30 <= end)
2144 				chan->flag |= HOSTAPD_CHAN_VHT_130_30;
2145 
2146 			if (chan->freq - 150 >= start && chan->freq + 10 <= end)
2147 				chan->flag |= HOSTAPD_CHAN_VHT_150_10;
2148 		}
2149 	}
2150 }
2151 
2152 
nl80211_reg_rule_vht(struct nlattr * tb[],struct phy_info_arg * results)2153 static void nl80211_reg_rule_vht(struct nlattr *tb[],
2154 				 struct phy_info_arg *results)
2155 {
2156 	u32 start, end, max_bw;
2157 	u16 m;
2158 
2159 	if (tb[NL80211_ATTR_FREQ_RANGE_START] == NULL ||
2160 	    tb[NL80211_ATTR_FREQ_RANGE_END] == NULL ||
2161 	    tb[NL80211_ATTR_FREQ_RANGE_MAX_BW] == NULL)
2162 		return;
2163 
2164 	start = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]) / 1000;
2165 	end = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]) / 1000;
2166 	max_bw = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) / 1000;
2167 
2168 	if (max_bw < 80)
2169 		return;
2170 
2171 	for (m = 0; m < *results->num_modes; m++) {
2172 		if (!(results->modes[m].ht_capab &
2173 		      HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET))
2174 			continue;
2175 		/* TODO: use a real VHT support indication */
2176 		if (!results->modes[m].vht_capab)
2177 			continue;
2178 
2179 		nl80211_set_vht_mode(&results->modes[m], start, end, max_bw);
2180 	}
2181 }
2182 
2183 
nl80211_set_dfs_domain(enum nl80211_dfs_regions region,u8 * dfs_domain)2184 static void nl80211_set_dfs_domain(enum nl80211_dfs_regions region,
2185 				   u8 *dfs_domain)
2186 {
2187 	if (region == NL80211_DFS_FCC)
2188 		*dfs_domain = HOSTAPD_DFS_REGION_FCC;
2189 	else if (region == NL80211_DFS_ETSI)
2190 		*dfs_domain = HOSTAPD_DFS_REGION_ETSI;
2191 	else if (region == NL80211_DFS_JP)
2192 		*dfs_domain = HOSTAPD_DFS_REGION_JP;
2193 	else
2194 		*dfs_domain = 0;
2195 }
2196 
2197 
dfs_domain_name(enum nl80211_dfs_regions region)2198 static const char * dfs_domain_name(enum nl80211_dfs_regions region)
2199 {
2200 	switch (region) {
2201 	case NL80211_DFS_UNSET:
2202 		return "DFS-UNSET";
2203 	case NL80211_DFS_FCC:
2204 		return "DFS-FCC";
2205 	case NL80211_DFS_ETSI:
2206 		return "DFS-ETSI";
2207 	case NL80211_DFS_JP:
2208 		return "DFS-JP";
2209 	default:
2210 		return "DFS-invalid";
2211 	}
2212 }
2213 
2214 
nl80211_get_reg(struct nl_msg * msg,void * arg)2215 static int nl80211_get_reg(struct nl_msg *msg, void *arg)
2216 {
2217 	struct phy_info_arg *results = arg;
2218 	struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
2219 	struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
2220 	struct nlattr *nl_rule;
2221 	struct nlattr *tb_rule[NL80211_FREQUENCY_ATTR_MAX + 1];
2222 	int rem_rule;
2223 	static struct nla_policy reg_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = {
2224 		[NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
2225 		[NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
2226 		[NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
2227 		[NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
2228 		[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
2229 		[NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
2230 	};
2231 
2232 	nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
2233 		  genlmsg_attrlen(gnlh, 0), NULL);
2234 	if (!tb_msg[NL80211_ATTR_REG_ALPHA2] ||
2235 	    !tb_msg[NL80211_ATTR_REG_RULES]) {
2236 		wpa_printf(MSG_DEBUG, "nl80211: No regulatory information "
2237 			   "available");
2238 		return NL_SKIP;
2239 	}
2240 
2241 	if (tb_msg[NL80211_ATTR_DFS_REGION]) {
2242 		enum nl80211_dfs_regions dfs_domain;
2243 		dfs_domain = nla_get_u8(tb_msg[NL80211_ATTR_DFS_REGION]);
2244 		nl80211_set_dfs_domain(dfs_domain, &results->dfs_domain);
2245 		wpa_printf(MSG_DEBUG, "nl80211: Regulatory information - country=%s (%s)",
2246 			   (char *) nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]),
2247 			   dfs_domain_name(dfs_domain));
2248 	} else {
2249 		wpa_printf(MSG_DEBUG, "nl80211: Regulatory information - country=%s",
2250 			   (char *) nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]));
2251 	}
2252 
2253 	nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule)
2254 	{
2255 		u32 start, end, max_eirp = 0, max_bw = 0, flags = 0;
2256 		nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX,
2257 			  nla_data(nl_rule), nla_len(nl_rule), reg_policy);
2258 		if (tb_rule[NL80211_ATTR_FREQ_RANGE_START] == NULL ||
2259 		    tb_rule[NL80211_ATTR_FREQ_RANGE_END] == NULL)
2260 			continue;
2261 		start = nla_get_u32(tb_rule[NL80211_ATTR_FREQ_RANGE_START]) / 1000;
2262 		end = nla_get_u32(tb_rule[NL80211_ATTR_FREQ_RANGE_END]) / 1000;
2263 		if (tb_rule[NL80211_ATTR_POWER_RULE_MAX_EIRP])
2264 			max_eirp = nla_get_u32(tb_rule[NL80211_ATTR_POWER_RULE_MAX_EIRP]) / 100;
2265 		if (tb_rule[NL80211_ATTR_FREQ_RANGE_MAX_BW])
2266 			max_bw = nla_get_u32(tb_rule[NL80211_ATTR_FREQ_RANGE_MAX_BW]) / 1000;
2267 		if (tb_rule[NL80211_ATTR_REG_RULE_FLAGS])
2268 			flags = nla_get_u32(tb_rule[NL80211_ATTR_REG_RULE_FLAGS]);
2269 
2270 		wpa_printf(MSG_DEBUG, "nl80211: %u-%u @ %u MHz %u mBm%s%s%s%s%s%s%s%s",
2271 			   start, end, max_bw, max_eirp,
2272 			   flags & NL80211_RRF_NO_OFDM ? " (no OFDM)" : "",
2273 			   flags & NL80211_RRF_NO_CCK ? " (no CCK)" : "",
2274 			   flags & NL80211_RRF_NO_INDOOR ? " (no indoor)" : "",
2275 			   flags & NL80211_RRF_NO_OUTDOOR ? " (no outdoor)" :
2276 			   "",
2277 			   flags & NL80211_RRF_DFS ? " (DFS)" : "",
2278 			   flags & NL80211_RRF_PTP_ONLY ? " (PTP only)" : "",
2279 			   flags & NL80211_RRF_PTMP_ONLY ? " (PTMP only)" : "",
2280 			   flags & NL80211_RRF_NO_IR ? " (no IR)" : "");
2281 		if (max_bw >= 40)
2282 			nl80211_reg_rule_ht40(start, end, results);
2283 		if (tb_rule[NL80211_ATTR_POWER_RULE_MAX_EIRP])
2284 			nl80211_reg_rule_max_eirp(start, end, max_eirp,
2285 						  results);
2286 	}
2287 
2288 	nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule)
2289 	{
2290 		nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX,
2291 			  nla_data(nl_rule), nla_len(nl_rule), reg_policy);
2292 		nl80211_reg_rule_sec(tb_rule, results);
2293 	}
2294 
2295 	nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule)
2296 	{
2297 		nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX,
2298 			  nla_data(nl_rule), nla_len(nl_rule), reg_policy);
2299 		nl80211_reg_rule_vht(tb_rule, results);
2300 	}
2301 
2302 	return NL_SKIP;
2303 }
2304 
2305 
nl80211_set_regulatory_flags(struct wpa_driver_nl80211_data * drv,struct phy_info_arg * results)2306 static int nl80211_set_regulatory_flags(struct wpa_driver_nl80211_data *drv,
2307 					struct phy_info_arg *results)
2308 {
2309 	struct nl_msg *msg;
2310 
2311 	msg = nlmsg_alloc();
2312 	if (!msg)
2313 		return -ENOMEM;
2314 
2315 	nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG);
2316 	if (drv->capa.flags & WPA_DRIVER_FLAGS_SELF_MANAGED_REGULATORY) {
2317 		if (nla_put_u32(msg, NL80211_ATTR_WIPHY, drv->wiphy_idx)) {
2318 			nlmsg_free(msg);
2319 			return -1;
2320 		}
2321 	}
2322 
2323 	return send_and_recv_msgs(drv, msg, nl80211_get_reg, results);
2324 }
2325 
2326 
modestr(enum hostapd_hw_mode mode)2327 static const char * modestr(enum hostapd_hw_mode mode)
2328 {
2329 	switch (mode) {
2330 	case HOSTAPD_MODE_IEEE80211B:
2331 		return "802.11b";
2332 	case HOSTAPD_MODE_IEEE80211G:
2333 		return "802.11g";
2334 	case HOSTAPD_MODE_IEEE80211A:
2335 		return "802.11a";
2336 	case HOSTAPD_MODE_IEEE80211AD:
2337 		return "802.11ad";
2338 	default:
2339 		return "?";
2340 	}
2341 }
2342 
2343 
nl80211_dump_chan_list(struct hostapd_hw_modes * modes,u16 num_modes)2344 static void nl80211_dump_chan_list(struct hostapd_hw_modes *modes,
2345 				   u16 num_modes)
2346 {
2347 	int i;
2348 
2349 	if (!modes)
2350 		return;
2351 
2352 	for (i = 0; i < num_modes; i++) {
2353 		struct hostapd_hw_modes *mode = &modes[i];
2354 		char str[200];
2355 		char *pos = str;
2356 		char *end = pos + sizeof(str);
2357 		int j, res;
2358 
2359 		for (j = 0; j < mode->num_channels; j++) {
2360 			struct hostapd_channel_data *chan = &mode->channels[j];
2361 
2362 			res = os_snprintf(pos, end - pos, " %d%s%s%s",
2363 					  chan->freq,
2364 					  (chan->flag & HOSTAPD_CHAN_DISABLED) ?
2365 					  "[DISABLED]" : "",
2366 					  (chan->flag & HOSTAPD_CHAN_NO_IR) ?
2367 					  "[NO_IR]" : "",
2368 					  (chan->flag & HOSTAPD_CHAN_RADAR) ?
2369 					  "[RADAR]" : "");
2370 			if (os_snprintf_error(end - pos, res))
2371 				break;
2372 			pos += res;
2373 		}
2374 
2375 		*pos = '\0';
2376 		wpa_printf(MSG_DEBUG, "nl80211: Mode IEEE %s:%s",
2377 			   modestr(mode->mode), str);
2378 	}
2379 }
2380 
2381 
2382 struct hostapd_hw_modes *
nl80211_get_hw_feature_data(void * priv,u16 * num_modes,u16 * flags,u8 * dfs_domain)2383 nl80211_get_hw_feature_data(void *priv, u16 *num_modes, u16 *flags,
2384 			    u8 *dfs_domain)
2385 {
2386 	u32 feat;
2387 	struct i802_bss *bss = priv;
2388 	struct wpa_driver_nl80211_data *drv = bss->drv;
2389 	int nl_flags = 0;
2390 	struct nl_msg *msg;
2391 	struct phy_info_arg result = {
2392 		.num_modes = num_modes,
2393 		.modes = NULL,
2394 		.last_mode = -1,
2395 		.failed = 0,
2396 		.dfs_domain = 0,
2397 	};
2398 
2399 	*num_modes = 0;
2400 	*flags = 0;
2401 	*dfs_domain = 0;
2402 
2403 	feat = get_nl80211_protocol_features(drv);
2404 	if (feat & NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)
2405 		nl_flags = NLM_F_DUMP;
2406 	if (!(msg = nl80211_cmd_msg(bss, nl_flags, NL80211_CMD_GET_WIPHY)) ||
2407 	    nla_put_flag(msg, NL80211_ATTR_SPLIT_WIPHY_DUMP)) {
2408 		nlmsg_free(msg);
2409 		return NULL;
2410 	}
2411 
2412 	if (send_and_recv_msgs(drv, msg, phy_info_handler, &result) == 0) {
2413 		struct hostapd_hw_modes *modes;
2414 
2415 		nl80211_set_regulatory_flags(drv, &result);
2416 		if (result.failed) {
2417 			int i;
2418 
2419 			for (i = 0; result.modes && i < *num_modes; i++) {
2420 				os_free(result.modes[i].channels);
2421 				os_free(result.modes[i].rates);
2422 			}
2423 			os_free(result.modes);
2424 			*num_modes = 0;
2425 			return NULL;
2426 		}
2427 
2428 		*dfs_domain = result.dfs_domain;
2429 
2430 		modes = wpa_driver_nl80211_postprocess_modes(result.modes,
2431 							     num_modes);
2432 		nl80211_dump_chan_list(modes, *num_modes);
2433 		return modes;
2434 	}
2435 
2436 	return NULL;
2437 }
2438