xref: /freebsd/contrib/wpa/src/drivers/driver_nl80211_capa.c (revision 4bc523382c7e72183c32be2c3aedecc1f5e844dd)
15b9c547cSRui Paulo /*
25b9c547cSRui Paulo  * Driver interaction with Linux nl80211/cfg80211 - Capabilities
35b9c547cSRui Paulo  * Copyright (c) 2002-2015, Jouni Malinen <j@w1.fi>
45b9c547cSRui Paulo  * Copyright (c) 2007, Johannes Berg <johannes@sipsolutions.net>
55b9c547cSRui Paulo  * Copyright (c) 2009-2010, Atheros Communications
65b9c547cSRui Paulo  *
75b9c547cSRui Paulo  * This software may be distributed under the terms of the BSD license.
85b9c547cSRui Paulo  * See README for more details.
95b9c547cSRui Paulo  */
105b9c547cSRui Paulo 
115b9c547cSRui Paulo #include "includes.h"
125b9c547cSRui Paulo #include <netlink/genl/genl.h>
135b9c547cSRui Paulo 
145b9c547cSRui Paulo #include "utils/common.h"
155b9c547cSRui Paulo #include "common/ieee802_11_common.h"
1685732ac8SCy Schubert #include "common/wpa_common.h"
175b9c547cSRui Paulo #include "common/qca-vendor.h"
185b9c547cSRui Paulo #include "common/qca-vendor-attr.h"
195b9c547cSRui Paulo #include "driver_nl80211.h"
205b9c547cSRui Paulo 
215b9c547cSRui Paulo 
225b9c547cSRui Paulo static int protocol_feature_handler(struct nl_msg *msg, void *arg)
235b9c547cSRui Paulo {
245b9c547cSRui Paulo 	u32 *feat = arg;
255b9c547cSRui Paulo 	struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
265b9c547cSRui Paulo 	struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
275b9c547cSRui Paulo 
285b9c547cSRui Paulo 	nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
295b9c547cSRui Paulo 		  genlmsg_attrlen(gnlh, 0), NULL);
305b9c547cSRui Paulo 
315b9c547cSRui Paulo 	if (tb_msg[NL80211_ATTR_PROTOCOL_FEATURES])
325b9c547cSRui Paulo 		*feat = nla_get_u32(tb_msg[NL80211_ATTR_PROTOCOL_FEATURES]);
335b9c547cSRui Paulo 
345b9c547cSRui Paulo 	return NL_SKIP;
355b9c547cSRui Paulo }
365b9c547cSRui Paulo 
375b9c547cSRui Paulo 
385b9c547cSRui Paulo static u32 get_nl80211_protocol_features(struct wpa_driver_nl80211_data *drv)
395b9c547cSRui Paulo {
405b9c547cSRui Paulo 	u32 feat = 0;
415b9c547cSRui Paulo 	struct nl_msg *msg;
425b9c547cSRui Paulo 
435b9c547cSRui Paulo 	msg = nlmsg_alloc();
445b9c547cSRui Paulo 	if (!msg)
455b9c547cSRui Paulo 		return 0;
465b9c547cSRui Paulo 
475b9c547cSRui Paulo 	if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_PROTOCOL_FEATURES)) {
485b9c547cSRui Paulo 		nlmsg_free(msg);
495b9c547cSRui Paulo 		return 0;
505b9c547cSRui Paulo 	}
515b9c547cSRui Paulo 
525b9c547cSRui Paulo 	if (send_and_recv_msgs(drv, msg, protocol_feature_handler, &feat) == 0)
535b9c547cSRui Paulo 		return feat;
545b9c547cSRui Paulo 
555b9c547cSRui Paulo 	return 0;
565b9c547cSRui Paulo }
575b9c547cSRui Paulo 
585b9c547cSRui Paulo 
595b9c547cSRui Paulo struct wiphy_info_data {
605b9c547cSRui Paulo 	struct wpa_driver_nl80211_data *drv;
615b9c547cSRui Paulo 	struct wpa_driver_capa *capa;
625b9c547cSRui Paulo 
635b9c547cSRui Paulo 	unsigned int num_multichan_concurrent;
645b9c547cSRui Paulo 
655b9c547cSRui Paulo 	unsigned int error:1;
665b9c547cSRui Paulo 	unsigned int device_ap_sme:1;
675b9c547cSRui Paulo 	unsigned int poll_command_supported:1;
685b9c547cSRui Paulo 	unsigned int data_tx_status:1;
695b9c547cSRui Paulo 	unsigned int auth_supported:1;
705b9c547cSRui Paulo 	unsigned int connect_supported:1;
715b9c547cSRui Paulo 	unsigned int p2p_go_supported:1;
725b9c547cSRui Paulo 	unsigned int p2p_client_supported:1;
735b9c547cSRui Paulo 	unsigned int p2p_go_ctwindow_supported:1;
745b9c547cSRui Paulo 	unsigned int p2p_concurrent:1;
755b9c547cSRui Paulo 	unsigned int channel_switch_supported:1;
765b9c547cSRui Paulo 	unsigned int set_qos_map_supported:1;
775b9c547cSRui Paulo 	unsigned int have_low_prio_scan:1;
785b9c547cSRui Paulo 	unsigned int wmm_ac_supported:1;
795b9c547cSRui Paulo 	unsigned int mac_addr_rand_scan_supported:1;
805b9c547cSRui Paulo 	unsigned int mac_addr_rand_sched_scan_supported:1;
815b9c547cSRui Paulo };
825b9c547cSRui Paulo 
835b9c547cSRui Paulo 
845b9c547cSRui Paulo static unsigned int probe_resp_offload_support(int supp_protocols)
855b9c547cSRui Paulo {
865b9c547cSRui Paulo 	unsigned int prot = 0;
875b9c547cSRui Paulo 
885b9c547cSRui Paulo 	if (supp_protocols & NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS)
895b9c547cSRui Paulo 		prot |= WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS;
905b9c547cSRui Paulo 	if (supp_protocols & NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2)
915b9c547cSRui Paulo 		prot |= WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2;
925b9c547cSRui Paulo 	if (supp_protocols & NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P)
935b9c547cSRui Paulo 		prot |= WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P;
945b9c547cSRui Paulo 	if (supp_protocols & NL80211_PROBE_RESP_OFFLOAD_SUPPORT_80211U)
955b9c547cSRui Paulo 		prot |= WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING;
965b9c547cSRui Paulo 
975b9c547cSRui Paulo 	return prot;
985b9c547cSRui Paulo }
995b9c547cSRui Paulo 
1005b9c547cSRui Paulo 
1015b9c547cSRui Paulo static void wiphy_info_supported_iftypes(struct wiphy_info_data *info,
1025b9c547cSRui Paulo 					 struct nlattr *tb)
1035b9c547cSRui Paulo {
1045b9c547cSRui Paulo 	struct nlattr *nl_mode;
1055b9c547cSRui Paulo 	int i;
1065b9c547cSRui Paulo 
1075b9c547cSRui Paulo 	if (tb == NULL)
1085b9c547cSRui Paulo 		return;
1095b9c547cSRui Paulo 
1105b9c547cSRui Paulo 	nla_for_each_nested(nl_mode, tb, i) {
1115b9c547cSRui Paulo 		switch (nla_type(nl_mode)) {
1125b9c547cSRui Paulo 		case NL80211_IFTYPE_AP:
1135b9c547cSRui Paulo 			info->capa->flags |= WPA_DRIVER_FLAGS_AP;
1145b9c547cSRui Paulo 			break;
1155b9c547cSRui Paulo 		case NL80211_IFTYPE_MESH_POINT:
1165b9c547cSRui Paulo 			info->capa->flags |= WPA_DRIVER_FLAGS_MESH;
1175b9c547cSRui Paulo 			break;
1185b9c547cSRui Paulo 		case NL80211_IFTYPE_ADHOC:
1195b9c547cSRui Paulo 			info->capa->flags |= WPA_DRIVER_FLAGS_IBSS;
1205b9c547cSRui Paulo 			break;
1215b9c547cSRui Paulo 		case NL80211_IFTYPE_P2P_DEVICE:
1225b9c547cSRui Paulo 			info->capa->flags |=
1235b9c547cSRui Paulo 				WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE;
1245b9c547cSRui Paulo 			break;
1255b9c547cSRui Paulo 		case NL80211_IFTYPE_P2P_GO:
1265b9c547cSRui Paulo 			info->p2p_go_supported = 1;
1275b9c547cSRui Paulo 			break;
1285b9c547cSRui Paulo 		case NL80211_IFTYPE_P2P_CLIENT:
1295b9c547cSRui Paulo 			info->p2p_client_supported = 1;
1305b9c547cSRui Paulo 			break;
1315b9c547cSRui Paulo 		}
1325b9c547cSRui Paulo 	}
1335b9c547cSRui Paulo }
1345b9c547cSRui Paulo 
1355b9c547cSRui Paulo 
1365b9c547cSRui Paulo static int wiphy_info_iface_comb_process(struct wiphy_info_data *info,
1375b9c547cSRui Paulo 					 struct nlattr *nl_combi)
1385b9c547cSRui Paulo {
1395b9c547cSRui Paulo 	struct nlattr *tb_comb[NUM_NL80211_IFACE_COMB];
1405b9c547cSRui Paulo 	struct nlattr *tb_limit[NUM_NL80211_IFACE_LIMIT];
1415b9c547cSRui Paulo 	struct nlattr *nl_limit, *nl_mode;
1425b9c547cSRui Paulo 	int err, rem_limit, rem_mode;
1435b9c547cSRui Paulo 	int combination_has_p2p = 0, combination_has_mgd = 0;
1445b9c547cSRui Paulo 	static struct nla_policy
1455b9c547cSRui Paulo 	iface_combination_policy[NUM_NL80211_IFACE_COMB] = {
1465b9c547cSRui Paulo 		[NL80211_IFACE_COMB_LIMITS] = { .type = NLA_NESTED },
1475b9c547cSRui Paulo 		[NL80211_IFACE_COMB_MAXNUM] = { .type = NLA_U32 },
1485b9c547cSRui Paulo 		[NL80211_IFACE_COMB_STA_AP_BI_MATCH] = { .type = NLA_FLAG },
1495b9c547cSRui Paulo 		[NL80211_IFACE_COMB_NUM_CHANNELS] = { .type = NLA_U32 },
1505b9c547cSRui Paulo 		[NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS] = { .type = NLA_U32 },
1515b9c547cSRui Paulo 	},
1525b9c547cSRui Paulo 	iface_limit_policy[NUM_NL80211_IFACE_LIMIT] = {
1535b9c547cSRui Paulo 		[NL80211_IFACE_LIMIT_TYPES] = { .type = NLA_NESTED },
1545b9c547cSRui Paulo 		[NL80211_IFACE_LIMIT_MAX] = { .type = NLA_U32 },
1555b9c547cSRui Paulo 	};
1565b9c547cSRui Paulo 
1575b9c547cSRui Paulo 	err = nla_parse_nested(tb_comb, MAX_NL80211_IFACE_COMB,
1585b9c547cSRui Paulo 			       nl_combi, iface_combination_policy);
1595b9c547cSRui Paulo 	if (err || !tb_comb[NL80211_IFACE_COMB_LIMITS] ||
1605b9c547cSRui Paulo 	    !tb_comb[NL80211_IFACE_COMB_MAXNUM] ||
1615b9c547cSRui Paulo 	    !tb_comb[NL80211_IFACE_COMB_NUM_CHANNELS])
1625b9c547cSRui Paulo 		return 0; /* broken combination */
1635b9c547cSRui Paulo 
1645b9c547cSRui Paulo 	if (tb_comb[NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS])
1655b9c547cSRui Paulo 		info->capa->flags |= WPA_DRIVER_FLAGS_RADAR;
1665b9c547cSRui Paulo 
1675b9c547cSRui Paulo 	nla_for_each_nested(nl_limit, tb_comb[NL80211_IFACE_COMB_LIMITS],
1685b9c547cSRui Paulo 			    rem_limit) {
1695b9c547cSRui Paulo 		err = nla_parse_nested(tb_limit, MAX_NL80211_IFACE_LIMIT,
1705b9c547cSRui Paulo 				       nl_limit, iface_limit_policy);
1715b9c547cSRui Paulo 		if (err || !tb_limit[NL80211_IFACE_LIMIT_TYPES])
1725b9c547cSRui Paulo 			return 0; /* broken combination */
1735b9c547cSRui Paulo 
1745b9c547cSRui Paulo 		nla_for_each_nested(nl_mode,
1755b9c547cSRui Paulo 				    tb_limit[NL80211_IFACE_LIMIT_TYPES],
1765b9c547cSRui Paulo 				    rem_mode) {
1775b9c547cSRui Paulo 			int ift = nla_type(nl_mode);
1785b9c547cSRui Paulo 			if (ift == NL80211_IFTYPE_P2P_GO ||
1795b9c547cSRui Paulo 			    ift == NL80211_IFTYPE_P2P_CLIENT)
1805b9c547cSRui Paulo 				combination_has_p2p = 1;
1815b9c547cSRui Paulo 			if (ift == NL80211_IFTYPE_STATION)
1825b9c547cSRui Paulo 				combination_has_mgd = 1;
1835b9c547cSRui Paulo 		}
1845b9c547cSRui Paulo 		if (combination_has_p2p && combination_has_mgd)
1855b9c547cSRui Paulo 			break;
1865b9c547cSRui Paulo 	}
1875b9c547cSRui Paulo 
1885b9c547cSRui Paulo 	if (combination_has_p2p && combination_has_mgd) {
1895b9c547cSRui Paulo 		unsigned int num_channels =
1905b9c547cSRui Paulo 			nla_get_u32(tb_comb[NL80211_IFACE_COMB_NUM_CHANNELS]);
1915b9c547cSRui Paulo 
1925b9c547cSRui Paulo 		info->p2p_concurrent = 1;
1935b9c547cSRui Paulo 		if (info->num_multichan_concurrent < num_channels)
1945b9c547cSRui Paulo 			info->num_multichan_concurrent = num_channels;
1955b9c547cSRui Paulo 	}
1965b9c547cSRui Paulo 
1975b9c547cSRui Paulo 	return 0;
1985b9c547cSRui Paulo }
1995b9c547cSRui Paulo 
2005b9c547cSRui Paulo 
2015b9c547cSRui Paulo static void wiphy_info_iface_comb(struct wiphy_info_data *info,
2025b9c547cSRui Paulo 				  struct nlattr *tb)
2035b9c547cSRui Paulo {
2045b9c547cSRui Paulo 	struct nlattr *nl_combi;
2055b9c547cSRui Paulo 	int rem_combi;
2065b9c547cSRui Paulo 
2075b9c547cSRui Paulo 	if (tb == NULL)
2085b9c547cSRui Paulo 		return;
2095b9c547cSRui Paulo 
2105b9c547cSRui Paulo 	nla_for_each_nested(nl_combi, tb, rem_combi) {
2115b9c547cSRui Paulo 		if (wiphy_info_iface_comb_process(info, nl_combi) > 0)
2125b9c547cSRui Paulo 			break;
2135b9c547cSRui Paulo 	}
2145b9c547cSRui Paulo }
2155b9c547cSRui Paulo 
2165b9c547cSRui Paulo 
2175b9c547cSRui Paulo static void wiphy_info_supp_cmds(struct wiphy_info_data *info,
2185b9c547cSRui Paulo 				 struct nlattr *tb)
2195b9c547cSRui Paulo {
2205b9c547cSRui Paulo 	struct nlattr *nl_cmd;
2215b9c547cSRui Paulo 	int i;
2225b9c547cSRui Paulo 
2235b9c547cSRui Paulo 	if (tb == NULL)
2245b9c547cSRui Paulo 		return;
2255b9c547cSRui Paulo 
2265b9c547cSRui Paulo 	nla_for_each_nested(nl_cmd, tb, i) {
2275b9c547cSRui Paulo 		switch (nla_get_u32(nl_cmd)) {
2285b9c547cSRui Paulo 		case NL80211_CMD_AUTHENTICATE:
2295b9c547cSRui Paulo 			info->auth_supported = 1;
2305b9c547cSRui Paulo 			break;
2315b9c547cSRui Paulo 		case NL80211_CMD_CONNECT:
2325b9c547cSRui Paulo 			info->connect_supported = 1;
2335b9c547cSRui Paulo 			break;
2345b9c547cSRui Paulo 		case NL80211_CMD_START_SCHED_SCAN:
2355b9c547cSRui Paulo 			info->capa->sched_scan_supported = 1;
2365b9c547cSRui Paulo 			break;
2375b9c547cSRui Paulo 		case NL80211_CMD_PROBE_CLIENT:
2385b9c547cSRui Paulo 			info->poll_command_supported = 1;
2395b9c547cSRui Paulo 			break;
2405b9c547cSRui Paulo 		case NL80211_CMD_CHANNEL_SWITCH:
2415b9c547cSRui Paulo 			info->channel_switch_supported = 1;
2425b9c547cSRui Paulo 			break;
2435b9c547cSRui Paulo 		case NL80211_CMD_SET_QOS_MAP:
2445b9c547cSRui Paulo 			info->set_qos_map_supported = 1;
2455b9c547cSRui Paulo 			break;
2465b9c547cSRui Paulo 		}
2475b9c547cSRui Paulo 	}
2485b9c547cSRui Paulo }
2495b9c547cSRui Paulo 
2505b9c547cSRui Paulo 
2515b9c547cSRui Paulo static void wiphy_info_cipher_suites(struct wiphy_info_data *info,
2525b9c547cSRui Paulo 				     struct nlattr *tb)
2535b9c547cSRui Paulo {
2545b9c547cSRui Paulo 	int i, num;
2555b9c547cSRui Paulo 	u32 *ciphers;
2565b9c547cSRui Paulo 
2575b9c547cSRui Paulo 	if (tb == NULL)
2585b9c547cSRui Paulo 		return;
2595b9c547cSRui Paulo 
2605b9c547cSRui Paulo 	num = nla_len(tb) / sizeof(u32);
2615b9c547cSRui Paulo 	ciphers = nla_data(tb);
2625b9c547cSRui Paulo 	for (i = 0; i < num; i++) {
2635b9c547cSRui Paulo 		u32 c = ciphers[i];
2645b9c547cSRui Paulo 
2655b9c547cSRui Paulo 		wpa_printf(MSG_DEBUG, "nl80211: Supported cipher %02x-%02x-%02x:%d",
2665b9c547cSRui Paulo 			   c >> 24, (c >> 16) & 0xff,
2675b9c547cSRui Paulo 			   (c >> 8) & 0xff, c & 0xff);
2685b9c547cSRui Paulo 		switch (c) {
26985732ac8SCy Schubert 		case RSN_CIPHER_SUITE_CCMP_256:
2705b9c547cSRui Paulo 			info->capa->enc |= WPA_DRIVER_CAPA_ENC_CCMP_256;
2715b9c547cSRui Paulo 			break;
27285732ac8SCy Schubert 		case RSN_CIPHER_SUITE_GCMP_256:
2735b9c547cSRui Paulo 			info->capa->enc |= WPA_DRIVER_CAPA_ENC_GCMP_256;
2745b9c547cSRui Paulo 			break;
27585732ac8SCy Schubert 		case RSN_CIPHER_SUITE_CCMP:
2765b9c547cSRui Paulo 			info->capa->enc |= WPA_DRIVER_CAPA_ENC_CCMP;
2775b9c547cSRui Paulo 			break;
27885732ac8SCy Schubert 		case RSN_CIPHER_SUITE_GCMP:
2795b9c547cSRui Paulo 			info->capa->enc |= WPA_DRIVER_CAPA_ENC_GCMP;
2805b9c547cSRui Paulo 			break;
28185732ac8SCy Schubert 		case RSN_CIPHER_SUITE_TKIP:
2825b9c547cSRui Paulo 			info->capa->enc |= WPA_DRIVER_CAPA_ENC_TKIP;
2835b9c547cSRui Paulo 			break;
28485732ac8SCy Schubert 		case RSN_CIPHER_SUITE_WEP104:
2855b9c547cSRui Paulo 			info->capa->enc |= WPA_DRIVER_CAPA_ENC_WEP104;
2865b9c547cSRui Paulo 			break;
28785732ac8SCy Schubert 		case RSN_CIPHER_SUITE_WEP40:
2885b9c547cSRui Paulo 			info->capa->enc |= WPA_DRIVER_CAPA_ENC_WEP40;
2895b9c547cSRui Paulo 			break;
29085732ac8SCy Schubert 		case RSN_CIPHER_SUITE_AES_128_CMAC:
2915b9c547cSRui Paulo 			info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP;
2925b9c547cSRui Paulo 			break;
29385732ac8SCy Schubert 		case RSN_CIPHER_SUITE_BIP_GMAC_128:
2945b9c547cSRui Paulo 			info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP_GMAC_128;
2955b9c547cSRui Paulo 			break;
29685732ac8SCy Schubert 		case RSN_CIPHER_SUITE_BIP_GMAC_256:
2975b9c547cSRui Paulo 			info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP_GMAC_256;
2985b9c547cSRui Paulo 			break;
29985732ac8SCy Schubert 		case RSN_CIPHER_SUITE_BIP_CMAC_256:
3005b9c547cSRui Paulo 			info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP_CMAC_256;
3015b9c547cSRui Paulo 			break;
30285732ac8SCy Schubert 		case RSN_CIPHER_SUITE_NO_GROUP_ADDRESSED:
3035b9c547cSRui Paulo 			info->capa->enc |= WPA_DRIVER_CAPA_ENC_GTK_NOT_USED;
3045b9c547cSRui Paulo 			break;
3055b9c547cSRui Paulo 		}
3065b9c547cSRui Paulo 	}
3075b9c547cSRui Paulo }
3085b9c547cSRui Paulo 
3095b9c547cSRui Paulo 
3105b9c547cSRui Paulo static void wiphy_info_max_roc(struct wpa_driver_capa *capa,
3115b9c547cSRui Paulo 			       struct nlattr *tb)
3125b9c547cSRui Paulo {
3135b9c547cSRui Paulo 	if (tb)
3145b9c547cSRui Paulo 		capa->max_remain_on_chan = nla_get_u32(tb);
3155b9c547cSRui Paulo }
3165b9c547cSRui Paulo 
3175b9c547cSRui Paulo 
3185b9c547cSRui Paulo static void wiphy_info_tdls(struct wpa_driver_capa *capa, struct nlattr *tdls,
3195b9c547cSRui Paulo 			    struct nlattr *ext_setup)
3205b9c547cSRui Paulo {
3215b9c547cSRui Paulo 	if (tdls == NULL)
3225b9c547cSRui Paulo 		return;
3235b9c547cSRui Paulo 
3245b9c547cSRui Paulo 	wpa_printf(MSG_DEBUG, "nl80211: TDLS supported");
3255b9c547cSRui Paulo 	capa->flags |= WPA_DRIVER_FLAGS_TDLS_SUPPORT;
3265b9c547cSRui Paulo 
3275b9c547cSRui Paulo 	if (ext_setup) {
3285b9c547cSRui Paulo 		wpa_printf(MSG_DEBUG, "nl80211: TDLS external setup");
3295b9c547cSRui Paulo 		capa->flags |= WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP;
3305b9c547cSRui Paulo 	}
3315b9c547cSRui Paulo }
3325b9c547cSRui Paulo 
3335b9c547cSRui Paulo 
334325151a3SRui Paulo static int ext_feature_isset(const u8 *ext_features, int ext_features_len,
335325151a3SRui Paulo 			     enum nl80211_ext_feature_index ftidx)
336325151a3SRui Paulo {
337325151a3SRui Paulo 	u8 ft_byte;
338325151a3SRui Paulo 
339325151a3SRui Paulo 	if ((int) ftidx / 8 >= ext_features_len)
340325151a3SRui Paulo 		return 0;
341325151a3SRui Paulo 
342325151a3SRui Paulo 	ft_byte = ext_features[ftidx / 8];
343325151a3SRui Paulo 	return (ft_byte & BIT(ftidx % 8)) != 0;
344325151a3SRui Paulo }
345325151a3SRui Paulo 
346325151a3SRui Paulo 
347325151a3SRui Paulo static void wiphy_info_ext_feature_flags(struct wiphy_info_data *info,
348325151a3SRui Paulo 					 struct nlattr *tb)
349325151a3SRui Paulo {
350325151a3SRui Paulo 	struct wpa_driver_capa *capa = info->capa;
351780fb4a2SCy Schubert 	u8 *ext_features;
352780fb4a2SCy Schubert 	int len;
353325151a3SRui Paulo 
354325151a3SRui Paulo 	if (tb == NULL)
355325151a3SRui Paulo 		return;
356325151a3SRui Paulo 
357780fb4a2SCy Schubert 	ext_features = nla_data(tb);
358780fb4a2SCy Schubert 	len = nla_len(tb);
359780fb4a2SCy Schubert 
360780fb4a2SCy Schubert 	if (ext_feature_isset(ext_features, len, NL80211_EXT_FEATURE_VHT_IBSS))
361325151a3SRui Paulo 		capa->flags |= WPA_DRIVER_FLAGS_VHT_IBSS;
362780fb4a2SCy Schubert 
363780fb4a2SCy Schubert 	if (ext_feature_isset(ext_features, len, NL80211_EXT_FEATURE_RRM))
364780fb4a2SCy Schubert 		capa->rrm_flags |= WPA_DRIVER_FLAGS_SUPPORT_RRM;
36585732ac8SCy Schubert 
36685732ac8SCy Schubert 	if (ext_feature_isset(ext_features, len, NL80211_EXT_FEATURE_FILS_STA))
36785732ac8SCy Schubert 		capa->flags |= WPA_DRIVER_FLAGS_SUPPORT_FILS;
36885732ac8SCy Schubert 
36985732ac8SCy Schubert 	if (ext_feature_isset(ext_features, len,
37085732ac8SCy Schubert 			      NL80211_EXT_FEATURE_BEACON_RATE_LEGACY))
37185732ac8SCy Schubert 		capa->flags |= WPA_DRIVER_FLAGS_BEACON_RATE_LEGACY;
37285732ac8SCy Schubert 
37385732ac8SCy Schubert 	if (ext_feature_isset(ext_features, len,
37485732ac8SCy Schubert 			      NL80211_EXT_FEATURE_BEACON_RATE_HT))
37585732ac8SCy Schubert 		capa->flags |= WPA_DRIVER_FLAGS_BEACON_RATE_HT;
37685732ac8SCy Schubert 
37785732ac8SCy Schubert 	if (ext_feature_isset(ext_features, len,
37885732ac8SCy Schubert 			      NL80211_EXT_FEATURE_BEACON_RATE_VHT))
37985732ac8SCy Schubert 		capa->flags |= WPA_DRIVER_FLAGS_BEACON_RATE_VHT;
38085732ac8SCy Schubert 
38185732ac8SCy Schubert 	if (ext_feature_isset(ext_features, len,
38285732ac8SCy Schubert 			      NL80211_EXT_FEATURE_SET_SCAN_DWELL))
38385732ac8SCy Schubert 		capa->rrm_flags |= WPA_DRIVER_FLAGS_SUPPORT_SET_SCAN_DWELL;
38485732ac8SCy Schubert 
38585732ac8SCy Schubert 	if (ext_feature_isset(ext_features, len,
38685732ac8SCy Schubert 			      NL80211_EXT_FEATURE_SCAN_START_TIME) &&
38785732ac8SCy Schubert 	    ext_feature_isset(ext_features, len,
38885732ac8SCy Schubert 			      NL80211_EXT_FEATURE_BSS_PARENT_TSF) &&
38985732ac8SCy Schubert 	    ext_feature_isset(ext_features, len,
39085732ac8SCy Schubert 			      NL80211_EXT_FEATURE_SET_SCAN_DWELL))
39185732ac8SCy Schubert 		capa->rrm_flags |= WPA_DRIVER_FLAGS_SUPPORT_BEACON_REPORT;
39285732ac8SCy Schubert 	if (ext_feature_isset(ext_features, len,
39385732ac8SCy Schubert 			      NL80211_EXT_FEATURE_MGMT_TX_RANDOM_TA))
39485732ac8SCy Schubert 		capa->flags |= WPA_DRIVER_FLAGS_MGMT_TX_RANDOM_TA;
39585732ac8SCy Schubert 	if (ext_feature_isset(ext_features, len,
39685732ac8SCy Schubert 			      NL80211_EXT_FEATURE_MGMT_TX_RANDOM_TA_CONNECTED))
39785732ac8SCy Schubert 		capa->flags |= WPA_DRIVER_FLAGS_MGMT_TX_RANDOM_TA_CONNECTED;
39885732ac8SCy Schubert 	if (ext_feature_isset(ext_features, len,
39985732ac8SCy Schubert 			      NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI))
40085732ac8SCy Schubert 		capa->flags |= WPA_DRIVER_FLAGS_SCHED_SCAN_RELATIVE_RSSI;
40185732ac8SCy Schubert 	if (ext_feature_isset(ext_features, len,
40285732ac8SCy Schubert 			      NL80211_EXT_FEATURE_FILS_SK_OFFLOAD))
40385732ac8SCy Schubert 		capa->flags |= WPA_DRIVER_FLAGS_FILS_SK_OFFLOAD;
40485732ac8SCy Schubert 
40585732ac8SCy Schubert 	if (ext_feature_isset(ext_features, len,
406*4bc52338SCy Schubert 			      NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK))
407*4bc52338SCy Schubert 		capa->flags |= WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK;
408*4bc52338SCy Schubert 	if (ext_feature_isset(ext_features, len,
40985732ac8SCy Schubert 			      NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
410*4bc52338SCy Schubert 		capa->flags |= WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X;
41185732ac8SCy Schubert 
41285732ac8SCy Schubert 	if (ext_feature_isset(ext_features, len,
41385732ac8SCy Schubert 			      NL80211_EXT_FEATURE_MFP_OPTIONAL))
41485732ac8SCy Schubert 		capa->flags |= WPA_DRIVER_FLAGS_MFP_OPTIONAL;
41585732ac8SCy Schubert 
41685732ac8SCy Schubert 	if (ext_feature_isset(ext_features, len,
41785732ac8SCy Schubert 			      NL80211_EXT_FEATURE_DFS_OFFLOAD))
41885732ac8SCy Schubert 		capa->flags |= WPA_DRIVER_FLAGS_DFS_OFFLOAD;
41985732ac8SCy Schubert 
42085732ac8SCy Schubert #ifdef CONFIG_MBO
42185732ac8SCy Schubert 	if (ext_feature_isset(ext_features, len,
42285732ac8SCy Schubert 			      NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME) &&
42385732ac8SCy Schubert 	    ext_feature_isset(ext_features, len,
42485732ac8SCy Schubert 			      NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP) &&
42585732ac8SCy Schubert 	    ext_feature_isset(ext_features, len,
42685732ac8SCy Schubert 			      NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE) &&
42785732ac8SCy Schubert 	    ext_feature_isset(
42885732ac8SCy Schubert 		    ext_features, len,
42985732ac8SCy Schubert 		    NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION))
43085732ac8SCy Schubert 		capa->flags |= WPA_DRIVER_FLAGS_OCE_STA;
43185732ac8SCy Schubert #endif /* CONFIG_MBO */
432*4bc52338SCy Schubert 
433*4bc52338SCy Schubert 	if (ext_feature_isset(ext_features, len,
434*4bc52338SCy Schubert 			      NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER))
435*4bc52338SCy Schubert 		capa->flags |= WPA_DRIVER_FLAGS_FTM_RESPONDER;
436325151a3SRui Paulo }
437325151a3SRui Paulo 
438325151a3SRui Paulo 
4395b9c547cSRui Paulo static void wiphy_info_feature_flags(struct wiphy_info_data *info,
4405b9c547cSRui Paulo 				     struct nlattr *tb)
4415b9c547cSRui Paulo {
4425b9c547cSRui Paulo 	u32 flags;
4435b9c547cSRui Paulo 	struct wpa_driver_capa *capa = info->capa;
4445b9c547cSRui Paulo 
4455b9c547cSRui Paulo 	if (tb == NULL)
4465b9c547cSRui Paulo 		return;
4475b9c547cSRui Paulo 
4485b9c547cSRui Paulo 	flags = nla_get_u32(tb);
4495b9c547cSRui Paulo 
4505b9c547cSRui Paulo 	if (flags & NL80211_FEATURE_SK_TX_STATUS)
4515b9c547cSRui Paulo 		info->data_tx_status = 1;
4525b9c547cSRui Paulo 
4535b9c547cSRui Paulo 	if (flags & NL80211_FEATURE_INACTIVITY_TIMER)
4545b9c547cSRui Paulo 		capa->flags |= WPA_DRIVER_FLAGS_INACTIVITY_TIMER;
4555b9c547cSRui Paulo 
4565b9c547cSRui Paulo 	if (flags & NL80211_FEATURE_SAE)
4575b9c547cSRui Paulo 		capa->flags |= WPA_DRIVER_FLAGS_SAE;
4585b9c547cSRui Paulo 
4595b9c547cSRui Paulo 	if (flags & NL80211_FEATURE_NEED_OBSS_SCAN)
4605b9c547cSRui Paulo 		capa->flags |= WPA_DRIVER_FLAGS_OBSS_SCAN;
4615b9c547cSRui Paulo 
4625b9c547cSRui Paulo 	if (flags & NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)
4635b9c547cSRui Paulo 		capa->flags |= WPA_DRIVER_FLAGS_HT_2040_COEX;
4645b9c547cSRui Paulo 
4655b9c547cSRui Paulo 	if (flags & NL80211_FEATURE_TDLS_CHANNEL_SWITCH) {
4665b9c547cSRui Paulo 		wpa_printf(MSG_DEBUG, "nl80211: TDLS channel switch");
4675b9c547cSRui Paulo 		capa->flags |= WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH;
4685b9c547cSRui Paulo 	}
4695b9c547cSRui Paulo 
4705b9c547cSRui Paulo 	if (flags & NL80211_FEATURE_P2P_GO_CTWIN)
4715b9c547cSRui Paulo 		info->p2p_go_ctwindow_supported = 1;
4725b9c547cSRui Paulo 
4735b9c547cSRui Paulo 	if (flags & NL80211_FEATURE_LOW_PRIORITY_SCAN)
4745b9c547cSRui Paulo 		info->have_low_prio_scan = 1;
4755b9c547cSRui Paulo 
4765b9c547cSRui Paulo 	if (flags & NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)
4775b9c547cSRui Paulo 		info->mac_addr_rand_scan_supported = 1;
4785b9c547cSRui Paulo 
4795b9c547cSRui Paulo 	if (flags & NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR)
4805b9c547cSRui Paulo 		info->mac_addr_rand_sched_scan_supported = 1;
4815b9c547cSRui Paulo 
4825b9c547cSRui Paulo 	if (flags & NL80211_FEATURE_STATIC_SMPS)
4835b9c547cSRui Paulo 		capa->smps_modes |= WPA_DRIVER_SMPS_MODE_STATIC;
4845b9c547cSRui Paulo 
4855b9c547cSRui Paulo 	if (flags & NL80211_FEATURE_DYNAMIC_SMPS)
4865b9c547cSRui Paulo 		capa->smps_modes |= WPA_DRIVER_SMPS_MODE_DYNAMIC;
4875b9c547cSRui Paulo 
4885b9c547cSRui Paulo 	if (flags & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
4895b9c547cSRui Paulo 		info->wmm_ac_supported = 1;
4905b9c547cSRui Paulo 
4915b9c547cSRui Paulo 	if (flags & NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES)
4925b9c547cSRui Paulo 		capa->rrm_flags |= WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES;
4935b9c547cSRui Paulo 
4945b9c547cSRui Paulo 	if (flags & NL80211_FEATURE_WFA_TPC_IE_IN_PROBES)
4955b9c547cSRui Paulo 		capa->rrm_flags |= WPA_DRIVER_FLAGS_WFA_TPC_IE_IN_PROBES;
4965b9c547cSRui Paulo 
4975b9c547cSRui Paulo 	if (flags & NL80211_FEATURE_QUIET)
4985b9c547cSRui Paulo 		capa->rrm_flags |= WPA_DRIVER_FLAGS_QUIET;
4995b9c547cSRui Paulo 
5005b9c547cSRui Paulo 	if (flags & NL80211_FEATURE_TX_POWER_INSERTION)
5015b9c547cSRui Paulo 		capa->rrm_flags |= WPA_DRIVER_FLAGS_TX_POWER_INSERTION;
5025b9c547cSRui Paulo 
5035b9c547cSRui Paulo 	if (flags & NL80211_FEATURE_HT_IBSS)
5045b9c547cSRui Paulo 		capa->flags |= WPA_DRIVER_FLAGS_HT_IBSS;
505780fb4a2SCy Schubert 
506780fb4a2SCy Schubert 	if (flags & NL80211_FEATURE_FULL_AP_CLIENT_STATE)
507780fb4a2SCy Schubert 		capa->flags |= WPA_DRIVER_FLAGS_FULL_AP_CLIENT_STATE;
5085b9c547cSRui Paulo }
5095b9c547cSRui Paulo 
5105b9c547cSRui Paulo 
5115b9c547cSRui Paulo static void wiphy_info_probe_resp_offload(struct wpa_driver_capa *capa,
5125b9c547cSRui Paulo 					  struct nlattr *tb)
5135b9c547cSRui Paulo {
5145b9c547cSRui Paulo 	u32 protocols;
5155b9c547cSRui Paulo 
5165b9c547cSRui Paulo 	if (tb == NULL)
5175b9c547cSRui Paulo 		return;
5185b9c547cSRui Paulo 
5195b9c547cSRui Paulo 	protocols = nla_get_u32(tb);
5205b9c547cSRui Paulo 	wpa_printf(MSG_DEBUG, "nl80211: Supports Probe Response offload in AP "
5215b9c547cSRui Paulo 		   "mode");
5225b9c547cSRui Paulo 	capa->flags |= WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD;
5235b9c547cSRui Paulo 	capa->probe_resp_offloads = probe_resp_offload_support(protocols);
5245b9c547cSRui Paulo }
5255b9c547cSRui Paulo 
5265b9c547cSRui Paulo 
5275b9c547cSRui Paulo static void wiphy_info_wowlan_triggers(struct wpa_driver_capa *capa,
5285b9c547cSRui Paulo 				       struct nlattr *tb)
5295b9c547cSRui Paulo {
5305b9c547cSRui Paulo 	struct nlattr *triggers[MAX_NL80211_WOWLAN_TRIG + 1];
5315b9c547cSRui Paulo 
5325b9c547cSRui Paulo 	if (tb == NULL)
5335b9c547cSRui Paulo 		return;
5345b9c547cSRui Paulo 
5355b9c547cSRui Paulo 	if (nla_parse_nested(triggers, MAX_NL80211_WOWLAN_TRIG,
5365b9c547cSRui Paulo 			     tb, NULL))
5375b9c547cSRui Paulo 		return;
5385b9c547cSRui Paulo 
5395b9c547cSRui Paulo 	if (triggers[NL80211_WOWLAN_TRIG_ANY])
5405b9c547cSRui Paulo 		capa->wowlan_triggers.any = 1;
5415b9c547cSRui Paulo 	if (triggers[NL80211_WOWLAN_TRIG_DISCONNECT])
5425b9c547cSRui Paulo 		capa->wowlan_triggers.disconnect = 1;
5435b9c547cSRui Paulo 	if (triggers[NL80211_WOWLAN_TRIG_MAGIC_PKT])
5445b9c547cSRui Paulo 		capa->wowlan_triggers.magic_pkt = 1;
5455b9c547cSRui Paulo 	if (triggers[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE])
5465b9c547cSRui Paulo 		capa->wowlan_triggers.gtk_rekey_failure = 1;
5475b9c547cSRui Paulo 	if (triggers[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST])
5485b9c547cSRui Paulo 		capa->wowlan_triggers.eap_identity_req = 1;
5495b9c547cSRui Paulo 	if (triggers[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE])
5505b9c547cSRui Paulo 		capa->wowlan_triggers.four_way_handshake = 1;
5515b9c547cSRui Paulo 	if (triggers[NL80211_WOWLAN_TRIG_RFKILL_RELEASE])
5525b9c547cSRui Paulo 		capa->wowlan_triggers.rfkill_release = 1;
5535b9c547cSRui Paulo }
5545b9c547cSRui Paulo 
5555b9c547cSRui Paulo 
556780fb4a2SCy Schubert static void wiphy_info_extended_capab(struct wpa_driver_nl80211_data *drv,
557780fb4a2SCy Schubert 				      struct nlattr *tb)
558780fb4a2SCy Schubert {
559780fb4a2SCy Schubert 	int rem = 0, i;
560780fb4a2SCy Schubert 	struct nlattr *tb1[NL80211_ATTR_MAX + 1], *attr;
561780fb4a2SCy Schubert 
562780fb4a2SCy Schubert 	if (!tb || drv->num_iface_ext_capa == NL80211_IFTYPE_MAX)
563780fb4a2SCy Schubert 		return;
564780fb4a2SCy Schubert 
565780fb4a2SCy Schubert 	nla_for_each_nested(attr, tb, rem) {
566780fb4a2SCy Schubert 		unsigned int len;
567780fb4a2SCy Schubert 		struct drv_nl80211_ext_capa *capa;
568780fb4a2SCy Schubert 
569780fb4a2SCy Schubert 		nla_parse(tb1, NL80211_ATTR_MAX, nla_data(attr),
570780fb4a2SCy Schubert 			  nla_len(attr), NULL);
571780fb4a2SCy Schubert 
572780fb4a2SCy Schubert 		if (!tb1[NL80211_ATTR_IFTYPE] ||
573780fb4a2SCy Schubert 		    !tb1[NL80211_ATTR_EXT_CAPA] ||
574780fb4a2SCy Schubert 		    !tb1[NL80211_ATTR_EXT_CAPA_MASK])
575780fb4a2SCy Schubert 			continue;
576780fb4a2SCy Schubert 
577780fb4a2SCy Schubert 		capa = &drv->iface_ext_capa[drv->num_iface_ext_capa];
578780fb4a2SCy Schubert 		capa->iftype = nla_get_u32(tb1[NL80211_ATTR_IFTYPE]);
579780fb4a2SCy Schubert 		wpa_printf(MSG_DEBUG,
580780fb4a2SCy Schubert 			   "nl80211: Driver-advertised extended capabilities for interface type %s",
581780fb4a2SCy Schubert 			   nl80211_iftype_str(capa->iftype));
582780fb4a2SCy Schubert 
583780fb4a2SCy Schubert 		len = nla_len(tb1[NL80211_ATTR_EXT_CAPA]);
58485732ac8SCy Schubert 		capa->ext_capa = os_memdup(nla_data(tb1[NL80211_ATTR_EXT_CAPA]),
58585732ac8SCy Schubert 					   len);
586780fb4a2SCy Schubert 		if (!capa->ext_capa)
587780fb4a2SCy Schubert 			goto err;
588780fb4a2SCy Schubert 
589780fb4a2SCy Schubert 		capa->ext_capa_len = len;
590780fb4a2SCy Schubert 		wpa_hexdump(MSG_DEBUG, "nl80211: Extended capabilities",
591780fb4a2SCy Schubert 			    capa->ext_capa, capa->ext_capa_len);
592780fb4a2SCy Schubert 
593780fb4a2SCy Schubert 		len = nla_len(tb1[NL80211_ATTR_EXT_CAPA_MASK]);
59485732ac8SCy Schubert 		capa->ext_capa_mask =
59585732ac8SCy Schubert 			os_memdup(nla_data(tb1[NL80211_ATTR_EXT_CAPA_MASK]),
59685732ac8SCy Schubert 				  len);
597780fb4a2SCy Schubert 		if (!capa->ext_capa_mask)
598780fb4a2SCy Schubert 			goto err;
599780fb4a2SCy Schubert 
600780fb4a2SCy Schubert 		wpa_hexdump(MSG_DEBUG, "nl80211: Extended capabilities mask",
601780fb4a2SCy Schubert 			    capa->ext_capa_mask, capa->ext_capa_len);
602780fb4a2SCy Schubert 
603780fb4a2SCy Schubert 		drv->num_iface_ext_capa++;
604780fb4a2SCy Schubert 		if (drv->num_iface_ext_capa == NL80211_IFTYPE_MAX)
605780fb4a2SCy Schubert 			break;
606780fb4a2SCy Schubert 	}
607780fb4a2SCy Schubert 
608780fb4a2SCy Schubert 	return;
609780fb4a2SCy Schubert 
610780fb4a2SCy Schubert err:
611780fb4a2SCy Schubert 	/* Cleanup allocated memory on error */
612780fb4a2SCy Schubert 	for (i = 0; i < NL80211_IFTYPE_MAX; i++) {
613780fb4a2SCy Schubert 		os_free(drv->iface_ext_capa[i].ext_capa);
614780fb4a2SCy Schubert 		drv->iface_ext_capa[i].ext_capa = NULL;
615780fb4a2SCy Schubert 		os_free(drv->iface_ext_capa[i].ext_capa_mask);
616780fb4a2SCy Schubert 		drv->iface_ext_capa[i].ext_capa_mask = NULL;
617780fb4a2SCy Schubert 		drv->iface_ext_capa[i].ext_capa_len = 0;
618780fb4a2SCy Schubert 	}
619780fb4a2SCy Schubert 	drv->num_iface_ext_capa = 0;
620780fb4a2SCy Schubert }
621780fb4a2SCy Schubert 
622780fb4a2SCy Schubert 
6235b9c547cSRui Paulo static int wiphy_info_handler(struct nl_msg *msg, void *arg)
6245b9c547cSRui Paulo {
6255b9c547cSRui Paulo 	struct nlattr *tb[NL80211_ATTR_MAX + 1];
6265b9c547cSRui Paulo 	struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
6275b9c547cSRui Paulo 	struct wiphy_info_data *info = arg;
6285b9c547cSRui Paulo 	struct wpa_driver_capa *capa = info->capa;
6295b9c547cSRui Paulo 	struct wpa_driver_nl80211_data *drv = info->drv;
6305b9c547cSRui Paulo 
6315b9c547cSRui Paulo 	nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
6325b9c547cSRui Paulo 		  genlmsg_attrlen(gnlh, 0), NULL);
6335b9c547cSRui Paulo 
634780fb4a2SCy Schubert 	if (tb[NL80211_ATTR_WIPHY])
635780fb4a2SCy Schubert 		drv->wiphy_idx = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
636780fb4a2SCy Schubert 
6375b9c547cSRui Paulo 	if (tb[NL80211_ATTR_WIPHY_NAME])
6385b9c547cSRui Paulo 		os_strlcpy(drv->phyname,
6395b9c547cSRui Paulo 			   nla_get_string(tb[NL80211_ATTR_WIPHY_NAME]),
6405b9c547cSRui Paulo 			   sizeof(drv->phyname));
6415b9c547cSRui Paulo 	if (tb[NL80211_ATTR_MAX_NUM_SCAN_SSIDS])
6425b9c547cSRui Paulo 		capa->max_scan_ssids =
6435b9c547cSRui Paulo 			nla_get_u8(tb[NL80211_ATTR_MAX_NUM_SCAN_SSIDS]);
6445b9c547cSRui Paulo 
6455b9c547cSRui Paulo 	if (tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS])
6465b9c547cSRui Paulo 		capa->max_sched_scan_ssids =
6475b9c547cSRui Paulo 			nla_get_u8(tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS]);
6485b9c547cSRui Paulo 
649780fb4a2SCy Schubert 	if (tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS] &&
650780fb4a2SCy Schubert 	    tb[NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL] &&
651780fb4a2SCy Schubert 	    tb[NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS]) {
652780fb4a2SCy Schubert 		capa->max_sched_scan_plans =
653780fb4a2SCy Schubert 			nla_get_u32(tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS]);
654780fb4a2SCy Schubert 
655780fb4a2SCy Schubert 		capa->max_sched_scan_plan_interval =
656780fb4a2SCy Schubert 			nla_get_u32(tb[NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL]);
657780fb4a2SCy Schubert 
658780fb4a2SCy Schubert 		capa->max_sched_scan_plan_iterations =
659780fb4a2SCy Schubert 			nla_get_u32(tb[NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS]);
660780fb4a2SCy Schubert 	}
661780fb4a2SCy Schubert 
6625b9c547cSRui Paulo 	if (tb[NL80211_ATTR_MAX_MATCH_SETS])
6635b9c547cSRui Paulo 		capa->max_match_sets =
6645b9c547cSRui Paulo 			nla_get_u8(tb[NL80211_ATTR_MAX_MATCH_SETS]);
6655b9c547cSRui Paulo 
6665b9c547cSRui Paulo 	if (tb[NL80211_ATTR_MAC_ACL_MAX])
6675b9c547cSRui Paulo 		capa->max_acl_mac_addrs =
6685b9c547cSRui Paulo 			nla_get_u8(tb[NL80211_ATTR_MAC_ACL_MAX]);
6695b9c547cSRui Paulo 
6705b9c547cSRui Paulo 	wiphy_info_supported_iftypes(info, tb[NL80211_ATTR_SUPPORTED_IFTYPES]);
6715b9c547cSRui Paulo 	wiphy_info_iface_comb(info, tb[NL80211_ATTR_INTERFACE_COMBINATIONS]);
6725b9c547cSRui Paulo 	wiphy_info_supp_cmds(info, tb[NL80211_ATTR_SUPPORTED_COMMANDS]);
6735b9c547cSRui Paulo 	wiphy_info_cipher_suites(info, tb[NL80211_ATTR_CIPHER_SUITES]);
6745b9c547cSRui Paulo 
6755b9c547cSRui Paulo 	if (tb[NL80211_ATTR_OFFCHANNEL_TX_OK]) {
6765b9c547cSRui Paulo 		wpa_printf(MSG_DEBUG, "nl80211: Using driver-based "
6775b9c547cSRui Paulo 			   "off-channel TX");
6785b9c547cSRui Paulo 		capa->flags |= WPA_DRIVER_FLAGS_OFFCHANNEL_TX;
6795b9c547cSRui Paulo 	}
6805b9c547cSRui Paulo 
6815b9c547cSRui Paulo 	if (tb[NL80211_ATTR_ROAM_SUPPORT]) {
6825b9c547cSRui Paulo 		wpa_printf(MSG_DEBUG, "nl80211: Using driver-based roaming");
6835b9c547cSRui Paulo 		capa->flags |= WPA_DRIVER_FLAGS_BSS_SELECTION;
6845b9c547cSRui Paulo 	}
6855b9c547cSRui Paulo 
6865b9c547cSRui Paulo 	wiphy_info_max_roc(capa,
6875b9c547cSRui Paulo 			   tb[NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION]);
6885b9c547cSRui Paulo 
6895b9c547cSRui Paulo 	if (tb[NL80211_ATTR_SUPPORT_AP_UAPSD])
6905b9c547cSRui Paulo 		capa->flags |= WPA_DRIVER_FLAGS_AP_UAPSD;
6915b9c547cSRui Paulo 
6925b9c547cSRui Paulo 	wiphy_info_tdls(capa, tb[NL80211_ATTR_TDLS_SUPPORT],
6935b9c547cSRui Paulo 			tb[NL80211_ATTR_TDLS_EXTERNAL_SETUP]);
6945b9c547cSRui Paulo 
6955b9c547cSRui Paulo 	if (tb[NL80211_ATTR_DEVICE_AP_SME])
6965b9c547cSRui Paulo 		info->device_ap_sme = 1;
6975b9c547cSRui Paulo 
6985b9c547cSRui Paulo 	wiphy_info_feature_flags(info, tb[NL80211_ATTR_FEATURE_FLAGS]);
699325151a3SRui Paulo 	wiphy_info_ext_feature_flags(info, tb[NL80211_ATTR_EXT_FEATURES]);
7005b9c547cSRui Paulo 	wiphy_info_probe_resp_offload(capa,
7015b9c547cSRui Paulo 				      tb[NL80211_ATTR_PROBE_RESP_OFFLOAD]);
7025b9c547cSRui Paulo 
7035b9c547cSRui Paulo 	if (tb[NL80211_ATTR_EXT_CAPA] && tb[NL80211_ATTR_EXT_CAPA_MASK] &&
7045b9c547cSRui Paulo 	    drv->extended_capa == NULL) {
7055b9c547cSRui Paulo 		drv->extended_capa =
7065b9c547cSRui Paulo 			os_malloc(nla_len(tb[NL80211_ATTR_EXT_CAPA]));
7075b9c547cSRui Paulo 		if (drv->extended_capa) {
7085b9c547cSRui Paulo 			os_memcpy(drv->extended_capa,
7095b9c547cSRui Paulo 				  nla_data(tb[NL80211_ATTR_EXT_CAPA]),
7105b9c547cSRui Paulo 				  nla_len(tb[NL80211_ATTR_EXT_CAPA]));
7115b9c547cSRui Paulo 			drv->extended_capa_len =
7125b9c547cSRui Paulo 				nla_len(tb[NL80211_ATTR_EXT_CAPA]);
713780fb4a2SCy Schubert 			wpa_hexdump(MSG_DEBUG,
714780fb4a2SCy Schubert 				    "nl80211: Driver-advertised extended capabilities (default)",
715780fb4a2SCy Schubert 				    drv->extended_capa, drv->extended_capa_len);
7165b9c547cSRui Paulo 		}
7175b9c547cSRui Paulo 		drv->extended_capa_mask =
7185b9c547cSRui Paulo 			os_malloc(nla_len(tb[NL80211_ATTR_EXT_CAPA_MASK]));
7195b9c547cSRui Paulo 		if (drv->extended_capa_mask) {
7205b9c547cSRui Paulo 			os_memcpy(drv->extended_capa_mask,
7215b9c547cSRui Paulo 				  nla_data(tb[NL80211_ATTR_EXT_CAPA_MASK]),
7225b9c547cSRui Paulo 				  nla_len(tb[NL80211_ATTR_EXT_CAPA_MASK]));
723780fb4a2SCy Schubert 			wpa_hexdump(MSG_DEBUG,
724780fb4a2SCy Schubert 				    "nl80211: Driver-advertised extended capabilities mask (default)",
725780fb4a2SCy Schubert 				    drv->extended_capa_mask,
726780fb4a2SCy Schubert 				    drv->extended_capa_len);
7275b9c547cSRui Paulo 		} else {
7285b9c547cSRui Paulo 			os_free(drv->extended_capa);
7295b9c547cSRui Paulo 			drv->extended_capa = NULL;
7305b9c547cSRui Paulo 			drv->extended_capa_len = 0;
7315b9c547cSRui Paulo 		}
7325b9c547cSRui Paulo 	}
7335b9c547cSRui Paulo 
734780fb4a2SCy Schubert 	wiphy_info_extended_capab(drv, tb[NL80211_ATTR_IFTYPE_EXT_CAPA]);
735780fb4a2SCy Schubert 
7365b9c547cSRui Paulo 	if (tb[NL80211_ATTR_VENDOR_DATA]) {
7375b9c547cSRui Paulo 		struct nlattr *nl;
7385b9c547cSRui Paulo 		int rem;
7395b9c547cSRui Paulo 
7405b9c547cSRui Paulo 		nla_for_each_nested(nl, tb[NL80211_ATTR_VENDOR_DATA], rem) {
7415b9c547cSRui Paulo 			struct nl80211_vendor_cmd_info *vinfo;
7425b9c547cSRui Paulo 			if (nla_len(nl) != sizeof(*vinfo)) {
7435b9c547cSRui Paulo 				wpa_printf(MSG_DEBUG, "nl80211: Unexpected vendor data info");
7445b9c547cSRui Paulo 				continue;
7455b9c547cSRui Paulo 			}
7465b9c547cSRui Paulo 			vinfo = nla_data(nl);
747325151a3SRui Paulo 			if (vinfo->vendor_id == OUI_QCA) {
7485b9c547cSRui Paulo 				switch (vinfo->subcmd) {
7495b9c547cSRui Paulo 				case QCA_NL80211_VENDOR_SUBCMD_TEST:
7505b9c547cSRui Paulo 					drv->vendor_cmd_test_avail = 1;
7515b9c547cSRui Paulo 					break;
752780fb4a2SCy Schubert #ifdef CONFIG_DRIVER_NL80211_QCA
7535b9c547cSRui Paulo 				case QCA_NL80211_VENDOR_SUBCMD_ROAMING:
7545b9c547cSRui Paulo 					drv->roaming_vendor_cmd_avail = 1;
7555b9c547cSRui Paulo 					break;
7565b9c547cSRui Paulo 				case QCA_NL80211_VENDOR_SUBCMD_DFS_CAPABILITY:
7575b9c547cSRui Paulo 					drv->dfs_vendor_cmd_avail = 1;
7585b9c547cSRui Paulo 					break;
7595b9c547cSRui Paulo 				case QCA_NL80211_VENDOR_SUBCMD_GET_FEATURES:
7605b9c547cSRui Paulo 					drv->get_features_vendor_cmd_avail = 1;
7615b9c547cSRui Paulo 					break;
762325151a3SRui Paulo 				case QCA_NL80211_VENDOR_SUBCMD_GET_PREFERRED_FREQ_LIST:
763325151a3SRui Paulo 					drv->get_pref_freq_list = 1;
7645b9c547cSRui Paulo 					break;
765325151a3SRui Paulo 				case QCA_NL80211_VENDOR_SUBCMD_SET_PROBABLE_OPER_CHANNEL:
766325151a3SRui Paulo 					drv->set_prob_oper_freq = 1;
767325151a3SRui Paulo 					break;
768325151a3SRui Paulo 				case QCA_NL80211_VENDOR_SUBCMD_DO_ACS:
769325151a3SRui Paulo 					drv->capa.flags |=
770325151a3SRui Paulo 						WPA_DRIVER_FLAGS_ACS_OFFLOAD;
771325151a3SRui Paulo 					break;
772325151a3SRui Paulo 				case QCA_NL80211_VENDOR_SUBCMD_SETBAND:
773325151a3SRui Paulo 					drv->setband_vendor_cmd_avail = 1;
774325151a3SRui Paulo 					break;
775780fb4a2SCy Schubert 				case QCA_NL80211_VENDOR_SUBCMD_TRIGGER_SCAN:
776780fb4a2SCy Schubert 					drv->scan_vendor_cmd_avail = 1;
777780fb4a2SCy Schubert 					break;
778780fb4a2SCy Schubert 				case QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION:
779780fb4a2SCy Schubert 					drv->set_wifi_conf_vendor_cmd_avail = 1;
780780fb4a2SCy Schubert 					break;
78185732ac8SCy Schubert 				case QCA_NL80211_VENDOR_SUBCMD_GET_HE_CAPABILITIES:
78285732ac8SCy Schubert 					drv->he_capab_vendor_cmd_avail = 1;
78385732ac8SCy Schubert 					break;
78485732ac8SCy Schubert 				case QCA_NL80211_VENDOR_SUBCMD_FETCH_BSS_TRANSITION_STATUS:
78585732ac8SCy Schubert 					drv->fetch_bss_trans_status = 1;
78685732ac8SCy Schubert 					break;
78785732ac8SCy Schubert 				case QCA_NL80211_VENDOR_SUBCMD_ROAM:
78885732ac8SCy Schubert 					drv->roam_vendor_cmd_avail = 1;
78985732ac8SCy Schubert 					break;
790*4bc52338SCy Schubert 				case QCA_NL80211_VENDOR_SUBCMD_GET_SUPPORTED_AKMS:
791*4bc52338SCy Schubert 					drv->get_supported_akm_suites_avail = 1;
792*4bc52338SCy Schubert 					break;
793780fb4a2SCy Schubert #endif /* CONFIG_DRIVER_NL80211_QCA */
794325151a3SRui Paulo 				}
7955b9c547cSRui Paulo 			}
7965b9c547cSRui Paulo 
7975b9c547cSRui Paulo 			wpa_printf(MSG_DEBUG, "nl80211: Supported vendor command: vendor_id=0x%x subcmd=%u",
7985b9c547cSRui Paulo 				   vinfo->vendor_id, vinfo->subcmd);
7995b9c547cSRui Paulo 		}
8005b9c547cSRui Paulo 	}
8015b9c547cSRui Paulo 
8025b9c547cSRui Paulo 	if (tb[NL80211_ATTR_VENDOR_EVENTS]) {
8035b9c547cSRui Paulo 		struct nlattr *nl;
8045b9c547cSRui Paulo 		int rem;
8055b9c547cSRui Paulo 
8065b9c547cSRui Paulo 		nla_for_each_nested(nl, tb[NL80211_ATTR_VENDOR_EVENTS], rem) {
8075b9c547cSRui Paulo 			struct nl80211_vendor_cmd_info *vinfo;
8085b9c547cSRui Paulo 			if (nla_len(nl) != sizeof(*vinfo)) {
8095b9c547cSRui Paulo 				wpa_printf(MSG_DEBUG, "nl80211: Unexpected vendor data info");
8105b9c547cSRui Paulo 				continue;
8115b9c547cSRui Paulo 			}
8125b9c547cSRui Paulo 			vinfo = nla_data(nl);
8135b9c547cSRui Paulo 			wpa_printf(MSG_DEBUG, "nl80211: Supported vendor event: vendor_id=0x%x subcmd=%u",
8145b9c547cSRui Paulo 				   vinfo->vendor_id, vinfo->subcmd);
8155b9c547cSRui Paulo 		}
8165b9c547cSRui Paulo 	}
8175b9c547cSRui Paulo 
8185b9c547cSRui Paulo 	wiphy_info_wowlan_triggers(capa,
8195b9c547cSRui Paulo 				   tb[NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED]);
8205b9c547cSRui Paulo 
8215b9c547cSRui Paulo 	if (tb[NL80211_ATTR_MAX_AP_ASSOC_STA])
8225b9c547cSRui Paulo 		capa->max_stations =
8235b9c547cSRui Paulo 			nla_get_u32(tb[NL80211_ATTR_MAX_AP_ASSOC_STA]);
8245b9c547cSRui Paulo 
825780fb4a2SCy Schubert 	if (tb[NL80211_ATTR_MAX_CSA_COUNTERS])
826780fb4a2SCy Schubert 		capa->max_csa_counters =
827780fb4a2SCy Schubert 			nla_get_u8(tb[NL80211_ATTR_MAX_CSA_COUNTERS]);
828780fb4a2SCy Schubert 
82985732ac8SCy Schubert 	if (tb[NL80211_ATTR_WIPHY_SELF_MANAGED_REG])
83085732ac8SCy Schubert 		capa->flags |= WPA_DRIVER_FLAGS_SELF_MANAGED_REGULATORY;
83185732ac8SCy Schubert 
8325b9c547cSRui Paulo 	return NL_SKIP;
8335b9c547cSRui Paulo }
8345b9c547cSRui Paulo 
8355b9c547cSRui Paulo 
8365b9c547cSRui Paulo static int wpa_driver_nl80211_get_info(struct wpa_driver_nl80211_data *drv,
8375b9c547cSRui Paulo 				       struct wiphy_info_data *info)
8385b9c547cSRui Paulo {
8395b9c547cSRui Paulo 	u32 feat;
8405b9c547cSRui Paulo 	struct nl_msg *msg;
8415b9c547cSRui Paulo 	int flags = 0;
8425b9c547cSRui Paulo 
8435b9c547cSRui Paulo 	os_memset(info, 0, sizeof(*info));
8445b9c547cSRui Paulo 	info->capa = &drv->capa;
8455b9c547cSRui Paulo 	info->drv = drv;
8465b9c547cSRui Paulo 
8475b9c547cSRui Paulo 	feat = get_nl80211_protocol_features(drv);
8485b9c547cSRui Paulo 	if (feat & NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)
8495b9c547cSRui Paulo 		flags = NLM_F_DUMP;
8505b9c547cSRui Paulo 	msg = nl80211_cmd_msg(drv->first_bss, flags, NL80211_CMD_GET_WIPHY);
8515b9c547cSRui Paulo 	if (!msg || nla_put_flag(msg, NL80211_ATTR_SPLIT_WIPHY_DUMP)) {
8525b9c547cSRui Paulo 		nlmsg_free(msg);
8535b9c547cSRui Paulo 		return -1;
8545b9c547cSRui Paulo 	}
8555b9c547cSRui Paulo 
8565b9c547cSRui Paulo 	if (send_and_recv_msgs(drv, msg, wiphy_info_handler, info))
8575b9c547cSRui Paulo 		return -1;
8585b9c547cSRui Paulo 
8595b9c547cSRui Paulo 	if (info->auth_supported)
8605b9c547cSRui Paulo 		drv->capa.flags |= WPA_DRIVER_FLAGS_SME;
8615b9c547cSRui Paulo 	else if (!info->connect_supported) {
8625b9c547cSRui Paulo 		wpa_printf(MSG_INFO, "nl80211: Driver does not support "
8635b9c547cSRui Paulo 			   "authentication/association or connect commands");
8645b9c547cSRui Paulo 		info->error = 1;
8655b9c547cSRui Paulo 	}
8665b9c547cSRui Paulo 
8675b9c547cSRui Paulo 	if (info->p2p_go_supported && info->p2p_client_supported)
8685b9c547cSRui Paulo 		drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CAPABLE;
8695b9c547cSRui Paulo 	if (info->p2p_concurrent) {
8705b9c547cSRui Paulo 		wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group "
8715b9c547cSRui Paulo 			   "interface (driver advertised support)");
8725b9c547cSRui Paulo 		drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT;
8735b9c547cSRui Paulo 		drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P;
8745b9c547cSRui Paulo 	}
8755b9c547cSRui Paulo 	if (info->num_multichan_concurrent > 1) {
8765b9c547cSRui Paulo 		wpa_printf(MSG_DEBUG, "nl80211: Enable multi-channel "
8775b9c547cSRui Paulo 			   "concurrent (driver advertised support)");
8785b9c547cSRui Paulo 		drv->capa.num_multichan_concurrent =
8795b9c547cSRui Paulo 			info->num_multichan_concurrent;
8805b9c547cSRui Paulo 	}
8815b9c547cSRui Paulo 	if (drv->capa.flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)
8825b9c547cSRui Paulo 		wpa_printf(MSG_DEBUG, "nl80211: use P2P_DEVICE support");
8835b9c547cSRui Paulo 
8845b9c547cSRui Paulo 	/* default to 5000 since early versions of mac80211 don't set it */
8855b9c547cSRui Paulo 	if (!drv->capa.max_remain_on_chan)
8865b9c547cSRui Paulo 		drv->capa.max_remain_on_chan = 5000;
8875b9c547cSRui Paulo 
8885b9c547cSRui Paulo 	drv->capa.wmm_ac_supported = info->wmm_ac_supported;
8895b9c547cSRui Paulo 
8905b9c547cSRui Paulo 	drv->capa.mac_addr_rand_sched_scan_supported =
8915b9c547cSRui Paulo 		info->mac_addr_rand_sched_scan_supported;
8925b9c547cSRui Paulo 	drv->capa.mac_addr_rand_scan_supported =
8935b9c547cSRui Paulo 		info->mac_addr_rand_scan_supported;
8945b9c547cSRui Paulo 
895780fb4a2SCy Schubert 	if (info->channel_switch_supported) {
896780fb4a2SCy Schubert 		drv->capa.flags |= WPA_DRIVER_FLAGS_AP_CSA;
897780fb4a2SCy Schubert 		if (!drv->capa.max_csa_counters)
898780fb4a2SCy Schubert 			drv->capa.max_csa_counters = 1;
899780fb4a2SCy Schubert 	}
900780fb4a2SCy Schubert 
901780fb4a2SCy Schubert 	if (!drv->capa.max_sched_scan_plans) {
902780fb4a2SCy Schubert 		drv->capa.max_sched_scan_plans = 1;
903780fb4a2SCy Schubert 		drv->capa.max_sched_scan_plan_interval = UINT32_MAX;
904780fb4a2SCy Schubert 		drv->capa.max_sched_scan_plan_iterations = 0;
905780fb4a2SCy Schubert 	}
906780fb4a2SCy Schubert 
9075b9c547cSRui Paulo 	return 0;
9085b9c547cSRui Paulo }
9095b9c547cSRui Paulo 
9105b9c547cSRui Paulo 
911780fb4a2SCy Schubert #ifdef CONFIG_DRIVER_NL80211_QCA
912780fb4a2SCy Schubert 
9135b9c547cSRui Paulo static int dfs_info_handler(struct nl_msg *msg, void *arg)
9145b9c547cSRui Paulo {
9155b9c547cSRui Paulo 	struct nlattr *tb[NL80211_ATTR_MAX + 1];
9165b9c547cSRui Paulo 	struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
9175b9c547cSRui Paulo 	int *dfs_capability_ptr = arg;
9185b9c547cSRui Paulo 
9195b9c547cSRui Paulo 	nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
9205b9c547cSRui Paulo 		  genlmsg_attrlen(gnlh, 0), NULL);
9215b9c547cSRui Paulo 
9225b9c547cSRui Paulo 	if (tb[NL80211_ATTR_VENDOR_DATA]) {
9235b9c547cSRui Paulo 		struct nlattr *nl_vend = tb[NL80211_ATTR_VENDOR_DATA];
9245b9c547cSRui Paulo 		struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1];
9255b9c547cSRui Paulo 
9265b9c547cSRui Paulo 		nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX,
9275b9c547cSRui Paulo 			  nla_data(nl_vend), nla_len(nl_vend), NULL);
9285b9c547cSRui Paulo 
9295b9c547cSRui Paulo 		if (tb_vendor[QCA_WLAN_VENDOR_ATTR_DFS]) {
9305b9c547cSRui Paulo 			u32 val;
9315b9c547cSRui Paulo 			val = nla_get_u32(tb_vendor[QCA_WLAN_VENDOR_ATTR_DFS]);
9325b9c547cSRui Paulo 			wpa_printf(MSG_DEBUG, "nl80211: DFS offload capability: %u",
9335b9c547cSRui Paulo 				   val);
9345b9c547cSRui Paulo 			*dfs_capability_ptr = val;
9355b9c547cSRui Paulo 		}
9365b9c547cSRui Paulo 	}
9375b9c547cSRui Paulo 
9385b9c547cSRui Paulo 	return NL_SKIP;
9395b9c547cSRui Paulo }
9405b9c547cSRui Paulo 
9415b9c547cSRui Paulo 
9425b9c547cSRui Paulo static void qca_nl80211_check_dfs_capa(struct wpa_driver_nl80211_data *drv)
9435b9c547cSRui Paulo {
9445b9c547cSRui Paulo 	struct nl_msg *msg;
9455b9c547cSRui Paulo 	int dfs_capability = 0;
9465b9c547cSRui Paulo 	int ret;
9475b9c547cSRui Paulo 
9485b9c547cSRui Paulo 	if (!drv->dfs_vendor_cmd_avail)
9495b9c547cSRui Paulo 		return;
9505b9c547cSRui Paulo 
9515b9c547cSRui Paulo 	if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
9525b9c547cSRui Paulo 	    nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9535b9c547cSRui Paulo 	    nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9545b9c547cSRui Paulo 			QCA_NL80211_VENDOR_SUBCMD_DFS_CAPABILITY)) {
9555b9c547cSRui Paulo 		nlmsg_free(msg);
9565b9c547cSRui Paulo 		return;
9575b9c547cSRui Paulo 	}
9585b9c547cSRui Paulo 
9595b9c547cSRui Paulo 	ret = send_and_recv_msgs(drv, msg, dfs_info_handler, &dfs_capability);
9605b9c547cSRui Paulo 	if (!ret && dfs_capability)
9615b9c547cSRui Paulo 		drv->capa.flags |= WPA_DRIVER_FLAGS_DFS_OFFLOAD;
9625b9c547cSRui Paulo }
9635b9c547cSRui Paulo 
9645b9c547cSRui Paulo 
965*4bc52338SCy Schubert static unsigned int get_akm_suites_info(struct nlattr *tb)
966*4bc52338SCy Schubert {
967*4bc52338SCy Schubert 	int i, num;
968*4bc52338SCy Schubert 	unsigned int key_mgmt = 0;
969*4bc52338SCy Schubert 	u32 *akms;
970*4bc52338SCy Schubert 
971*4bc52338SCy Schubert 	if (!tb)
972*4bc52338SCy Schubert 		return 0;
973*4bc52338SCy Schubert 
974*4bc52338SCy Schubert 	num = nla_len(tb) / sizeof(u32);
975*4bc52338SCy Schubert 	akms = nla_data(tb);
976*4bc52338SCy Schubert 	for (i = 0; i < num; i++) {
977*4bc52338SCy Schubert 		u32 a = akms[i];
978*4bc52338SCy Schubert 
979*4bc52338SCy Schubert 		wpa_printf(MSG_DEBUG,
980*4bc52338SCy Schubert 			   "nl80211: Supported AKM %02x-%02x-%02x:%u",
981*4bc52338SCy Schubert 			   a >> 24, (a >> 16) & 0xff,
982*4bc52338SCy Schubert 			   (a >> 8) & 0xff, a & 0xff);
983*4bc52338SCy Schubert 		switch (a) {
984*4bc52338SCy Schubert 		case RSN_AUTH_KEY_MGMT_UNSPEC_802_1X:
985*4bc52338SCy Schubert 			key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_WPA |
986*4bc52338SCy Schubert 				WPA_DRIVER_CAPA_KEY_MGMT_WPA2;
987*4bc52338SCy Schubert 			break;
988*4bc52338SCy Schubert 		case RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X:
989*4bc52338SCy Schubert 			key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
990*4bc52338SCy Schubert 				WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK;
991*4bc52338SCy Schubert 			break;
992*4bc52338SCy Schubert 		case RSN_AUTH_KEY_MGMT_FT_802_1X:
993*4bc52338SCy Schubert 			key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT;
994*4bc52338SCy Schubert 			break;
995*4bc52338SCy Schubert 		case RSN_AUTH_KEY_MGMT_FT_PSK:
996*4bc52338SCy Schubert 			key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK;
997*4bc52338SCy Schubert 			break;
998*4bc52338SCy Schubert 		case RSN_AUTH_KEY_MGMT_802_1X_SUITE_B:
999*4bc52338SCy Schubert 			key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B;
1000*4bc52338SCy Schubert 			break;
1001*4bc52338SCy Schubert 		case RSN_AUTH_KEY_MGMT_802_1X_SUITE_B_192:
1002*4bc52338SCy Schubert 			key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192;
1003*4bc52338SCy Schubert 			break;
1004*4bc52338SCy Schubert 		case RSN_AUTH_KEY_MGMT_OWE:
1005*4bc52338SCy Schubert 			key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_OWE;
1006*4bc52338SCy Schubert 			break;
1007*4bc52338SCy Schubert 		case RSN_AUTH_KEY_MGMT_DPP:
1008*4bc52338SCy Schubert 			key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_DPP;
1009*4bc52338SCy Schubert 			break;
1010*4bc52338SCy Schubert 		case RSN_AUTH_KEY_MGMT_FILS_SHA256:
1011*4bc52338SCy Schubert 			key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256;
1012*4bc52338SCy Schubert 			break;
1013*4bc52338SCy Schubert 		case RSN_AUTH_KEY_MGMT_FILS_SHA384:
1014*4bc52338SCy Schubert 			key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384;
1015*4bc52338SCy Schubert 			break;
1016*4bc52338SCy Schubert 		case RSN_AUTH_KEY_MGMT_FT_FILS_SHA256:
1017*4bc52338SCy Schubert 			key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA256;
1018*4bc52338SCy Schubert 			break;
1019*4bc52338SCy Schubert 		case RSN_AUTH_KEY_MGMT_FT_FILS_SHA384:
1020*4bc52338SCy Schubert 			key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA384;
1021*4bc52338SCy Schubert 			break;
1022*4bc52338SCy Schubert 		case RSN_AUTH_KEY_MGMT_SAE:
1023*4bc52338SCy Schubert 			key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_SAE;
1024*4bc52338SCy Schubert 			break;
1025*4bc52338SCy Schubert 		}
1026*4bc52338SCy Schubert 	}
1027*4bc52338SCy Schubert 
1028*4bc52338SCy Schubert 	return key_mgmt;
1029*4bc52338SCy Schubert }
1030*4bc52338SCy Schubert 
1031*4bc52338SCy Schubert 
1032*4bc52338SCy Schubert static int get_akm_suites_handler(struct nl_msg *msg, void *arg)
1033*4bc52338SCy Schubert {
1034*4bc52338SCy Schubert 	struct nlattr *tb[NL80211_ATTR_MAX + 1];
1035*4bc52338SCy Schubert 	struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1036*4bc52338SCy Schubert 	unsigned int *key_mgmt = arg;
1037*4bc52338SCy Schubert 
1038*4bc52338SCy Schubert 	nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1039*4bc52338SCy Schubert 		  genlmsg_attrlen(gnlh, 0), NULL);
1040*4bc52338SCy Schubert 
1041*4bc52338SCy Schubert 	if (tb[NL80211_ATTR_VENDOR_DATA]) {
1042*4bc52338SCy Schubert 		struct nlattr *nl_vend = tb[NL80211_ATTR_VENDOR_DATA];
1043*4bc52338SCy Schubert 		struct nlattr *tb_data[NL80211_ATTR_MAX + 1];
1044*4bc52338SCy Schubert 
1045*4bc52338SCy Schubert 		nla_parse(tb_data, NL80211_ATTR_MAX,
1046*4bc52338SCy Schubert 			  nla_data(nl_vend), nla_len(nl_vend), NULL);
1047*4bc52338SCy Schubert 
1048*4bc52338SCy Schubert 		*key_mgmt =
1049*4bc52338SCy Schubert 			get_akm_suites_info(tb_data[NL80211_ATTR_AKM_SUITES]);
1050*4bc52338SCy Schubert 	}
1051*4bc52338SCy Schubert 
1052*4bc52338SCy Schubert 	return NL_SKIP;
1053*4bc52338SCy Schubert }
1054*4bc52338SCy Schubert 
1055*4bc52338SCy Schubert 
1056*4bc52338SCy Schubert static int qca_nl80211_get_akm_suites(struct wpa_driver_nl80211_data *drv)
1057*4bc52338SCy Schubert {
1058*4bc52338SCy Schubert 	struct nl_msg *msg;
1059*4bc52338SCy Schubert 	unsigned int key_mgmt = 0;
1060*4bc52338SCy Schubert 	int ret;
1061*4bc52338SCy Schubert 
1062*4bc52338SCy Schubert 	if (!drv->get_supported_akm_suites_avail)
1063*4bc52338SCy Schubert 		return -1;
1064*4bc52338SCy Schubert 
1065*4bc52338SCy Schubert 	if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
1066*4bc52338SCy Schubert 	    nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
1067*4bc52338SCy Schubert 	    nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
1068*4bc52338SCy Schubert 			QCA_NL80211_VENDOR_SUBCMD_GET_SUPPORTED_AKMS)) {
1069*4bc52338SCy Schubert 		nlmsg_free(msg);
1070*4bc52338SCy Schubert 		return -1;
1071*4bc52338SCy Schubert 	}
1072*4bc52338SCy Schubert 
1073*4bc52338SCy Schubert 	ret = send_and_recv_msgs(drv, msg, get_akm_suites_handler, &key_mgmt);
1074*4bc52338SCy Schubert 	if (!ret) {
1075*4bc52338SCy Schubert 		wpa_printf(MSG_DEBUG,
1076*4bc52338SCy Schubert 			   "nl80211: Replace capa.key_mgmt based on driver advertised capabilities: 0x%x",
1077*4bc52338SCy Schubert 			   key_mgmt);
1078*4bc52338SCy Schubert 		drv->capa.key_mgmt = key_mgmt;
1079*4bc52338SCy Schubert 	}
1080*4bc52338SCy Schubert 
1081*4bc52338SCy Schubert 	return ret;
1082*4bc52338SCy Schubert }
1083*4bc52338SCy Schubert 
1084*4bc52338SCy Schubert 
108585732ac8SCy Schubert static int qca_nl80211_he_capab_handler(struct nl_msg *msg, void *arg)
108685732ac8SCy Schubert {
108785732ac8SCy Schubert 	struct nlattr *tb[NL80211_ATTR_MAX + 1];
108885732ac8SCy Schubert 	struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
108985732ac8SCy Schubert 	struct he_capabilities *he_capab = arg;
109085732ac8SCy Schubert 	struct nlattr *nl_vend;
109185732ac8SCy Schubert 	struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_HE_CAPABILITIES_MAX + 1];
109285732ac8SCy Schubert 	size_t len;
109385732ac8SCy Schubert 
109485732ac8SCy Schubert 	nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
109585732ac8SCy Schubert 		  genlmsg_attrlen(gnlh, 0), NULL);
109685732ac8SCy Schubert 
109785732ac8SCy Schubert 	if (!tb[NL80211_ATTR_VENDOR_DATA])
109885732ac8SCy Schubert 		return NL_SKIP;
109985732ac8SCy Schubert 
110085732ac8SCy Schubert 	nl_vend = tb[NL80211_ATTR_VENDOR_DATA];
110185732ac8SCy Schubert 	nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_HE_CAPABILITIES_MAX,
110285732ac8SCy Schubert 		  nla_data(nl_vend), nla_len(nl_vend), NULL);
110385732ac8SCy Schubert 
110485732ac8SCy Schubert 	if (tb_vendor[QCA_WLAN_VENDOR_ATTR_HE_SUPPORTED]) {
110585732ac8SCy Schubert 		u8 he_supported;
110685732ac8SCy Schubert 
110785732ac8SCy Schubert 		he_supported = nla_get_u8(
110885732ac8SCy Schubert 			tb_vendor[QCA_WLAN_VENDOR_ATTR_HE_SUPPORTED]);
110985732ac8SCy Schubert 		wpa_printf(MSG_DEBUG, "nl80211: HE capabilities supported: %u",
111085732ac8SCy Schubert 			   he_supported);
111185732ac8SCy Schubert 		he_capab->he_supported = he_supported;
111285732ac8SCy Schubert 		if (!he_supported)
111385732ac8SCy Schubert 			return NL_SKIP;
111485732ac8SCy Schubert 	}
111585732ac8SCy Schubert 
111685732ac8SCy Schubert 	if (tb_vendor[QCA_WLAN_VENDOR_ATTR_PHY_CAPAB]) {
111785732ac8SCy Schubert 		len = nla_len(tb_vendor[QCA_WLAN_VENDOR_ATTR_PHY_CAPAB]);
111885732ac8SCy Schubert 
111985732ac8SCy Schubert 		if (len > sizeof(he_capab->phy_cap))
112085732ac8SCy Schubert 			len = sizeof(he_capab->phy_cap);
112185732ac8SCy Schubert 		os_memcpy(he_capab->phy_cap,
112285732ac8SCy Schubert 			  nla_data(tb_vendor[QCA_WLAN_VENDOR_ATTR_PHY_CAPAB]),
112385732ac8SCy Schubert 			  len);
112485732ac8SCy Schubert 	}
112585732ac8SCy Schubert 
112685732ac8SCy Schubert 	if (tb_vendor[QCA_WLAN_VENDOR_ATTR_MAC_CAPAB])
112785732ac8SCy Schubert 		he_capab->mac_cap =
112885732ac8SCy Schubert 			nla_get_u32(tb_vendor[QCA_WLAN_VENDOR_ATTR_MAC_CAPAB]);
112985732ac8SCy Schubert 
113085732ac8SCy Schubert 	if (tb_vendor[QCA_WLAN_VENDOR_ATTR_HE_MCS])
113185732ac8SCy Schubert 		he_capab->mcs =
113285732ac8SCy Schubert 			nla_get_u32(tb_vendor[QCA_WLAN_VENDOR_ATTR_HE_MCS]);
113385732ac8SCy Schubert 
113485732ac8SCy Schubert 	if (tb_vendor[QCA_WLAN_VENDOR_ATTR_NUM_SS])
113585732ac8SCy Schubert 		he_capab->ppet.numss_m1 =
113685732ac8SCy Schubert 			nla_get_u32(tb_vendor[QCA_WLAN_VENDOR_ATTR_NUM_SS]);
113785732ac8SCy Schubert 
113885732ac8SCy Schubert 	if (tb_vendor[QCA_WLAN_VENDOR_ATTR_RU_IDX_MASK])
113985732ac8SCy Schubert 		he_capab->ppet.ru_count =
114085732ac8SCy Schubert 			nla_get_u32(tb_vendor[QCA_WLAN_VENDOR_ATTR_RU_IDX_MASK]);
114185732ac8SCy Schubert 
114285732ac8SCy Schubert 	if (tb_vendor[QCA_WLAN_VENDOR_ATTR_PPE_THRESHOLD]) {
114385732ac8SCy Schubert 		len = nla_len(tb_vendor[QCA_WLAN_VENDOR_ATTR_PPE_THRESHOLD]);
114485732ac8SCy Schubert 
114585732ac8SCy Schubert 		if (len > sizeof(he_capab->ppet.ppet16_ppet8_ru3_ru0))
114685732ac8SCy Schubert 			len = sizeof(he_capab->ppet.ppet16_ppet8_ru3_ru0);
114785732ac8SCy Schubert 		os_memcpy(he_capab->ppet.ppet16_ppet8_ru3_ru0,
114885732ac8SCy Schubert 			  nla_data(tb_vendor[QCA_WLAN_VENDOR_ATTR_PPE_THRESHOLD]),
114985732ac8SCy Schubert 			  len);
115085732ac8SCy Schubert 	}
115185732ac8SCy Schubert 
115285732ac8SCy Schubert 	return NL_SKIP;
115385732ac8SCy Schubert }
115485732ac8SCy Schubert 
115585732ac8SCy Schubert 
115685732ac8SCy Schubert static void qca_nl80211_check_he_capab(struct wpa_driver_nl80211_data *drv)
115785732ac8SCy Schubert {
115885732ac8SCy Schubert 	struct nl_msg *msg;
115985732ac8SCy Schubert 	int ret;
116085732ac8SCy Schubert 
116185732ac8SCy Schubert 	if (!drv->he_capab_vendor_cmd_avail)
116285732ac8SCy Schubert 		return;
116385732ac8SCy Schubert 
116485732ac8SCy Schubert 	if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
116585732ac8SCy Schubert 		nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
116685732ac8SCy Schubert 		nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
116785732ac8SCy Schubert 			    QCA_NL80211_VENDOR_SUBCMD_GET_HE_CAPABILITIES)) {
116885732ac8SCy Schubert 		nlmsg_free(msg);
116985732ac8SCy Schubert 		return;
117085732ac8SCy Schubert 	}
117185732ac8SCy Schubert 
117285732ac8SCy Schubert 	ret = send_and_recv_msgs(drv, msg, qca_nl80211_he_capab_handler,
117385732ac8SCy Schubert 				 &drv->he_capab);
117485732ac8SCy Schubert 	if (!ret && drv->he_capab.he_supported)
117585732ac8SCy Schubert 		drv->capa.flags |= WPA_DRIVER_FLAGS_HE_CAPABILITIES;
117685732ac8SCy Schubert }
117785732ac8SCy Schubert 
117885732ac8SCy Schubert 
11795b9c547cSRui Paulo struct features_info {
11805b9c547cSRui Paulo 	u8 *flags;
11815b9c547cSRui Paulo 	size_t flags_len;
1182325151a3SRui Paulo 	struct wpa_driver_capa *capa;
11835b9c547cSRui Paulo };
11845b9c547cSRui Paulo 
11855b9c547cSRui Paulo 
11865b9c547cSRui Paulo static int features_info_handler(struct nl_msg *msg, void *arg)
11875b9c547cSRui Paulo {
11885b9c547cSRui Paulo 	struct nlattr *tb[NL80211_ATTR_MAX + 1];
11895b9c547cSRui Paulo 	struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
11905b9c547cSRui Paulo 	struct features_info *info = arg;
11915b9c547cSRui Paulo 	struct nlattr *nl_vend, *attr;
11925b9c547cSRui Paulo 
11935b9c547cSRui Paulo 	nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
11945b9c547cSRui Paulo 		  genlmsg_attrlen(gnlh, 0), NULL);
11955b9c547cSRui Paulo 
11965b9c547cSRui Paulo 	nl_vend = tb[NL80211_ATTR_VENDOR_DATA];
11975b9c547cSRui Paulo 	if (nl_vend) {
11985b9c547cSRui Paulo 		struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1];
11995b9c547cSRui Paulo 
12005b9c547cSRui Paulo 		nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX,
12015b9c547cSRui Paulo 			  nla_data(nl_vend), nla_len(nl_vend), NULL);
12025b9c547cSRui Paulo 
12035b9c547cSRui Paulo 		attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_FEATURE_FLAGS];
12045b9c547cSRui Paulo 		if (attr) {
1205780fb4a2SCy Schubert 			int len = nla_len(attr);
1206780fb4a2SCy Schubert 			info->flags = os_malloc(len);
1207780fb4a2SCy Schubert 			if (info->flags != NULL) {
1208780fb4a2SCy Schubert 				os_memcpy(info->flags, nla_data(attr), len);
1209780fb4a2SCy Schubert 				info->flags_len = len;
1210780fb4a2SCy Schubert 			}
12115b9c547cSRui Paulo 		}
1212325151a3SRui Paulo 		attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_CONCURRENCY_CAPA];
1213325151a3SRui Paulo 		if (attr)
1214325151a3SRui Paulo 			info->capa->conc_capab = nla_get_u32(attr);
1215325151a3SRui Paulo 
1216325151a3SRui Paulo 		attr = tb_vendor[
1217325151a3SRui Paulo 			QCA_WLAN_VENDOR_ATTR_MAX_CONCURRENT_CHANNELS_2_4_BAND];
1218325151a3SRui Paulo 		if (attr)
1219325151a3SRui Paulo 			info->capa->max_conc_chan_2_4 = nla_get_u32(attr);
1220325151a3SRui Paulo 
1221325151a3SRui Paulo 		attr = tb_vendor[
1222325151a3SRui Paulo 			QCA_WLAN_VENDOR_ATTR_MAX_CONCURRENT_CHANNELS_5_0_BAND];
1223325151a3SRui Paulo 		if (attr)
1224325151a3SRui Paulo 			info->capa->max_conc_chan_5_0 = nla_get_u32(attr);
12255b9c547cSRui Paulo 	}
12265b9c547cSRui Paulo 
12275b9c547cSRui Paulo 	return NL_SKIP;
12285b9c547cSRui Paulo }
12295b9c547cSRui Paulo 
12305b9c547cSRui Paulo 
12315b9c547cSRui Paulo static int check_feature(enum qca_wlan_vendor_features feature,
12325b9c547cSRui Paulo 			 struct features_info *info)
12335b9c547cSRui Paulo {
12345b9c547cSRui Paulo 	size_t idx = feature / 8;
12355b9c547cSRui Paulo 
12365b9c547cSRui Paulo 	return (idx < info->flags_len) &&
12375b9c547cSRui Paulo 		(info->flags[idx] & BIT(feature % 8));
12385b9c547cSRui Paulo }
12395b9c547cSRui Paulo 
12405b9c547cSRui Paulo 
12415b9c547cSRui Paulo static void qca_nl80211_get_features(struct wpa_driver_nl80211_data *drv)
12425b9c547cSRui Paulo {
12435b9c547cSRui Paulo 	struct nl_msg *msg;
12445b9c547cSRui Paulo 	struct features_info info;
12455b9c547cSRui Paulo 	int ret;
12465b9c547cSRui Paulo 
12475b9c547cSRui Paulo 	if (!drv->get_features_vendor_cmd_avail)
12485b9c547cSRui Paulo 		return;
12495b9c547cSRui Paulo 
12505b9c547cSRui Paulo 	if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
12515b9c547cSRui Paulo 	    nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
12525b9c547cSRui Paulo 	    nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
12535b9c547cSRui Paulo 			QCA_NL80211_VENDOR_SUBCMD_GET_FEATURES)) {
12545b9c547cSRui Paulo 		nlmsg_free(msg);
12555b9c547cSRui Paulo 		return;
12565b9c547cSRui Paulo 	}
12575b9c547cSRui Paulo 
12585b9c547cSRui Paulo 	os_memset(&info, 0, sizeof(info));
1259325151a3SRui Paulo 	info.capa = &drv->capa;
12605b9c547cSRui Paulo 	ret = send_and_recv_msgs(drv, msg, features_info_handler, &info);
12615b9c547cSRui Paulo 	if (ret || !info.flags)
12625b9c547cSRui Paulo 		return;
12635b9c547cSRui Paulo 
12645b9c547cSRui Paulo 	if (check_feature(QCA_WLAN_VENDOR_FEATURE_KEY_MGMT_OFFLOAD, &info))
12655b9c547cSRui Paulo 		drv->capa.flags |= WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD;
1266325151a3SRui Paulo 
1267325151a3SRui Paulo 	if (check_feature(QCA_WLAN_VENDOR_FEATURE_SUPPORT_HW_MODE_ANY, &info))
1268325151a3SRui Paulo 		drv->capa.flags |= WPA_DRIVER_FLAGS_SUPPORT_HW_MODE_ANY;
1269780fb4a2SCy Schubert 
1270780fb4a2SCy Schubert 	if (check_feature(QCA_WLAN_VENDOR_FEATURE_OFFCHANNEL_SIMULTANEOUS,
1271780fb4a2SCy Schubert 			  &info))
1272780fb4a2SCy Schubert 		drv->capa.flags |= WPA_DRIVER_FLAGS_OFFCHANNEL_SIMULTANEOUS;
1273780fb4a2SCy Schubert 	if (check_feature(QCA_WLAN_VENDOR_FEATURE_P2P_LISTEN_OFFLOAD, &info))
1274780fb4a2SCy Schubert 		drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD;
127585732ac8SCy Schubert 	if (check_feature(QCA_WLAN_VENDOR_FEATURE_OCE_STA, &info))
127685732ac8SCy Schubert 		drv->capa.flags |= WPA_DRIVER_FLAGS_OCE_STA;
127785732ac8SCy Schubert 	if (check_feature(QCA_WLAN_VENDOR_FEATURE_OCE_AP, &info))
127885732ac8SCy Schubert 		drv->capa.flags |= WPA_DRIVER_FLAGS_OCE_AP;
127985732ac8SCy Schubert 	if (check_feature(QCA_WLAN_VENDOR_FEATURE_OCE_STA_CFON, &info))
128085732ac8SCy Schubert 		drv->capa.flags |= WPA_DRIVER_FLAGS_OCE_STA_CFON;
1281780fb4a2SCy Schubert 	os_free(info.flags);
12825b9c547cSRui Paulo }
12835b9c547cSRui Paulo 
1284780fb4a2SCy Schubert #endif /* CONFIG_DRIVER_NL80211_QCA */
1285780fb4a2SCy Schubert 
12865b9c547cSRui Paulo 
12875b9c547cSRui Paulo int wpa_driver_nl80211_capa(struct wpa_driver_nl80211_data *drv)
12885b9c547cSRui Paulo {
12895b9c547cSRui Paulo 	struct wiphy_info_data info;
12905b9c547cSRui Paulo 	if (wpa_driver_nl80211_get_info(drv, &info))
12915b9c547cSRui Paulo 		return -1;
12925b9c547cSRui Paulo 
12935b9c547cSRui Paulo 	if (info.error)
12945b9c547cSRui Paulo 		return -1;
12955b9c547cSRui Paulo 
12965b9c547cSRui Paulo 	drv->has_capability = 1;
12975b9c547cSRui Paulo 	drv->capa.key_mgmt = WPA_DRIVER_CAPA_KEY_MGMT_WPA |
12985b9c547cSRui Paulo 		WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
12995b9c547cSRui Paulo 		WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
13005b9c547cSRui Paulo 		WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK |
13015b9c547cSRui Paulo 		WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B |
130285732ac8SCy Schubert 		WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192 |
130385732ac8SCy Schubert 		WPA_DRIVER_CAPA_KEY_MGMT_OWE |
130485732ac8SCy Schubert 		WPA_DRIVER_CAPA_KEY_MGMT_DPP;
130585732ac8SCy Schubert 
130685732ac8SCy Schubert 	if (drv->capa.flags & WPA_DRIVER_FLAGS_SME)
130785732ac8SCy Schubert 		drv->capa.key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256 |
130885732ac8SCy Schubert 			WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384 |
130985732ac8SCy Schubert 			WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA256 |
1310*4bc52338SCy Schubert 			WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA384 |
1311*4bc52338SCy Schubert 			WPA_DRIVER_CAPA_KEY_MGMT_SAE;
131285732ac8SCy Schubert 	else if (drv->capa.flags & WPA_DRIVER_FLAGS_FILS_SK_OFFLOAD)
131385732ac8SCy Schubert 		drv->capa.key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256 |
131485732ac8SCy Schubert 			WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384;
131585732ac8SCy Schubert 
1316*4bc52338SCy Schubert #ifdef CONFIG_DRIVER_NL80211_QCA
1317*4bc52338SCy Schubert 	/* Override drv->capa.key_mgmt based on driver advertised capability
1318*4bc52338SCy Schubert 	 * constraints, if available. */
1319*4bc52338SCy Schubert 	qca_nl80211_get_akm_suites(drv);
1320*4bc52338SCy Schubert #endif /* CONFIG_DRIVER_NL80211_QCA */
1321*4bc52338SCy Schubert 
13225b9c547cSRui Paulo 	drv->capa.auth = WPA_DRIVER_AUTH_OPEN |
13235b9c547cSRui Paulo 		WPA_DRIVER_AUTH_SHARED |
13245b9c547cSRui Paulo 		WPA_DRIVER_AUTH_LEAP;
13255b9c547cSRui Paulo 
13265b9c547cSRui Paulo 	drv->capa.flags |= WPA_DRIVER_FLAGS_SANE_ERROR_CODES;
13275b9c547cSRui Paulo 	drv->capa.flags |= WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE;
13285b9c547cSRui Paulo 	drv->capa.flags |= WPA_DRIVER_FLAGS_EAPOL_TX_STATUS;
13295b9c547cSRui Paulo 
13305b9c547cSRui Paulo 	/*
13315b9c547cSRui Paulo 	 * As all cfg80211 drivers must support cases where the AP interface is
13325b9c547cSRui Paulo 	 * removed without the knowledge of wpa_supplicant/hostapd, e.g., in
13335b9c547cSRui Paulo 	 * case that the user space daemon has crashed, they must be able to
13345b9c547cSRui Paulo 	 * cleanup all stations and key entries in the AP tear down flow. Thus,
13355b9c547cSRui Paulo 	 * this flag can/should always be set for cfg80211 drivers.
13365b9c547cSRui Paulo 	 */
13375b9c547cSRui Paulo 	drv->capa.flags |= WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT;
13385b9c547cSRui Paulo 
13395b9c547cSRui Paulo 	if (!info.device_ap_sme) {
13405b9c547cSRui Paulo 		drv->capa.flags |= WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS;
13415b9c547cSRui Paulo 
13425b9c547cSRui Paulo 		/*
13435b9c547cSRui Paulo 		 * No AP SME is currently assumed to also indicate no AP MLME
13445b9c547cSRui Paulo 		 * in the driver/firmware.
13455b9c547cSRui Paulo 		 */
13465b9c547cSRui Paulo 		drv->capa.flags |= WPA_DRIVER_FLAGS_AP_MLME;
13475b9c547cSRui Paulo 	}
13485b9c547cSRui Paulo 
13495b9c547cSRui Paulo 	drv->device_ap_sme = info.device_ap_sme;
13505b9c547cSRui Paulo 	drv->poll_command_supported = info.poll_command_supported;
13515b9c547cSRui Paulo 	drv->data_tx_status = info.data_tx_status;
13525b9c547cSRui Paulo 	drv->p2p_go_ctwindow_supported = info.p2p_go_ctwindow_supported;
13535b9c547cSRui Paulo 	if (info.set_qos_map_supported)
13545b9c547cSRui Paulo 		drv->capa.flags |= WPA_DRIVER_FLAGS_QOS_MAPPING;
13555b9c547cSRui Paulo 	drv->have_low_prio_scan = info.have_low_prio_scan;
13565b9c547cSRui Paulo 
13575b9c547cSRui Paulo 	/*
13585b9c547cSRui Paulo 	 * If poll command and tx status are supported, mac80211 is new enough
13595b9c547cSRui Paulo 	 * to have everything we need to not need monitor interfaces.
13605b9c547cSRui Paulo 	 */
1361780fb4a2SCy Schubert 	drv->use_monitor = !info.device_ap_sme &&
1362780fb4a2SCy Schubert 		(!info.poll_command_supported || !info.data_tx_status);
13635b9c547cSRui Paulo 
13645b9c547cSRui Paulo 	/*
13655b9c547cSRui Paulo 	 * If we aren't going to use monitor interfaces, but the
13665b9c547cSRui Paulo 	 * driver doesn't support data TX status, we won't get TX
13675b9c547cSRui Paulo 	 * status for EAPOL frames.
13685b9c547cSRui Paulo 	 */
13695b9c547cSRui Paulo 	if (!drv->use_monitor && !info.data_tx_status)
13705b9c547cSRui Paulo 		drv->capa.flags &= ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS;
13715b9c547cSRui Paulo 
1372780fb4a2SCy Schubert #ifdef CONFIG_DRIVER_NL80211_QCA
137385732ac8SCy Schubert 	if (!(info.capa->flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD))
13745b9c547cSRui Paulo 		qca_nl80211_check_dfs_capa(drv);
13755b9c547cSRui Paulo 	qca_nl80211_get_features(drv);
137685732ac8SCy Schubert 	qca_nl80211_check_he_capab(drv);
13775b9c547cSRui Paulo 
1378780fb4a2SCy Schubert 	/*
1379780fb4a2SCy Schubert 	 * To enable offchannel simultaneous support in wpa_supplicant, the
1380780fb4a2SCy Schubert 	 * underlying driver needs to support the same along with offchannel TX.
1381780fb4a2SCy Schubert 	 * Offchannel TX support is needed since remain_on_channel and
1382780fb4a2SCy Schubert 	 * action_tx use some common data structures and hence cannot be
1383780fb4a2SCy Schubert 	 * scheduled simultaneously.
1384780fb4a2SCy Schubert 	 */
1385780fb4a2SCy Schubert 	if (!(drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX))
1386780fb4a2SCy Schubert 		drv->capa.flags &= ~WPA_DRIVER_FLAGS_OFFCHANNEL_SIMULTANEOUS;
1387780fb4a2SCy Schubert #endif /* CONFIG_DRIVER_NL80211_QCA */
1388780fb4a2SCy Schubert 
13895b9c547cSRui Paulo 	return 0;
13905b9c547cSRui Paulo }
13915b9c547cSRui Paulo 
13925b9c547cSRui Paulo 
13935b9c547cSRui Paulo struct phy_info_arg {
13945b9c547cSRui Paulo 	u16 *num_modes;
13955b9c547cSRui Paulo 	struct hostapd_hw_modes *modes;
13965b9c547cSRui Paulo 	int last_mode, last_chan_idx;
1397780fb4a2SCy Schubert 	int failed;
139885732ac8SCy Schubert 	u8 dfs_domain;
13995b9c547cSRui Paulo };
14005b9c547cSRui Paulo 
14015b9c547cSRui Paulo static void phy_info_ht_capa(struct hostapd_hw_modes *mode, struct nlattr *capa,
14025b9c547cSRui Paulo 			     struct nlattr *ampdu_factor,
14035b9c547cSRui Paulo 			     struct nlattr *ampdu_density,
14045b9c547cSRui Paulo 			     struct nlattr *mcs_set)
14055b9c547cSRui Paulo {
14065b9c547cSRui Paulo 	if (capa)
14075b9c547cSRui Paulo 		mode->ht_capab = nla_get_u16(capa);
14085b9c547cSRui Paulo 
14095b9c547cSRui Paulo 	if (ampdu_factor)
14105b9c547cSRui Paulo 		mode->a_mpdu_params |= nla_get_u8(ampdu_factor) & 0x03;
14115b9c547cSRui Paulo 
14125b9c547cSRui Paulo 	if (ampdu_density)
14135b9c547cSRui Paulo 		mode->a_mpdu_params |= nla_get_u8(ampdu_density) << 2;
14145b9c547cSRui Paulo 
14155b9c547cSRui Paulo 	if (mcs_set && nla_len(mcs_set) >= 16) {
14165b9c547cSRui Paulo 		u8 *mcs;
14175b9c547cSRui Paulo 		mcs = nla_data(mcs_set);
14185b9c547cSRui Paulo 		os_memcpy(mode->mcs_set, mcs, 16);
14195b9c547cSRui Paulo 	}
14205b9c547cSRui Paulo }
14215b9c547cSRui Paulo 
14225b9c547cSRui Paulo 
14235b9c547cSRui Paulo static void phy_info_vht_capa(struct hostapd_hw_modes *mode,
14245b9c547cSRui Paulo 			      struct nlattr *capa,
14255b9c547cSRui Paulo 			      struct nlattr *mcs_set)
14265b9c547cSRui Paulo {
14275b9c547cSRui Paulo 	if (capa)
14285b9c547cSRui Paulo 		mode->vht_capab = nla_get_u32(capa);
14295b9c547cSRui Paulo 
14305b9c547cSRui Paulo 	if (mcs_set && nla_len(mcs_set) >= 8) {
14315b9c547cSRui Paulo 		u8 *mcs;
14325b9c547cSRui Paulo 		mcs = nla_data(mcs_set);
14335b9c547cSRui Paulo 		os_memcpy(mode->vht_mcs_set, mcs, 8);
14345b9c547cSRui Paulo 	}
14355b9c547cSRui Paulo }
14365b9c547cSRui Paulo 
14375b9c547cSRui Paulo 
14385b9c547cSRui Paulo static void phy_info_freq(struct hostapd_hw_modes *mode,
14395b9c547cSRui Paulo 			  struct hostapd_channel_data *chan,
14405b9c547cSRui Paulo 			  struct nlattr *tb_freq[])
14415b9c547cSRui Paulo {
14425b9c547cSRui Paulo 	u8 channel;
14435b9c547cSRui Paulo 	chan->freq = nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_FREQ]);
14445b9c547cSRui Paulo 	chan->flag = 0;
1445*4bc52338SCy Schubert 	chan->allowed_bw = ~0;
14465b9c547cSRui Paulo 	chan->dfs_cac_ms = 0;
14475b9c547cSRui Paulo 	if (ieee80211_freq_to_chan(chan->freq, &channel) != NUM_HOSTAPD_MODES)
14485b9c547cSRui Paulo 		chan->chan = channel;
14495b9c547cSRui Paulo 
14505b9c547cSRui Paulo 	if (tb_freq[NL80211_FREQUENCY_ATTR_DISABLED])
14515b9c547cSRui Paulo 		chan->flag |= HOSTAPD_CHAN_DISABLED;
14525b9c547cSRui Paulo 	if (tb_freq[NL80211_FREQUENCY_ATTR_NO_IR])
14535b9c547cSRui Paulo 		chan->flag |= HOSTAPD_CHAN_NO_IR;
14545b9c547cSRui Paulo 	if (tb_freq[NL80211_FREQUENCY_ATTR_RADAR])
14555b9c547cSRui Paulo 		chan->flag |= HOSTAPD_CHAN_RADAR;
14565b9c547cSRui Paulo 	if (tb_freq[NL80211_FREQUENCY_ATTR_INDOOR_ONLY])
14575b9c547cSRui Paulo 		chan->flag |= HOSTAPD_CHAN_INDOOR_ONLY;
14585b9c547cSRui Paulo 	if (tb_freq[NL80211_FREQUENCY_ATTR_GO_CONCURRENT])
14595b9c547cSRui Paulo 		chan->flag |= HOSTAPD_CHAN_GO_CONCURRENT;
14605b9c547cSRui Paulo 
1461*4bc52338SCy Schubert 	if (tb_freq[NL80211_FREQUENCY_ATTR_NO_10MHZ])
1462*4bc52338SCy Schubert 		chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_10;
1463*4bc52338SCy Schubert 	if (tb_freq[NL80211_FREQUENCY_ATTR_NO_20MHZ])
1464*4bc52338SCy Schubert 		chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_20;
1465*4bc52338SCy Schubert 	if (tb_freq[NL80211_FREQUENCY_ATTR_NO_HT40_PLUS])
1466*4bc52338SCy Schubert 		chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_40P;
1467*4bc52338SCy Schubert 	if (tb_freq[NL80211_FREQUENCY_ATTR_NO_HT40_MINUS])
1468*4bc52338SCy Schubert 		chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_40M;
1469*4bc52338SCy Schubert 	if (tb_freq[NL80211_FREQUENCY_ATTR_NO_80MHZ])
1470*4bc52338SCy Schubert 		chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_80;
1471*4bc52338SCy Schubert 	if (tb_freq[NL80211_FREQUENCY_ATTR_NO_160MHZ])
1472*4bc52338SCy Schubert 		chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_160;
1473*4bc52338SCy Schubert 
14745b9c547cSRui Paulo 	if (tb_freq[NL80211_FREQUENCY_ATTR_DFS_STATE]) {
14755b9c547cSRui Paulo 		enum nl80211_dfs_state state =
14765b9c547cSRui Paulo 			nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_DFS_STATE]);
14775b9c547cSRui Paulo 
14785b9c547cSRui Paulo 		switch (state) {
14795b9c547cSRui Paulo 		case NL80211_DFS_USABLE:
14805b9c547cSRui Paulo 			chan->flag |= HOSTAPD_CHAN_DFS_USABLE;
14815b9c547cSRui Paulo 			break;
14825b9c547cSRui Paulo 		case NL80211_DFS_AVAILABLE:
14835b9c547cSRui Paulo 			chan->flag |= HOSTAPD_CHAN_DFS_AVAILABLE;
14845b9c547cSRui Paulo 			break;
14855b9c547cSRui Paulo 		case NL80211_DFS_UNAVAILABLE:
14865b9c547cSRui Paulo 			chan->flag |= HOSTAPD_CHAN_DFS_UNAVAILABLE;
14875b9c547cSRui Paulo 			break;
14885b9c547cSRui Paulo 		}
14895b9c547cSRui Paulo 	}
14905b9c547cSRui Paulo 
14915b9c547cSRui Paulo 	if (tb_freq[NL80211_FREQUENCY_ATTR_DFS_CAC_TIME]) {
14925b9c547cSRui Paulo 		chan->dfs_cac_ms = nla_get_u32(
14935b9c547cSRui Paulo 			tb_freq[NL80211_FREQUENCY_ATTR_DFS_CAC_TIME]);
14945b9c547cSRui Paulo 	}
14955b9c547cSRui Paulo }
14965b9c547cSRui Paulo 
14975b9c547cSRui Paulo 
14985b9c547cSRui Paulo static int phy_info_freqs(struct phy_info_arg *phy_info,
14995b9c547cSRui Paulo 			  struct hostapd_hw_modes *mode, struct nlattr *tb)
15005b9c547cSRui Paulo {
15015b9c547cSRui Paulo 	static struct nla_policy freq_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = {
15025b9c547cSRui Paulo 		[NL80211_FREQUENCY_ATTR_FREQ] = { .type = NLA_U32 },
15035b9c547cSRui Paulo 		[NL80211_FREQUENCY_ATTR_DISABLED] = { .type = NLA_FLAG },
15045b9c547cSRui Paulo 		[NL80211_FREQUENCY_ATTR_NO_IR] = { .type = NLA_FLAG },
15055b9c547cSRui Paulo 		[NL80211_FREQUENCY_ATTR_RADAR] = { .type = NLA_FLAG },
15065b9c547cSRui Paulo 		[NL80211_FREQUENCY_ATTR_MAX_TX_POWER] = { .type = NLA_U32 },
15075b9c547cSRui Paulo 		[NL80211_FREQUENCY_ATTR_DFS_STATE] = { .type = NLA_U32 },
1508*4bc52338SCy Schubert 		[NL80211_FREQUENCY_ATTR_NO_10MHZ] = { .type = NLA_FLAG },
1509*4bc52338SCy Schubert 		[NL80211_FREQUENCY_ATTR_NO_20MHZ] = { .type = NLA_FLAG },
1510*4bc52338SCy Schubert 		[NL80211_FREQUENCY_ATTR_NO_HT40_PLUS] = { .type = NLA_FLAG },
1511*4bc52338SCy Schubert 		[NL80211_FREQUENCY_ATTR_NO_HT40_MINUS] = { .type = NLA_FLAG },
1512*4bc52338SCy Schubert 		[NL80211_FREQUENCY_ATTR_NO_80MHZ] = { .type = NLA_FLAG },
1513*4bc52338SCy Schubert 		[NL80211_FREQUENCY_ATTR_NO_160MHZ] = { .type = NLA_FLAG },
15145b9c547cSRui Paulo 	};
15155b9c547cSRui Paulo 	int new_channels = 0;
15165b9c547cSRui Paulo 	struct hostapd_channel_data *channel;
15175b9c547cSRui Paulo 	struct nlattr *tb_freq[NL80211_FREQUENCY_ATTR_MAX + 1];
15185b9c547cSRui Paulo 	struct nlattr *nl_freq;
15195b9c547cSRui Paulo 	int rem_freq, idx;
15205b9c547cSRui Paulo 
15215b9c547cSRui Paulo 	if (tb == NULL)
15225b9c547cSRui Paulo 		return NL_OK;
15235b9c547cSRui Paulo 
15245b9c547cSRui Paulo 	nla_for_each_nested(nl_freq, tb, rem_freq) {
15255b9c547cSRui Paulo 		nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX,
15265b9c547cSRui Paulo 			  nla_data(nl_freq), nla_len(nl_freq), freq_policy);
15275b9c547cSRui Paulo 		if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ])
15285b9c547cSRui Paulo 			continue;
15295b9c547cSRui Paulo 		new_channels++;
15305b9c547cSRui Paulo 	}
15315b9c547cSRui Paulo 
15325b9c547cSRui Paulo 	channel = os_realloc_array(mode->channels,
15335b9c547cSRui Paulo 				   mode->num_channels + new_channels,
15345b9c547cSRui Paulo 				   sizeof(struct hostapd_channel_data));
15355b9c547cSRui Paulo 	if (!channel)
1536780fb4a2SCy Schubert 		return NL_STOP;
15375b9c547cSRui Paulo 
15385b9c547cSRui Paulo 	mode->channels = channel;
15395b9c547cSRui Paulo 	mode->num_channels += new_channels;
15405b9c547cSRui Paulo 
15415b9c547cSRui Paulo 	idx = phy_info->last_chan_idx;
15425b9c547cSRui Paulo 
15435b9c547cSRui Paulo 	nla_for_each_nested(nl_freq, tb, rem_freq) {
15445b9c547cSRui Paulo 		nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX,
15455b9c547cSRui Paulo 			  nla_data(nl_freq), nla_len(nl_freq), freq_policy);
15465b9c547cSRui Paulo 		if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ])
15475b9c547cSRui Paulo 			continue;
15485b9c547cSRui Paulo 		phy_info_freq(mode, &mode->channels[idx], tb_freq);
15495b9c547cSRui Paulo 		idx++;
15505b9c547cSRui Paulo 	}
15515b9c547cSRui Paulo 	phy_info->last_chan_idx = idx;
15525b9c547cSRui Paulo 
15535b9c547cSRui Paulo 	return NL_OK;
15545b9c547cSRui Paulo }
15555b9c547cSRui Paulo 
15565b9c547cSRui Paulo 
15575b9c547cSRui Paulo static int phy_info_rates(struct hostapd_hw_modes *mode, struct nlattr *tb)
15585b9c547cSRui Paulo {
15595b9c547cSRui Paulo 	static struct nla_policy rate_policy[NL80211_BITRATE_ATTR_MAX + 1] = {
15605b9c547cSRui Paulo 		[NL80211_BITRATE_ATTR_RATE] = { .type = NLA_U32 },
15615b9c547cSRui Paulo 		[NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE] =
15625b9c547cSRui Paulo 		{ .type = NLA_FLAG },
15635b9c547cSRui Paulo 	};
15645b9c547cSRui Paulo 	struct nlattr *tb_rate[NL80211_BITRATE_ATTR_MAX + 1];
15655b9c547cSRui Paulo 	struct nlattr *nl_rate;
15665b9c547cSRui Paulo 	int rem_rate, idx;
15675b9c547cSRui Paulo 
15685b9c547cSRui Paulo 	if (tb == NULL)
15695b9c547cSRui Paulo 		return NL_OK;
15705b9c547cSRui Paulo 
15715b9c547cSRui Paulo 	nla_for_each_nested(nl_rate, tb, rem_rate) {
15725b9c547cSRui Paulo 		nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX,
15735b9c547cSRui Paulo 			  nla_data(nl_rate), nla_len(nl_rate),
15745b9c547cSRui Paulo 			  rate_policy);
15755b9c547cSRui Paulo 		if (!tb_rate[NL80211_BITRATE_ATTR_RATE])
15765b9c547cSRui Paulo 			continue;
15775b9c547cSRui Paulo 		mode->num_rates++;
15785b9c547cSRui Paulo 	}
15795b9c547cSRui Paulo 
15805b9c547cSRui Paulo 	mode->rates = os_calloc(mode->num_rates, sizeof(int));
15815b9c547cSRui Paulo 	if (!mode->rates)
1582780fb4a2SCy Schubert 		return NL_STOP;
15835b9c547cSRui Paulo 
15845b9c547cSRui Paulo 	idx = 0;
15855b9c547cSRui Paulo 
15865b9c547cSRui Paulo 	nla_for_each_nested(nl_rate, tb, rem_rate) {
15875b9c547cSRui Paulo 		nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX,
15885b9c547cSRui Paulo 			  nla_data(nl_rate), nla_len(nl_rate),
15895b9c547cSRui Paulo 			  rate_policy);
15905b9c547cSRui Paulo 		if (!tb_rate[NL80211_BITRATE_ATTR_RATE])
15915b9c547cSRui Paulo 			continue;
15925b9c547cSRui Paulo 		mode->rates[idx] = nla_get_u32(
15935b9c547cSRui Paulo 			tb_rate[NL80211_BITRATE_ATTR_RATE]);
15945b9c547cSRui Paulo 		idx++;
15955b9c547cSRui Paulo 	}
15965b9c547cSRui Paulo 
15975b9c547cSRui Paulo 	return NL_OK;
15985b9c547cSRui Paulo }
15995b9c547cSRui Paulo 
16005b9c547cSRui Paulo 
16015b9c547cSRui Paulo static int phy_info_band(struct phy_info_arg *phy_info, struct nlattr *nl_band)
16025b9c547cSRui Paulo {
16035b9c547cSRui Paulo 	struct nlattr *tb_band[NL80211_BAND_ATTR_MAX + 1];
16045b9c547cSRui Paulo 	struct hostapd_hw_modes *mode;
16055b9c547cSRui Paulo 	int ret;
16065b9c547cSRui Paulo 
16075b9c547cSRui Paulo 	if (phy_info->last_mode != nl_band->nla_type) {
16085b9c547cSRui Paulo 		mode = os_realloc_array(phy_info->modes,
16095b9c547cSRui Paulo 					*phy_info->num_modes + 1,
16105b9c547cSRui Paulo 					sizeof(*mode));
1611780fb4a2SCy Schubert 		if (!mode) {
1612780fb4a2SCy Schubert 			phy_info->failed = 1;
1613780fb4a2SCy Schubert 			return NL_STOP;
1614780fb4a2SCy Schubert 		}
16155b9c547cSRui Paulo 		phy_info->modes = mode;
16165b9c547cSRui Paulo 
16175b9c547cSRui Paulo 		mode = &phy_info->modes[*(phy_info->num_modes)];
16185b9c547cSRui Paulo 		os_memset(mode, 0, sizeof(*mode));
16195b9c547cSRui Paulo 		mode->mode = NUM_HOSTAPD_MODES;
16205b9c547cSRui Paulo 		mode->flags = HOSTAPD_MODE_FLAG_HT_INFO_KNOWN |
16215b9c547cSRui Paulo 			HOSTAPD_MODE_FLAG_VHT_INFO_KNOWN;
16225b9c547cSRui Paulo 
16235b9c547cSRui Paulo 		/*
16245b9c547cSRui Paulo 		 * Unsupported VHT MCS stream is defined as value 3, so the VHT
16255b9c547cSRui Paulo 		 * MCS RX/TX map must be initialized with 0xffff to mark all 8
16265b9c547cSRui Paulo 		 * possible streams as unsupported. This will be overridden if
16275b9c547cSRui Paulo 		 * driver advertises VHT support.
16285b9c547cSRui Paulo 		 */
16295b9c547cSRui Paulo 		mode->vht_mcs_set[0] = 0xff;
16305b9c547cSRui Paulo 		mode->vht_mcs_set[1] = 0xff;
16315b9c547cSRui Paulo 		mode->vht_mcs_set[4] = 0xff;
16325b9c547cSRui Paulo 		mode->vht_mcs_set[5] = 0xff;
16335b9c547cSRui Paulo 
16345b9c547cSRui Paulo 		*(phy_info->num_modes) += 1;
16355b9c547cSRui Paulo 		phy_info->last_mode = nl_band->nla_type;
16365b9c547cSRui Paulo 		phy_info->last_chan_idx = 0;
16375b9c547cSRui Paulo 	} else
16385b9c547cSRui Paulo 		mode = &phy_info->modes[*(phy_info->num_modes) - 1];
16395b9c547cSRui Paulo 
16405b9c547cSRui Paulo 	nla_parse(tb_band, NL80211_BAND_ATTR_MAX, nla_data(nl_band),
16415b9c547cSRui Paulo 		  nla_len(nl_band), NULL);
16425b9c547cSRui Paulo 
16435b9c547cSRui Paulo 	phy_info_ht_capa(mode, tb_band[NL80211_BAND_ATTR_HT_CAPA],
16445b9c547cSRui Paulo 			 tb_band[NL80211_BAND_ATTR_HT_AMPDU_FACTOR],
16455b9c547cSRui Paulo 			 tb_band[NL80211_BAND_ATTR_HT_AMPDU_DENSITY],
16465b9c547cSRui Paulo 			 tb_band[NL80211_BAND_ATTR_HT_MCS_SET]);
16475b9c547cSRui Paulo 	phy_info_vht_capa(mode, tb_band[NL80211_BAND_ATTR_VHT_CAPA],
16485b9c547cSRui Paulo 			  tb_band[NL80211_BAND_ATTR_VHT_MCS_SET]);
16495b9c547cSRui Paulo 	ret = phy_info_freqs(phy_info, mode, tb_band[NL80211_BAND_ATTR_FREQS]);
1650780fb4a2SCy Schubert 	if (ret == NL_OK)
16515b9c547cSRui Paulo 		ret = phy_info_rates(mode, tb_band[NL80211_BAND_ATTR_RATES]);
1652780fb4a2SCy Schubert 	if (ret != NL_OK) {
1653780fb4a2SCy Schubert 		phy_info->failed = 1;
16545b9c547cSRui Paulo 		return ret;
1655780fb4a2SCy Schubert 	}
16565b9c547cSRui Paulo 
16575b9c547cSRui Paulo 	return NL_OK;
16585b9c547cSRui Paulo }
16595b9c547cSRui Paulo 
16605b9c547cSRui Paulo 
16615b9c547cSRui Paulo static int phy_info_handler(struct nl_msg *msg, void *arg)
16625b9c547cSRui Paulo {
16635b9c547cSRui Paulo 	struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
16645b9c547cSRui Paulo 	struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
16655b9c547cSRui Paulo 	struct phy_info_arg *phy_info = arg;
16665b9c547cSRui Paulo 	struct nlattr *nl_band;
16675b9c547cSRui Paulo 	int rem_band;
16685b9c547cSRui Paulo 
16695b9c547cSRui Paulo 	nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
16705b9c547cSRui Paulo 		  genlmsg_attrlen(gnlh, 0), NULL);
16715b9c547cSRui Paulo 
16725b9c547cSRui Paulo 	if (!tb_msg[NL80211_ATTR_WIPHY_BANDS])
16735b9c547cSRui Paulo 		return NL_SKIP;
16745b9c547cSRui Paulo 
16755b9c547cSRui Paulo 	nla_for_each_nested(nl_band, tb_msg[NL80211_ATTR_WIPHY_BANDS], rem_band)
16765b9c547cSRui Paulo 	{
16775b9c547cSRui Paulo 		int res = phy_info_band(phy_info, nl_band);
16785b9c547cSRui Paulo 		if (res != NL_OK)
16795b9c547cSRui Paulo 			return res;
16805b9c547cSRui Paulo 	}
16815b9c547cSRui Paulo 
16825b9c547cSRui Paulo 	return NL_SKIP;
16835b9c547cSRui Paulo }
16845b9c547cSRui Paulo 
16855b9c547cSRui Paulo 
16865b9c547cSRui Paulo static struct hostapd_hw_modes *
16875b9c547cSRui Paulo wpa_driver_nl80211_postprocess_modes(struct hostapd_hw_modes *modes,
16885b9c547cSRui Paulo 				     u16 *num_modes)
16895b9c547cSRui Paulo {
16905b9c547cSRui Paulo 	u16 m;
16915b9c547cSRui Paulo 	struct hostapd_hw_modes *mode11g = NULL, *nmodes, *mode;
16925b9c547cSRui Paulo 	int i, mode11g_idx = -1;
16935b9c547cSRui Paulo 
16945b9c547cSRui Paulo 	/* heuristic to set up modes */
16955b9c547cSRui Paulo 	for (m = 0; m < *num_modes; m++) {
16965b9c547cSRui Paulo 		if (!modes[m].num_channels)
16975b9c547cSRui Paulo 			continue;
16985b9c547cSRui Paulo 		if (modes[m].channels[0].freq < 4000) {
16995b9c547cSRui Paulo 			modes[m].mode = HOSTAPD_MODE_IEEE80211B;
17005b9c547cSRui Paulo 			for (i = 0; i < modes[m].num_rates; i++) {
17015b9c547cSRui Paulo 				if (modes[m].rates[i] > 200) {
17025b9c547cSRui Paulo 					modes[m].mode = HOSTAPD_MODE_IEEE80211G;
17035b9c547cSRui Paulo 					break;
17045b9c547cSRui Paulo 				}
17055b9c547cSRui Paulo 			}
17065b9c547cSRui Paulo 		} else if (modes[m].channels[0].freq > 50000)
17075b9c547cSRui Paulo 			modes[m].mode = HOSTAPD_MODE_IEEE80211AD;
17085b9c547cSRui Paulo 		else
17095b9c547cSRui Paulo 			modes[m].mode = HOSTAPD_MODE_IEEE80211A;
17105b9c547cSRui Paulo 	}
17115b9c547cSRui Paulo 
17125b9c547cSRui Paulo 	/* If only 802.11g mode is included, use it to construct matching
17135b9c547cSRui Paulo 	 * 802.11b mode data. */
17145b9c547cSRui Paulo 
17155b9c547cSRui Paulo 	for (m = 0; m < *num_modes; m++) {
17165b9c547cSRui Paulo 		if (modes[m].mode == HOSTAPD_MODE_IEEE80211B)
17175b9c547cSRui Paulo 			return modes; /* 802.11b already included */
17185b9c547cSRui Paulo 		if (modes[m].mode == HOSTAPD_MODE_IEEE80211G)
17195b9c547cSRui Paulo 			mode11g_idx = m;
17205b9c547cSRui Paulo 	}
17215b9c547cSRui Paulo 
17225b9c547cSRui Paulo 	if (mode11g_idx < 0)
17235b9c547cSRui Paulo 		return modes; /* 2.4 GHz band not supported at all */
17245b9c547cSRui Paulo 
17255b9c547cSRui Paulo 	nmodes = os_realloc_array(modes, *num_modes + 1, sizeof(*nmodes));
17265b9c547cSRui Paulo 	if (nmodes == NULL)
17275b9c547cSRui Paulo 		return modes; /* Could not add 802.11b mode */
17285b9c547cSRui Paulo 
17295b9c547cSRui Paulo 	mode = &nmodes[*num_modes];
17305b9c547cSRui Paulo 	os_memset(mode, 0, sizeof(*mode));
17315b9c547cSRui Paulo 	(*num_modes)++;
17325b9c547cSRui Paulo 	modes = nmodes;
17335b9c547cSRui Paulo 
17345b9c547cSRui Paulo 	mode->mode = HOSTAPD_MODE_IEEE80211B;
17355b9c547cSRui Paulo 
17365b9c547cSRui Paulo 	mode11g = &modes[mode11g_idx];
17375b9c547cSRui Paulo 	mode->num_channels = mode11g->num_channels;
173885732ac8SCy Schubert 	mode->channels = os_memdup(mode11g->channels,
173985732ac8SCy Schubert 				   mode11g->num_channels *
17405b9c547cSRui Paulo 				   sizeof(struct hostapd_channel_data));
17415b9c547cSRui Paulo 	if (mode->channels == NULL) {
17425b9c547cSRui Paulo 		(*num_modes)--;
17435b9c547cSRui Paulo 		return modes; /* Could not add 802.11b mode */
17445b9c547cSRui Paulo 	}
17455b9c547cSRui Paulo 
17465b9c547cSRui Paulo 	mode->num_rates = 0;
17475b9c547cSRui Paulo 	mode->rates = os_malloc(4 * sizeof(int));
17485b9c547cSRui Paulo 	if (mode->rates == NULL) {
17495b9c547cSRui Paulo 		os_free(mode->channels);
17505b9c547cSRui Paulo 		(*num_modes)--;
17515b9c547cSRui Paulo 		return modes; /* Could not add 802.11b mode */
17525b9c547cSRui Paulo 	}
17535b9c547cSRui Paulo 
17545b9c547cSRui Paulo 	for (i = 0; i < mode11g->num_rates; i++) {
17555b9c547cSRui Paulo 		if (mode11g->rates[i] != 10 && mode11g->rates[i] != 20 &&
17565b9c547cSRui Paulo 		    mode11g->rates[i] != 55 && mode11g->rates[i] != 110)
17575b9c547cSRui Paulo 			continue;
17585b9c547cSRui Paulo 		mode->rates[mode->num_rates] = mode11g->rates[i];
17595b9c547cSRui Paulo 		mode->num_rates++;
17605b9c547cSRui Paulo 		if (mode->num_rates == 4)
17615b9c547cSRui Paulo 			break;
17625b9c547cSRui Paulo 	}
17635b9c547cSRui Paulo 
17645b9c547cSRui Paulo 	if (mode->num_rates == 0) {
17655b9c547cSRui Paulo 		os_free(mode->channels);
17665b9c547cSRui Paulo 		os_free(mode->rates);
17675b9c547cSRui Paulo 		(*num_modes)--;
17685b9c547cSRui Paulo 		return modes; /* No 802.11b rates */
17695b9c547cSRui Paulo 	}
17705b9c547cSRui Paulo 
17715b9c547cSRui Paulo 	wpa_printf(MSG_DEBUG, "nl80211: Added 802.11b mode based on 802.11g "
17725b9c547cSRui Paulo 		   "information");
17735b9c547cSRui Paulo 
17745b9c547cSRui Paulo 	return modes;
17755b9c547cSRui Paulo }
17765b9c547cSRui Paulo 
17775b9c547cSRui Paulo 
17785b9c547cSRui Paulo static void nl80211_set_ht40_mode(struct hostapd_hw_modes *mode, int start,
17795b9c547cSRui Paulo 				  int end)
17805b9c547cSRui Paulo {
17815b9c547cSRui Paulo 	int c;
17825b9c547cSRui Paulo 
17835b9c547cSRui Paulo 	for (c = 0; c < mode->num_channels; c++) {
17845b9c547cSRui Paulo 		struct hostapd_channel_data *chan = &mode->channels[c];
17855b9c547cSRui Paulo 		if (chan->freq - 10 >= start && chan->freq + 10 <= end)
17865b9c547cSRui Paulo 			chan->flag |= HOSTAPD_CHAN_HT40;
17875b9c547cSRui Paulo 	}
17885b9c547cSRui Paulo }
17895b9c547cSRui Paulo 
17905b9c547cSRui Paulo 
17915b9c547cSRui Paulo static void nl80211_set_ht40_mode_sec(struct hostapd_hw_modes *mode, int start,
17925b9c547cSRui Paulo 				      int end)
17935b9c547cSRui Paulo {
17945b9c547cSRui Paulo 	int c;
17955b9c547cSRui Paulo 
17965b9c547cSRui Paulo 	for (c = 0; c < mode->num_channels; c++) {
17975b9c547cSRui Paulo 		struct hostapd_channel_data *chan = &mode->channels[c];
17985b9c547cSRui Paulo 		if (!(chan->flag & HOSTAPD_CHAN_HT40))
17995b9c547cSRui Paulo 			continue;
18005b9c547cSRui Paulo 		if (chan->freq - 30 >= start && chan->freq - 10 <= end)
18015b9c547cSRui Paulo 			chan->flag |= HOSTAPD_CHAN_HT40MINUS;
18025b9c547cSRui Paulo 		if (chan->freq + 10 >= start && chan->freq + 30 <= end)
18035b9c547cSRui Paulo 			chan->flag |= HOSTAPD_CHAN_HT40PLUS;
18045b9c547cSRui Paulo 	}
18055b9c547cSRui Paulo }
18065b9c547cSRui Paulo 
18075b9c547cSRui Paulo 
18085b9c547cSRui Paulo static void nl80211_reg_rule_max_eirp(u32 start, u32 end, u32 max_eirp,
18095b9c547cSRui Paulo 				      struct phy_info_arg *results)
18105b9c547cSRui Paulo {
18115b9c547cSRui Paulo 	u16 m;
18125b9c547cSRui Paulo 
18135b9c547cSRui Paulo 	for (m = 0; m < *results->num_modes; m++) {
18145b9c547cSRui Paulo 		int c;
18155b9c547cSRui Paulo 		struct hostapd_hw_modes *mode = &results->modes[m];
18165b9c547cSRui Paulo 
18175b9c547cSRui Paulo 		for (c = 0; c < mode->num_channels; c++) {
18185b9c547cSRui Paulo 			struct hostapd_channel_data *chan = &mode->channels[c];
18195b9c547cSRui Paulo 			if ((u32) chan->freq - 10 >= start &&
18205b9c547cSRui Paulo 			    (u32) chan->freq + 10 <= end)
18215b9c547cSRui Paulo 				chan->max_tx_power = max_eirp;
18225b9c547cSRui Paulo 		}
18235b9c547cSRui Paulo 	}
18245b9c547cSRui Paulo }
18255b9c547cSRui Paulo 
18265b9c547cSRui Paulo 
18275b9c547cSRui Paulo static void nl80211_reg_rule_ht40(u32 start, u32 end,
18285b9c547cSRui Paulo 				  struct phy_info_arg *results)
18295b9c547cSRui Paulo {
18305b9c547cSRui Paulo 	u16 m;
18315b9c547cSRui Paulo 
18325b9c547cSRui Paulo 	for (m = 0; m < *results->num_modes; m++) {
18335b9c547cSRui Paulo 		if (!(results->modes[m].ht_capab &
18345b9c547cSRui Paulo 		      HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET))
18355b9c547cSRui Paulo 			continue;
18365b9c547cSRui Paulo 		nl80211_set_ht40_mode(&results->modes[m], start, end);
18375b9c547cSRui Paulo 	}
18385b9c547cSRui Paulo }
18395b9c547cSRui Paulo 
18405b9c547cSRui Paulo 
18415b9c547cSRui Paulo static void nl80211_reg_rule_sec(struct nlattr *tb[],
18425b9c547cSRui Paulo 				 struct phy_info_arg *results)
18435b9c547cSRui Paulo {
18445b9c547cSRui Paulo 	u32 start, end, max_bw;
18455b9c547cSRui Paulo 	u16 m;
18465b9c547cSRui Paulo 
18475b9c547cSRui Paulo 	if (tb[NL80211_ATTR_FREQ_RANGE_START] == NULL ||
18485b9c547cSRui Paulo 	    tb[NL80211_ATTR_FREQ_RANGE_END] == NULL ||
18495b9c547cSRui Paulo 	    tb[NL80211_ATTR_FREQ_RANGE_MAX_BW] == NULL)
18505b9c547cSRui Paulo 		return;
18515b9c547cSRui Paulo 
18525b9c547cSRui Paulo 	start = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]) / 1000;
18535b9c547cSRui Paulo 	end = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]) / 1000;
18545b9c547cSRui Paulo 	max_bw = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) / 1000;
18555b9c547cSRui Paulo 
18565b9c547cSRui Paulo 	if (max_bw < 20)
18575b9c547cSRui Paulo 		return;
18585b9c547cSRui Paulo 
18595b9c547cSRui Paulo 	for (m = 0; m < *results->num_modes; m++) {
18605b9c547cSRui Paulo 		if (!(results->modes[m].ht_capab &
18615b9c547cSRui Paulo 		      HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET))
18625b9c547cSRui Paulo 			continue;
18635b9c547cSRui Paulo 		nl80211_set_ht40_mode_sec(&results->modes[m], start, end);
18645b9c547cSRui Paulo 	}
18655b9c547cSRui Paulo }
18665b9c547cSRui Paulo 
18675b9c547cSRui Paulo 
18685b9c547cSRui Paulo static void nl80211_set_vht_mode(struct hostapd_hw_modes *mode, int start,
1869780fb4a2SCy Schubert 				 int end, int max_bw)
18705b9c547cSRui Paulo {
18715b9c547cSRui Paulo 	int c;
18725b9c547cSRui Paulo 
18735b9c547cSRui Paulo 	for (c = 0; c < mode->num_channels; c++) {
18745b9c547cSRui Paulo 		struct hostapd_channel_data *chan = &mode->channels[c];
18755b9c547cSRui Paulo 		if (chan->freq - 10 >= start && chan->freq + 70 <= end)
18765b9c547cSRui Paulo 			chan->flag |= HOSTAPD_CHAN_VHT_10_70;
18775b9c547cSRui Paulo 
18785b9c547cSRui Paulo 		if (chan->freq - 30 >= start && chan->freq + 50 <= end)
18795b9c547cSRui Paulo 			chan->flag |= HOSTAPD_CHAN_VHT_30_50;
18805b9c547cSRui Paulo 
18815b9c547cSRui Paulo 		if (chan->freq - 50 >= start && chan->freq + 30 <= end)
18825b9c547cSRui Paulo 			chan->flag |= HOSTAPD_CHAN_VHT_50_30;
18835b9c547cSRui Paulo 
18845b9c547cSRui Paulo 		if (chan->freq - 70 >= start && chan->freq + 10 <= end)
18855b9c547cSRui Paulo 			chan->flag |= HOSTAPD_CHAN_VHT_70_10;
1886780fb4a2SCy Schubert 
1887780fb4a2SCy Schubert 		if (max_bw >= 160) {
1888780fb4a2SCy Schubert 			if (chan->freq - 10 >= start && chan->freq + 150 <= end)
1889780fb4a2SCy Schubert 				chan->flag |= HOSTAPD_CHAN_VHT_10_150;
1890780fb4a2SCy Schubert 
1891780fb4a2SCy Schubert 			if (chan->freq - 30 >= start && chan->freq + 130 <= end)
1892780fb4a2SCy Schubert 				chan->flag |= HOSTAPD_CHAN_VHT_30_130;
1893780fb4a2SCy Schubert 
1894780fb4a2SCy Schubert 			if (chan->freq - 50 >= start && chan->freq + 110 <= end)
1895780fb4a2SCy Schubert 				chan->flag |= HOSTAPD_CHAN_VHT_50_110;
1896780fb4a2SCy Schubert 
1897780fb4a2SCy Schubert 			if (chan->freq - 70 >= start && chan->freq + 90 <= end)
1898780fb4a2SCy Schubert 				chan->flag |= HOSTAPD_CHAN_VHT_70_90;
1899780fb4a2SCy Schubert 
1900780fb4a2SCy Schubert 			if (chan->freq - 90 >= start && chan->freq + 70 <= end)
1901780fb4a2SCy Schubert 				chan->flag |= HOSTAPD_CHAN_VHT_90_70;
1902780fb4a2SCy Schubert 
1903780fb4a2SCy Schubert 			if (chan->freq - 110 >= start && chan->freq + 50 <= end)
1904780fb4a2SCy Schubert 				chan->flag |= HOSTAPD_CHAN_VHT_110_50;
1905780fb4a2SCy Schubert 
1906780fb4a2SCy Schubert 			if (chan->freq - 130 >= start && chan->freq + 30 <= end)
1907780fb4a2SCy Schubert 				chan->flag |= HOSTAPD_CHAN_VHT_130_30;
1908780fb4a2SCy Schubert 
1909780fb4a2SCy Schubert 			if (chan->freq - 150 >= start && chan->freq + 10 <= end)
1910780fb4a2SCy Schubert 				chan->flag |= HOSTAPD_CHAN_VHT_150_10;
1911780fb4a2SCy Schubert 		}
19125b9c547cSRui Paulo 	}
19135b9c547cSRui Paulo }
19145b9c547cSRui Paulo 
19155b9c547cSRui Paulo 
19165b9c547cSRui Paulo static void nl80211_reg_rule_vht(struct nlattr *tb[],
19175b9c547cSRui Paulo 				 struct phy_info_arg *results)
19185b9c547cSRui Paulo {
19195b9c547cSRui Paulo 	u32 start, end, max_bw;
19205b9c547cSRui Paulo 	u16 m;
19215b9c547cSRui Paulo 
19225b9c547cSRui Paulo 	if (tb[NL80211_ATTR_FREQ_RANGE_START] == NULL ||
19235b9c547cSRui Paulo 	    tb[NL80211_ATTR_FREQ_RANGE_END] == NULL ||
19245b9c547cSRui Paulo 	    tb[NL80211_ATTR_FREQ_RANGE_MAX_BW] == NULL)
19255b9c547cSRui Paulo 		return;
19265b9c547cSRui Paulo 
19275b9c547cSRui Paulo 	start = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]) / 1000;
19285b9c547cSRui Paulo 	end = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]) / 1000;
19295b9c547cSRui Paulo 	max_bw = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) / 1000;
19305b9c547cSRui Paulo 
19315b9c547cSRui Paulo 	if (max_bw < 80)
19325b9c547cSRui Paulo 		return;
19335b9c547cSRui Paulo 
19345b9c547cSRui Paulo 	for (m = 0; m < *results->num_modes; m++) {
19355b9c547cSRui Paulo 		if (!(results->modes[m].ht_capab &
19365b9c547cSRui Paulo 		      HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET))
19375b9c547cSRui Paulo 			continue;
19385b9c547cSRui Paulo 		/* TODO: use a real VHT support indication */
19395b9c547cSRui Paulo 		if (!results->modes[m].vht_capab)
19405b9c547cSRui Paulo 			continue;
19415b9c547cSRui Paulo 
1942780fb4a2SCy Schubert 		nl80211_set_vht_mode(&results->modes[m], start, end, max_bw);
19435b9c547cSRui Paulo 	}
19445b9c547cSRui Paulo }
19455b9c547cSRui Paulo 
19465b9c547cSRui Paulo 
194785732ac8SCy Schubert static void nl80211_set_dfs_domain(enum nl80211_dfs_regions region,
194885732ac8SCy Schubert 				   u8 *dfs_domain)
194985732ac8SCy Schubert {
195085732ac8SCy Schubert 	if (region == NL80211_DFS_FCC)
195185732ac8SCy Schubert 		*dfs_domain = HOSTAPD_DFS_REGION_FCC;
195285732ac8SCy Schubert 	else if (region == NL80211_DFS_ETSI)
195385732ac8SCy Schubert 		*dfs_domain = HOSTAPD_DFS_REGION_ETSI;
195485732ac8SCy Schubert 	else if (region == NL80211_DFS_JP)
195585732ac8SCy Schubert 		*dfs_domain = HOSTAPD_DFS_REGION_JP;
195685732ac8SCy Schubert 	else
195785732ac8SCy Schubert 		*dfs_domain = 0;
195885732ac8SCy Schubert }
195985732ac8SCy Schubert 
196085732ac8SCy Schubert 
19615b9c547cSRui Paulo static const char * dfs_domain_name(enum nl80211_dfs_regions region)
19625b9c547cSRui Paulo {
19635b9c547cSRui Paulo 	switch (region) {
19645b9c547cSRui Paulo 	case NL80211_DFS_UNSET:
19655b9c547cSRui Paulo 		return "DFS-UNSET";
19665b9c547cSRui Paulo 	case NL80211_DFS_FCC:
19675b9c547cSRui Paulo 		return "DFS-FCC";
19685b9c547cSRui Paulo 	case NL80211_DFS_ETSI:
19695b9c547cSRui Paulo 		return "DFS-ETSI";
19705b9c547cSRui Paulo 	case NL80211_DFS_JP:
19715b9c547cSRui Paulo 		return "DFS-JP";
19725b9c547cSRui Paulo 	default:
19735b9c547cSRui Paulo 		return "DFS-invalid";
19745b9c547cSRui Paulo 	}
19755b9c547cSRui Paulo }
19765b9c547cSRui Paulo 
19775b9c547cSRui Paulo 
19785b9c547cSRui Paulo static int nl80211_get_reg(struct nl_msg *msg, void *arg)
19795b9c547cSRui Paulo {
19805b9c547cSRui Paulo 	struct phy_info_arg *results = arg;
19815b9c547cSRui Paulo 	struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
19825b9c547cSRui Paulo 	struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
19835b9c547cSRui Paulo 	struct nlattr *nl_rule;
19845b9c547cSRui Paulo 	struct nlattr *tb_rule[NL80211_FREQUENCY_ATTR_MAX + 1];
19855b9c547cSRui Paulo 	int rem_rule;
19865b9c547cSRui Paulo 	static struct nla_policy reg_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = {
19875b9c547cSRui Paulo 		[NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
19885b9c547cSRui Paulo 		[NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
19895b9c547cSRui Paulo 		[NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
19905b9c547cSRui Paulo 		[NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
19915b9c547cSRui Paulo 		[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
19925b9c547cSRui Paulo 		[NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
19935b9c547cSRui Paulo 	};
19945b9c547cSRui Paulo 
19955b9c547cSRui Paulo 	nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
19965b9c547cSRui Paulo 		  genlmsg_attrlen(gnlh, 0), NULL);
19975b9c547cSRui Paulo 	if (!tb_msg[NL80211_ATTR_REG_ALPHA2] ||
19985b9c547cSRui Paulo 	    !tb_msg[NL80211_ATTR_REG_RULES]) {
19995b9c547cSRui Paulo 		wpa_printf(MSG_DEBUG, "nl80211: No regulatory information "
20005b9c547cSRui Paulo 			   "available");
20015b9c547cSRui Paulo 		return NL_SKIP;
20025b9c547cSRui Paulo 	}
20035b9c547cSRui Paulo 
20045b9c547cSRui Paulo 	if (tb_msg[NL80211_ATTR_DFS_REGION]) {
20055b9c547cSRui Paulo 		enum nl80211_dfs_regions dfs_domain;
20065b9c547cSRui Paulo 		dfs_domain = nla_get_u8(tb_msg[NL80211_ATTR_DFS_REGION]);
200785732ac8SCy Schubert 		nl80211_set_dfs_domain(dfs_domain, &results->dfs_domain);
20085b9c547cSRui Paulo 		wpa_printf(MSG_DEBUG, "nl80211: Regulatory information - country=%s (%s)",
20095b9c547cSRui Paulo 			   (char *) nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]),
20105b9c547cSRui Paulo 			   dfs_domain_name(dfs_domain));
20115b9c547cSRui Paulo 	} else {
20125b9c547cSRui Paulo 		wpa_printf(MSG_DEBUG, "nl80211: Regulatory information - country=%s",
20135b9c547cSRui Paulo 			   (char *) nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]));
20145b9c547cSRui Paulo 	}
20155b9c547cSRui Paulo 
20165b9c547cSRui Paulo 	nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule)
20175b9c547cSRui Paulo 	{
20185b9c547cSRui Paulo 		u32 start, end, max_eirp = 0, max_bw = 0, flags = 0;
20195b9c547cSRui Paulo 		nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX,
20205b9c547cSRui Paulo 			  nla_data(nl_rule), nla_len(nl_rule), reg_policy);
20215b9c547cSRui Paulo 		if (tb_rule[NL80211_ATTR_FREQ_RANGE_START] == NULL ||
20225b9c547cSRui Paulo 		    tb_rule[NL80211_ATTR_FREQ_RANGE_END] == NULL)
20235b9c547cSRui Paulo 			continue;
20245b9c547cSRui Paulo 		start = nla_get_u32(tb_rule[NL80211_ATTR_FREQ_RANGE_START]) / 1000;
20255b9c547cSRui Paulo 		end = nla_get_u32(tb_rule[NL80211_ATTR_FREQ_RANGE_END]) / 1000;
20265b9c547cSRui Paulo 		if (tb_rule[NL80211_ATTR_POWER_RULE_MAX_EIRP])
20275b9c547cSRui Paulo 			max_eirp = nla_get_u32(tb_rule[NL80211_ATTR_POWER_RULE_MAX_EIRP]) / 100;
20285b9c547cSRui Paulo 		if (tb_rule[NL80211_ATTR_FREQ_RANGE_MAX_BW])
20295b9c547cSRui Paulo 			max_bw = nla_get_u32(tb_rule[NL80211_ATTR_FREQ_RANGE_MAX_BW]) / 1000;
20305b9c547cSRui Paulo 		if (tb_rule[NL80211_ATTR_REG_RULE_FLAGS])
20315b9c547cSRui Paulo 			flags = nla_get_u32(tb_rule[NL80211_ATTR_REG_RULE_FLAGS]);
20325b9c547cSRui Paulo 
20335b9c547cSRui Paulo 		wpa_printf(MSG_DEBUG, "nl80211: %u-%u @ %u MHz %u mBm%s%s%s%s%s%s%s%s",
20345b9c547cSRui Paulo 			   start, end, max_bw, max_eirp,
20355b9c547cSRui Paulo 			   flags & NL80211_RRF_NO_OFDM ? " (no OFDM)" : "",
20365b9c547cSRui Paulo 			   flags & NL80211_RRF_NO_CCK ? " (no CCK)" : "",
20375b9c547cSRui Paulo 			   flags & NL80211_RRF_NO_INDOOR ? " (no indoor)" : "",
20385b9c547cSRui Paulo 			   flags & NL80211_RRF_NO_OUTDOOR ? " (no outdoor)" :
20395b9c547cSRui Paulo 			   "",
20405b9c547cSRui Paulo 			   flags & NL80211_RRF_DFS ? " (DFS)" : "",
20415b9c547cSRui Paulo 			   flags & NL80211_RRF_PTP_ONLY ? " (PTP only)" : "",
20425b9c547cSRui Paulo 			   flags & NL80211_RRF_PTMP_ONLY ? " (PTMP only)" : "",
20435b9c547cSRui Paulo 			   flags & NL80211_RRF_NO_IR ? " (no IR)" : "");
20445b9c547cSRui Paulo 		if (max_bw >= 40)
20455b9c547cSRui Paulo 			nl80211_reg_rule_ht40(start, end, results);
20465b9c547cSRui Paulo 		if (tb_rule[NL80211_ATTR_POWER_RULE_MAX_EIRP])
20475b9c547cSRui Paulo 			nl80211_reg_rule_max_eirp(start, end, max_eirp,
20485b9c547cSRui Paulo 						  results);
20495b9c547cSRui Paulo 	}
20505b9c547cSRui Paulo 
20515b9c547cSRui Paulo 	nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule)
20525b9c547cSRui Paulo 	{
20535b9c547cSRui Paulo 		nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX,
20545b9c547cSRui Paulo 			  nla_data(nl_rule), nla_len(nl_rule), reg_policy);
20555b9c547cSRui Paulo 		nl80211_reg_rule_sec(tb_rule, results);
20565b9c547cSRui Paulo 	}
20575b9c547cSRui Paulo 
20585b9c547cSRui Paulo 	nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule)
20595b9c547cSRui Paulo 	{
20605b9c547cSRui Paulo 		nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX,
20615b9c547cSRui Paulo 			  nla_data(nl_rule), nla_len(nl_rule), reg_policy);
20625b9c547cSRui Paulo 		nl80211_reg_rule_vht(tb_rule, results);
20635b9c547cSRui Paulo 	}
20645b9c547cSRui Paulo 
20655b9c547cSRui Paulo 	return NL_SKIP;
20665b9c547cSRui Paulo }
20675b9c547cSRui Paulo 
20685b9c547cSRui Paulo 
20695b9c547cSRui Paulo static int nl80211_set_regulatory_flags(struct wpa_driver_nl80211_data *drv,
20705b9c547cSRui Paulo 					struct phy_info_arg *results)
20715b9c547cSRui Paulo {
20725b9c547cSRui Paulo 	struct nl_msg *msg;
20735b9c547cSRui Paulo 
20745b9c547cSRui Paulo 	msg = nlmsg_alloc();
20755b9c547cSRui Paulo 	if (!msg)
20765b9c547cSRui Paulo 		return -ENOMEM;
20775b9c547cSRui Paulo 
20785b9c547cSRui Paulo 	nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG);
207985732ac8SCy Schubert 	if (drv->capa.flags & WPA_DRIVER_FLAGS_SELF_MANAGED_REGULATORY) {
208085732ac8SCy Schubert 		if (nla_put_u32(msg, NL80211_ATTR_WIPHY, drv->wiphy_idx)) {
208185732ac8SCy Schubert 			nlmsg_free(msg);
208285732ac8SCy Schubert 			return -1;
208385732ac8SCy Schubert 		}
208485732ac8SCy Schubert 	}
208585732ac8SCy Schubert 
20865b9c547cSRui Paulo 	return send_and_recv_msgs(drv, msg, nl80211_get_reg, results);
20875b9c547cSRui Paulo }
20885b9c547cSRui Paulo 
20895b9c547cSRui Paulo 
2090*4bc52338SCy Schubert static const char * modestr(enum hostapd_hw_mode mode)
2091*4bc52338SCy Schubert {
2092*4bc52338SCy Schubert 	switch (mode) {
2093*4bc52338SCy Schubert 	case HOSTAPD_MODE_IEEE80211B:
2094*4bc52338SCy Schubert 		return "802.11b";
2095*4bc52338SCy Schubert 	case HOSTAPD_MODE_IEEE80211G:
2096*4bc52338SCy Schubert 		return "802.11g";
2097*4bc52338SCy Schubert 	case HOSTAPD_MODE_IEEE80211A:
2098*4bc52338SCy Schubert 		return "802.11a";
2099*4bc52338SCy Schubert 	case HOSTAPD_MODE_IEEE80211AD:
2100*4bc52338SCy Schubert 		return "802.11ad";
2101*4bc52338SCy Schubert 	default:
2102*4bc52338SCy Schubert 		return "?";
2103*4bc52338SCy Schubert 	}
2104*4bc52338SCy Schubert }
2105*4bc52338SCy Schubert 
2106*4bc52338SCy Schubert 
2107*4bc52338SCy Schubert static void nl80211_dump_chan_list(struct hostapd_hw_modes *modes,
2108*4bc52338SCy Schubert 				   u16 num_modes)
2109*4bc52338SCy Schubert {
2110*4bc52338SCy Schubert 	int i;
2111*4bc52338SCy Schubert 
2112*4bc52338SCy Schubert 	if (!modes)
2113*4bc52338SCy Schubert 		return;
2114*4bc52338SCy Schubert 
2115*4bc52338SCy Schubert 	for (i = 0; i < num_modes; i++) {
2116*4bc52338SCy Schubert 		struct hostapd_hw_modes *mode = &modes[i];
2117*4bc52338SCy Schubert 		char str[200];
2118*4bc52338SCy Schubert 		char *pos = str;
2119*4bc52338SCy Schubert 		char *end = pos + sizeof(str);
2120*4bc52338SCy Schubert 		int j, res;
2121*4bc52338SCy Schubert 
2122*4bc52338SCy Schubert 		for (j = 0; j < mode->num_channels; j++) {
2123*4bc52338SCy Schubert 			struct hostapd_channel_data *chan = &mode->channels[j];
2124*4bc52338SCy Schubert 
2125*4bc52338SCy Schubert 			res = os_snprintf(pos, end - pos, " %d%s%s%s",
2126*4bc52338SCy Schubert 					  chan->freq,
2127*4bc52338SCy Schubert 					  (chan->flag & HOSTAPD_CHAN_DISABLED) ?
2128*4bc52338SCy Schubert 					  "[DISABLED]" : "",
2129*4bc52338SCy Schubert 					  (chan->flag & HOSTAPD_CHAN_NO_IR) ?
2130*4bc52338SCy Schubert 					  "[NO_IR]" : "",
2131*4bc52338SCy Schubert 					  (chan->flag & HOSTAPD_CHAN_RADAR) ?
2132*4bc52338SCy Schubert 					  "[RADAR]" : "");
2133*4bc52338SCy Schubert 			if (os_snprintf_error(end - pos, res))
2134*4bc52338SCy Schubert 				break;
2135*4bc52338SCy Schubert 			pos += res;
2136*4bc52338SCy Schubert 		}
2137*4bc52338SCy Schubert 
2138*4bc52338SCy Schubert 		*pos = '\0';
2139*4bc52338SCy Schubert 		wpa_printf(MSG_DEBUG, "nl80211: Mode IEEE %s:%s",
2140*4bc52338SCy Schubert 			   modestr(mode->mode), str);
2141*4bc52338SCy Schubert 	}
2142*4bc52338SCy Schubert }
2143*4bc52338SCy Schubert 
2144*4bc52338SCy Schubert 
21455b9c547cSRui Paulo struct hostapd_hw_modes *
214685732ac8SCy Schubert nl80211_get_hw_feature_data(void *priv, u16 *num_modes, u16 *flags,
214785732ac8SCy Schubert 			    u8 *dfs_domain)
21485b9c547cSRui Paulo {
21495b9c547cSRui Paulo 	u32 feat;
21505b9c547cSRui Paulo 	struct i802_bss *bss = priv;
21515b9c547cSRui Paulo 	struct wpa_driver_nl80211_data *drv = bss->drv;
21525b9c547cSRui Paulo 	int nl_flags = 0;
21535b9c547cSRui Paulo 	struct nl_msg *msg;
21545b9c547cSRui Paulo 	struct phy_info_arg result = {
21555b9c547cSRui Paulo 		.num_modes = num_modes,
21565b9c547cSRui Paulo 		.modes = NULL,
21575b9c547cSRui Paulo 		.last_mode = -1,
2158780fb4a2SCy Schubert 		.failed = 0,
215985732ac8SCy Schubert 		.dfs_domain = 0,
21605b9c547cSRui Paulo 	};
21615b9c547cSRui Paulo 
21625b9c547cSRui Paulo 	*num_modes = 0;
21635b9c547cSRui Paulo 	*flags = 0;
216485732ac8SCy Schubert 	*dfs_domain = 0;
21655b9c547cSRui Paulo 
21665b9c547cSRui Paulo 	feat = get_nl80211_protocol_features(drv);
21675b9c547cSRui Paulo 	if (feat & NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)
21685b9c547cSRui Paulo 		nl_flags = NLM_F_DUMP;
21695b9c547cSRui Paulo 	if (!(msg = nl80211_cmd_msg(bss, nl_flags, NL80211_CMD_GET_WIPHY)) ||
21705b9c547cSRui Paulo 	    nla_put_flag(msg, NL80211_ATTR_SPLIT_WIPHY_DUMP)) {
21715b9c547cSRui Paulo 		nlmsg_free(msg);
21725b9c547cSRui Paulo 		return NULL;
21735b9c547cSRui Paulo 	}
21745b9c547cSRui Paulo 
21755b9c547cSRui Paulo 	if (send_and_recv_msgs(drv, msg, phy_info_handler, &result) == 0) {
2176*4bc52338SCy Schubert 		struct hostapd_hw_modes *modes;
2177*4bc52338SCy Schubert 
21785b9c547cSRui Paulo 		nl80211_set_regulatory_flags(drv, &result);
2179780fb4a2SCy Schubert 		if (result.failed) {
2180780fb4a2SCy Schubert 			int i;
2181780fb4a2SCy Schubert 
2182780fb4a2SCy Schubert 			for (i = 0; result.modes && i < *num_modes; i++) {
2183780fb4a2SCy Schubert 				os_free(result.modes[i].channels);
2184780fb4a2SCy Schubert 				os_free(result.modes[i].rates);
2185780fb4a2SCy Schubert 			}
2186780fb4a2SCy Schubert 			os_free(result.modes);
218785732ac8SCy Schubert 			*num_modes = 0;
2188780fb4a2SCy Schubert 			return NULL;
2189780fb4a2SCy Schubert 		}
219085732ac8SCy Schubert 
219185732ac8SCy Schubert 		*dfs_domain = result.dfs_domain;
219285732ac8SCy Schubert 
2193*4bc52338SCy Schubert 		modes = wpa_driver_nl80211_postprocess_modes(result.modes,
21945b9c547cSRui Paulo 							     num_modes);
2195*4bc52338SCy Schubert 		nl80211_dump_chan_list(modes, *num_modes);
2196*4bc52338SCy Schubert 		return modes;
21975b9c547cSRui Paulo 	}
21985b9c547cSRui Paulo 
21995b9c547cSRui Paulo 	return NULL;
22005b9c547cSRui Paulo }
2201