19a53cbbeSchristos /*
29a53cbbeSchristos  * Driver interaction with Linux nl80211/cfg80211 - Capabilities
39a53cbbeSchristos  * Copyright (c) 2002-2015, Jouni Malinen <j@w1.fi>
49a53cbbeSchristos  * Copyright (c) 2007, Johannes Berg <johannes@sipsolutions.net>
59a53cbbeSchristos  * Copyright (c) 2009-2010, Atheros Communications
69a53cbbeSchristos  *
79a53cbbeSchristos  * This software may be distributed under the terms of the BSD license.
89a53cbbeSchristos  * See README for more details.
99a53cbbeSchristos  */
109a53cbbeSchristos 
119a53cbbeSchristos #include "includes.h"
129a53cbbeSchristos #include <netlink/genl/genl.h>
139a53cbbeSchristos 
149a53cbbeSchristos #include "utils/common.h"
159a53cbbeSchristos #include "common/ieee802_11_common.h"
16ebb5671cSchristos #include "common/wpa_common.h"
179a53cbbeSchristos #include "common/qca-vendor.h"
189a53cbbeSchristos #include "common/qca-vendor-attr.h"
199a53cbbeSchristos #include "driver_nl80211.h"
209a53cbbeSchristos 
219a53cbbeSchristos 
protocol_feature_handler(struct nl_msg * msg,void * arg)229a53cbbeSchristos static int protocol_feature_handler(struct nl_msg *msg, void *arg)
239a53cbbeSchristos {
249a53cbbeSchristos 	u32 *feat = arg;
259a53cbbeSchristos 	struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
269a53cbbeSchristos 	struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
279a53cbbeSchristos 
289a53cbbeSchristos 	nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
299a53cbbeSchristos 		  genlmsg_attrlen(gnlh, 0), NULL);
309a53cbbeSchristos 
319a53cbbeSchristos 	if (tb_msg[NL80211_ATTR_PROTOCOL_FEATURES])
329a53cbbeSchristos 		*feat = nla_get_u32(tb_msg[NL80211_ATTR_PROTOCOL_FEATURES]);
339a53cbbeSchristos 
349a53cbbeSchristos 	return NL_SKIP;
359a53cbbeSchristos }
369a53cbbeSchristos 
379a53cbbeSchristos 
get_nl80211_protocol_features(struct wpa_driver_nl80211_data * drv)389a53cbbeSchristos static u32 get_nl80211_protocol_features(struct wpa_driver_nl80211_data *drv)
399a53cbbeSchristos {
409a53cbbeSchristos 	u32 feat = 0;
419a53cbbeSchristos 	struct nl_msg *msg;
429a53cbbeSchristos 
439a53cbbeSchristos 	msg = nlmsg_alloc();
449a53cbbeSchristos 	if (!msg)
459a53cbbeSchristos 		return 0;
469a53cbbeSchristos 
479a53cbbeSchristos 	if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_PROTOCOL_FEATURES)) {
489a53cbbeSchristos 		nlmsg_free(msg);
499a53cbbeSchristos 		return 0;
509a53cbbeSchristos 	}
519a53cbbeSchristos 
529a53cbbeSchristos 	if (send_and_recv_msgs(drv, msg, protocol_feature_handler, &feat) == 0)
539a53cbbeSchristos 		return feat;
549a53cbbeSchristos 
559a53cbbeSchristos 	return 0;
569a53cbbeSchristos }
579a53cbbeSchristos 
589a53cbbeSchristos 
599a53cbbeSchristos struct wiphy_info_data {
609a53cbbeSchristos 	struct wpa_driver_nl80211_data *drv;
619a53cbbeSchristos 	struct wpa_driver_capa *capa;
629a53cbbeSchristos 
639a53cbbeSchristos 	unsigned int num_multichan_concurrent;
649a53cbbeSchristos 
659a53cbbeSchristos 	unsigned int error:1;
669a53cbbeSchristos 	unsigned int device_ap_sme:1;
679a53cbbeSchristos 	unsigned int poll_command_supported:1;
689a53cbbeSchristos 	unsigned int data_tx_status:1;
699a53cbbeSchristos 	unsigned int auth_supported:1;
709a53cbbeSchristos 	unsigned int connect_supported:1;
719a53cbbeSchristos 	unsigned int p2p_go_supported:1;
729a53cbbeSchristos 	unsigned int p2p_client_supported:1;
739a53cbbeSchristos 	unsigned int p2p_go_ctwindow_supported:1;
749a53cbbeSchristos 	unsigned int p2p_concurrent:1;
759a53cbbeSchristos 	unsigned int channel_switch_supported:1;
769a53cbbeSchristos 	unsigned int set_qos_map_supported:1;
779a53cbbeSchristos 	unsigned int have_low_prio_scan:1;
789a53cbbeSchristos 	unsigned int wmm_ac_supported:1;
799a53cbbeSchristos 	unsigned int mac_addr_rand_scan_supported:1;
809a53cbbeSchristos 	unsigned int mac_addr_rand_sched_scan_supported:1;
819a53cbbeSchristos };
829a53cbbeSchristos 
839a53cbbeSchristos 
probe_resp_offload_support(int supp_protocols)849a53cbbeSchristos static unsigned int probe_resp_offload_support(int supp_protocols)
859a53cbbeSchristos {
869a53cbbeSchristos 	unsigned int prot = 0;
879a53cbbeSchristos 
889a53cbbeSchristos 	if (supp_protocols & NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS)
899a53cbbeSchristos 		prot |= WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS;
909a53cbbeSchristos 	if (supp_protocols & NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2)
919a53cbbeSchristos 		prot |= WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2;
929a53cbbeSchristos 	if (supp_protocols & NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P)
939a53cbbeSchristos 		prot |= WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P;
949a53cbbeSchristos 	if (supp_protocols & NL80211_PROBE_RESP_OFFLOAD_SUPPORT_80211U)
959a53cbbeSchristos 		prot |= WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING;
969a53cbbeSchristos 
979a53cbbeSchristos 	return prot;
989a53cbbeSchristos }
999a53cbbeSchristos 
1009a53cbbeSchristos 
wiphy_info_supported_iftypes(struct wiphy_info_data * info,struct nlattr * tb)1019a53cbbeSchristos static void wiphy_info_supported_iftypes(struct wiphy_info_data *info,
1029a53cbbeSchristos 					 struct nlattr *tb)
1039a53cbbeSchristos {
1049a53cbbeSchristos 	struct nlattr *nl_mode;
1059a53cbbeSchristos 	int i;
1069a53cbbeSchristos 
1079a53cbbeSchristos 	if (tb == NULL)
1089a53cbbeSchristos 		return;
1099a53cbbeSchristos 
1109a53cbbeSchristos 	nla_for_each_nested(nl_mode, tb, i) {
1119a53cbbeSchristos 		switch (nla_type(nl_mode)) {
1129a53cbbeSchristos 		case NL80211_IFTYPE_AP:
1139a53cbbeSchristos 			info->capa->flags |= WPA_DRIVER_FLAGS_AP;
1149a53cbbeSchristos 			break;
1159a53cbbeSchristos 		case NL80211_IFTYPE_MESH_POINT:
1169a53cbbeSchristos 			info->capa->flags |= WPA_DRIVER_FLAGS_MESH;
1179a53cbbeSchristos 			break;
1189a53cbbeSchristos 		case NL80211_IFTYPE_ADHOC:
1199a53cbbeSchristos 			info->capa->flags |= WPA_DRIVER_FLAGS_IBSS;
1209a53cbbeSchristos 			break;
1219a53cbbeSchristos 		case NL80211_IFTYPE_P2P_DEVICE:
1229a53cbbeSchristos 			info->capa->flags |=
1239a53cbbeSchristos 				WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE;
1249a53cbbeSchristos 			break;
1259a53cbbeSchristos 		case NL80211_IFTYPE_P2P_GO:
1269a53cbbeSchristos 			info->p2p_go_supported = 1;
1279a53cbbeSchristos 			break;
1289a53cbbeSchristos 		case NL80211_IFTYPE_P2P_CLIENT:
1299a53cbbeSchristos 			info->p2p_client_supported = 1;
1309a53cbbeSchristos 			break;
1319a53cbbeSchristos 		}
1329a53cbbeSchristos 	}
1339a53cbbeSchristos }
1349a53cbbeSchristos 
1359a53cbbeSchristos 
wiphy_info_iface_comb_process(struct wiphy_info_data * info,struct nlattr * nl_combi)1369a53cbbeSchristos static int wiphy_info_iface_comb_process(struct wiphy_info_data *info,
1379a53cbbeSchristos 					 struct nlattr *nl_combi)
1389a53cbbeSchristos {
1399a53cbbeSchristos 	struct nlattr *tb_comb[NUM_NL80211_IFACE_COMB];
1409a53cbbeSchristos 	struct nlattr *tb_limit[NUM_NL80211_IFACE_LIMIT];
1419a53cbbeSchristos 	struct nlattr *nl_limit, *nl_mode;
1429a53cbbeSchristos 	int err, rem_limit, rem_mode;
1439a53cbbeSchristos 	int combination_has_p2p = 0, combination_has_mgd = 0;
1449a53cbbeSchristos 	static struct nla_policy
1459a53cbbeSchristos 	iface_combination_policy[NUM_NL80211_IFACE_COMB] = {
1469a53cbbeSchristos 		[NL80211_IFACE_COMB_LIMITS] = { .type = NLA_NESTED },
1479a53cbbeSchristos 		[NL80211_IFACE_COMB_MAXNUM] = { .type = NLA_U32 },
1489a53cbbeSchristos 		[NL80211_IFACE_COMB_STA_AP_BI_MATCH] = { .type = NLA_FLAG },
1499a53cbbeSchristos 		[NL80211_IFACE_COMB_NUM_CHANNELS] = { .type = NLA_U32 },
1509a53cbbeSchristos 		[NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS] = { .type = NLA_U32 },
1519a53cbbeSchristos 	},
1529a53cbbeSchristos 	iface_limit_policy[NUM_NL80211_IFACE_LIMIT] = {
1539a53cbbeSchristos 		[NL80211_IFACE_LIMIT_TYPES] = { .type = NLA_NESTED },
1549a53cbbeSchristos 		[NL80211_IFACE_LIMIT_MAX] = { .type = NLA_U32 },
1559a53cbbeSchristos 	};
1569a53cbbeSchristos 
1579a53cbbeSchristos 	err = nla_parse_nested(tb_comb, MAX_NL80211_IFACE_COMB,
1589a53cbbeSchristos 			       nl_combi, iface_combination_policy);
1599a53cbbeSchristos 	if (err || !tb_comb[NL80211_IFACE_COMB_LIMITS] ||
1609a53cbbeSchristos 	    !tb_comb[NL80211_IFACE_COMB_MAXNUM] ||
1619a53cbbeSchristos 	    !tb_comb[NL80211_IFACE_COMB_NUM_CHANNELS])
1629a53cbbeSchristos 		return 0; /* broken combination */
1639a53cbbeSchristos 
1649a53cbbeSchristos 	if (tb_comb[NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS])
1659a53cbbeSchristos 		info->capa->flags |= WPA_DRIVER_FLAGS_RADAR;
1669a53cbbeSchristos 
1679a53cbbeSchristos 	nla_for_each_nested(nl_limit, tb_comb[NL80211_IFACE_COMB_LIMITS],
1689a53cbbeSchristos 			    rem_limit) {
1699a53cbbeSchristos 		err = nla_parse_nested(tb_limit, MAX_NL80211_IFACE_LIMIT,
1709a53cbbeSchristos 				       nl_limit, iface_limit_policy);
1719a53cbbeSchristos 		if (err || !tb_limit[NL80211_IFACE_LIMIT_TYPES])
1729a53cbbeSchristos 			return 0; /* broken combination */
1739a53cbbeSchristos 
1749a53cbbeSchristos 		nla_for_each_nested(nl_mode,
1759a53cbbeSchristos 				    tb_limit[NL80211_IFACE_LIMIT_TYPES],
1769a53cbbeSchristos 				    rem_mode) {
1779a53cbbeSchristos 			int ift = nla_type(nl_mode);
1789a53cbbeSchristos 			if (ift == NL80211_IFTYPE_P2P_GO ||
1799a53cbbeSchristos 			    ift == NL80211_IFTYPE_P2P_CLIENT)
1809a53cbbeSchristos 				combination_has_p2p = 1;
1819a53cbbeSchristos 			if (ift == NL80211_IFTYPE_STATION)
1829a53cbbeSchristos 				combination_has_mgd = 1;
1839a53cbbeSchristos 		}
1849a53cbbeSchristos 		if (combination_has_p2p && combination_has_mgd)
1859a53cbbeSchristos 			break;
1869a53cbbeSchristos 	}
1879a53cbbeSchristos 
1889a53cbbeSchristos 	if (combination_has_p2p && combination_has_mgd) {
1899a53cbbeSchristos 		unsigned int num_channels =
1909a53cbbeSchristos 			nla_get_u32(tb_comb[NL80211_IFACE_COMB_NUM_CHANNELS]);
1919a53cbbeSchristos 
1929a53cbbeSchristos 		info->p2p_concurrent = 1;
1939a53cbbeSchristos 		if (info->num_multichan_concurrent < num_channels)
1949a53cbbeSchristos 			info->num_multichan_concurrent = num_channels;
1959a53cbbeSchristos 	}
1969a53cbbeSchristos 
1979a53cbbeSchristos 	return 0;
1989a53cbbeSchristos }
1999a53cbbeSchristos 
2009a53cbbeSchristos 
wiphy_info_iface_comb(struct wiphy_info_data * info,struct nlattr * tb)2019a53cbbeSchristos static void wiphy_info_iface_comb(struct wiphy_info_data *info,
2029a53cbbeSchristos 				  struct nlattr *tb)
2039a53cbbeSchristos {
2049a53cbbeSchristos 	struct nlattr *nl_combi;
2059a53cbbeSchristos 	int rem_combi;
2069a53cbbeSchristos 
2079a53cbbeSchristos 	if (tb == NULL)
2089a53cbbeSchristos 		return;
2099a53cbbeSchristos 
2109a53cbbeSchristos 	nla_for_each_nested(nl_combi, tb, rem_combi) {
2119a53cbbeSchristos 		if (wiphy_info_iface_comb_process(info, nl_combi) > 0)
2129a53cbbeSchristos 			break;
2139a53cbbeSchristos 	}
2149a53cbbeSchristos }
2159a53cbbeSchristos 
2169a53cbbeSchristos 
wiphy_info_supp_cmds(struct wiphy_info_data * info,struct nlattr * tb)2179a53cbbeSchristos static void wiphy_info_supp_cmds(struct wiphy_info_data *info,
2189a53cbbeSchristos 				 struct nlattr *tb)
2199a53cbbeSchristos {
2209a53cbbeSchristos 	struct nlattr *nl_cmd;
2219a53cbbeSchristos 	int i;
2229a53cbbeSchristos 
2239a53cbbeSchristos 	if (tb == NULL)
2249a53cbbeSchristos 		return;
2259a53cbbeSchristos 
2269a53cbbeSchristos 	nla_for_each_nested(nl_cmd, tb, i) {
2279a53cbbeSchristos 		switch (nla_get_u32(nl_cmd)) {
2289a53cbbeSchristos 		case NL80211_CMD_AUTHENTICATE:
2299a53cbbeSchristos 			info->auth_supported = 1;
2309a53cbbeSchristos 			break;
2319a53cbbeSchristos 		case NL80211_CMD_CONNECT:
2329a53cbbeSchristos 			info->connect_supported = 1;
2339a53cbbeSchristos 			break;
2349a53cbbeSchristos 		case NL80211_CMD_START_SCHED_SCAN:
2359a53cbbeSchristos 			info->capa->sched_scan_supported = 1;
2369a53cbbeSchristos 			break;
2379a53cbbeSchristos 		case NL80211_CMD_PROBE_CLIENT:
2389a53cbbeSchristos 			info->poll_command_supported = 1;
2399a53cbbeSchristos 			break;
2409a53cbbeSchristos 		case NL80211_CMD_CHANNEL_SWITCH:
2419a53cbbeSchristos 			info->channel_switch_supported = 1;
2429a53cbbeSchristos 			break;
2439a53cbbeSchristos 		case NL80211_CMD_SET_QOS_MAP:
2449a53cbbeSchristos 			info->set_qos_map_supported = 1;
2459a53cbbeSchristos 			break;
2469a53cbbeSchristos 		}
2479a53cbbeSchristos 	}
2489a53cbbeSchristos }
2499a53cbbeSchristos 
2509a53cbbeSchristos 
wiphy_info_cipher_suites(struct wiphy_info_data * info,struct nlattr * tb)2519a53cbbeSchristos static void wiphy_info_cipher_suites(struct wiphy_info_data *info,
2529a53cbbeSchristos 				     struct nlattr *tb)
2539a53cbbeSchristos {
2549a53cbbeSchristos 	int i, num;
2559a53cbbeSchristos 	u32 *ciphers;
2569a53cbbeSchristos 
2579a53cbbeSchristos 	if (tb == NULL)
2589a53cbbeSchristos 		return;
2599a53cbbeSchristos 
2609a53cbbeSchristos 	num = nla_len(tb) / sizeof(u32);
2619a53cbbeSchristos 	ciphers = nla_data(tb);
2629a53cbbeSchristos 	for (i = 0; i < num; i++) {
2639a53cbbeSchristos 		u32 c = ciphers[i];
2649a53cbbeSchristos 
2659a53cbbeSchristos 		wpa_printf(MSG_DEBUG, "nl80211: Supported cipher %02x-%02x-%02x:%d",
2669a53cbbeSchristos 			   c >> 24, (c >> 16) & 0xff,
2679a53cbbeSchristos 			   (c >> 8) & 0xff, c & 0xff);
2689a53cbbeSchristos 		switch (c) {
269ebb5671cSchristos 		case RSN_CIPHER_SUITE_CCMP_256:
2709a53cbbeSchristos 			info->capa->enc |= WPA_DRIVER_CAPA_ENC_CCMP_256;
2719a53cbbeSchristos 			break;
272ebb5671cSchristos 		case RSN_CIPHER_SUITE_GCMP_256:
2739a53cbbeSchristos 			info->capa->enc |= WPA_DRIVER_CAPA_ENC_GCMP_256;
2749a53cbbeSchristos 			break;
275ebb5671cSchristos 		case RSN_CIPHER_SUITE_CCMP:
2769a53cbbeSchristos 			info->capa->enc |= WPA_DRIVER_CAPA_ENC_CCMP;
2779a53cbbeSchristos 			break;
278ebb5671cSchristos 		case RSN_CIPHER_SUITE_GCMP:
2799a53cbbeSchristos 			info->capa->enc |= WPA_DRIVER_CAPA_ENC_GCMP;
2809a53cbbeSchristos 			break;
281ebb5671cSchristos 		case RSN_CIPHER_SUITE_TKIP:
2829a53cbbeSchristos 			info->capa->enc |= WPA_DRIVER_CAPA_ENC_TKIP;
2839a53cbbeSchristos 			break;
284ebb5671cSchristos 		case RSN_CIPHER_SUITE_WEP104:
2859a53cbbeSchristos 			info->capa->enc |= WPA_DRIVER_CAPA_ENC_WEP104;
2869a53cbbeSchristos 			break;
287ebb5671cSchristos 		case RSN_CIPHER_SUITE_WEP40:
2889a53cbbeSchristos 			info->capa->enc |= WPA_DRIVER_CAPA_ENC_WEP40;
2899a53cbbeSchristos 			break;
290ebb5671cSchristos 		case RSN_CIPHER_SUITE_AES_128_CMAC:
2919a53cbbeSchristos 			info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP;
2929a53cbbeSchristos 			break;
293ebb5671cSchristos 		case RSN_CIPHER_SUITE_BIP_GMAC_128:
2949a53cbbeSchristos 			info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP_GMAC_128;
2959a53cbbeSchristos 			break;
296ebb5671cSchristos 		case RSN_CIPHER_SUITE_BIP_GMAC_256:
2979a53cbbeSchristos 			info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP_GMAC_256;
2989a53cbbeSchristos 			break;
299ebb5671cSchristos 		case RSN_CIPHER_SUITE_BIP_CMAC_256:
3009a53cbbeSchristos 			info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP_CMAC_256;
3019a53cbbeSchristos 			break;
302ebb5671cSchristos 		case RSN_CIPHER_SUITE_NO_GROUP_ADDRESSED:
3039a53cbbeSchristos 			info->capa->enc |= WPA_DRIVER_CAPA_ENC_GTK_NOT_USED;
3049a53cbbeSchristos 			break;
3059a53cbbeSchristos 		}
3069a53cbbeSchristos 	}
3079a53cbbeSchristos }
3089a53cbbeSchristos 
3099a53cbbeSchristos 
wiphy_info_max_roc(struct wpa_driver_capa * capa,struct nlattr * tb)3109a53cbbeSchristos static void wiphy_info_max_roc(struct wpa_driver_capa *capa,
3119a53cbbeSchristos 			       struct nlattr *tb)
3129a53cbbeSchristos {
3139a53cbbeSchristos 	if (tb)
3149a53cbbeSchristos 		capa->max_remain_on_chan = nla_get_u32(tb);
3159a53cbbeSchristos }
3169a53cbbeSchristos 
3179a53cbbeSchristos 
wiphy_info_tdls(struct wpa_driver_capa * capa,struct nlattr * tdls,struct nlattr * ext_setup)3189a53cbbeSchristos static void wiphy_info_tdls(struct wpa_driver_capa *capa, struct nlattr *tdls,
3199a53cbbeSchristos 			    struct nlattr *ext_setup)
3209a53cbbeSchristos {
3219a53cbbeSchristos 	if (tdls == NULL)
3229a53cbbeSchristos 		return;
3239a53cbbeSchristos 
3249a53cbbeSchristos 	wpa_printf(MSG_DEBUG, "nl80211: TDLS supported");
3259a53cbbeSchristos 	capa->flags |= WPA_DRIVER_FLAGS_TDLS_SUPPORT;
3269a53cbbeSchristos 
3279a53cbbeSchristos 	if (ext_setup) {
3289a53cbbeSchristos 		wpa_printf(MSG_DEBUG, "nl80211: TDLS external setup");
3299a53cbbeSchristos 		capa->flags |= WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP;
3309a53cbbeSchristos 	}
3319a53cbbeSchristos }
3329a53cbbeSchristos 
3339a53cbbeSchristos 
ext_feature_isset(const u8 * ext_features,int ext_features_len,enum nl80211_ext_feature_index ftidx)334928750b6Schristos static int ext_feature_isset(const u8 *ext_features, int ext_features_len,
335928750b6Schristos 			     enum nl80211_ext_feature_index ftidx)
336928750b6Schristos {
337928750b6Schristos 	u8 ft_byte;
338928750b6Schristos 
339928750b6Schristos 	if ((int) ftidx / 8 >= ext_features_len)
340928750b6Schristos 		return 0;
341928750b6Schristos 
342928750b6Schristos 	ft_byte = ext_features[ftidx / 8];
343928750b6Schristos 	return (ft_byte & BIT(ftidx % 8)) != 0;
344928750b6Schristos }
345928750b6Schristos 
346928750b6Schristos 
wiphy_info_ext_feature_flags(struct wiphy_info_data * info,struct nlattr * tb)347928750b6Schristos static void wiphy_info_ext_feature_flags(struct wiphy_info_data *info,
348928750b6Schristos 					 struct nlattr *tb)
349928750b6Schristos {
350928750b6Schristos 	struct wpa_driver_capa *capa = info->capa;
351928750b6Schristos 	u8 *ext_features;
352928750b6Schristos 	int len;
353928750b6Schristos 
354928750b6Schristos 	if (tb == NULL)
355928750b6Schristos 		return;
356928750b6Schristos 
357928750b6Schristos 	ext_features = nla_data(tb);
358928750b6Schristos 	len = nla_len(tb);
359928750b6Schristos 
360928750b6Schristos 	if (ext_feature_isset(ext_features, len, NL80211_EXT_FEATURE_VHT_IBSS))
361928750b6Schristos 		capa->flags |= WPA_DRIVER_FLAGS_VHT_IBSS;
362928750b6Schristos 
363928750b6Schristos 	if (ext_feature_isset(ext_features, len, NL80211_EXT_FEATURE_RRM))
364928750b6Schristos 		capa->rrm_flags |= WPA_DRIVER_FLAGS_SUPPORT_RRM;
365ebb5671cSchristos 
366ebb5671cSchristos 	if (ext_feature_isset(ext_features, len, NL80211_EXT_FEATURE_FILS_STA))
367ebb5671cSchristos 		capa->flags |= WPA_DRIVER_FLAGS_SUPPORT_FILS;
368ebb5671cSchristos 
369ebb5671cSchristos 	if (ext_feature_isset(ext_features, len,
370ebb5671cSchristos 			      NL80211_EXT_FEATURE_BEACON_RATE_LEGACY))
371ebb5671cSchristos 		capa->flags |= WPA_DRIVER_FLAGS_BEACON_RATE_LEGACY;
372ebb5671cSchristos 
373ebb5671cSchristos 	if (ext_feature_isset(ext_features, len,
374ebb5671cSchristos 			      NL80211_EXT_FEATURE_BEACON_RATE_HT))
375ebb5671cSchristos 		capa->flags |= WPA_DRIVER_FLAGS_BEACON_RATE_HT;
376ebb5671cSchristos 
377ebb5671cSchristos 	if (ext_feature_isset(ext_features, len,
378ebb5671cSchristos 			      NL80211_EXT_FEATURE_BEACON_RATE_VHT))
379ebb5671cSchristos 		capa->flags |= WPA_DRIVER_FLAGS_BEACON_RATE_VHT;
380ebb5671cSchristos 
381ebb5671cSchristos 	if (ext_feature_isset(ext_features, len,
382ebb5671cSchristos 			      NL80211_EXT_FEATURE_SET_SCAN_DWELL))
383ebb5671cSchristos 		capa->rrm_flags |= WPA_DRIVER_FLAGS_SUPPORT_SET_SCAN_DWELL;
384ebb5671cSchristos 
385ebb5671cSchristos 	if (ext_feature_isset(ext_features, len,
386ebb5671cSchristos 			      NL80211_EXT_FEATURE_SCAN_START_TIME) &&
387ebb5671cSchristos 	    ext_feature_isset(ext_features, len,
388ebb5671cSchristos 			      NL80211_EXT_FEATURE_BSS_PARENT_TSF) &&
389ebb5671cSchristos 	    ext_feature_isset(ext_features, len,
390ebb5671cSchristos 			      NL80211_EXT_FEATURE_SET_SCAN_DWELL))
391ebb5671cSchristos 		capa->rrm_flags |= WPA_DRIVER_FLAGS_SUPPORT_BEACON_REPORT;
392ebb5671cSchristos 	if (ext_feature_isset(ext_features, len,
393ebb5671cSchristos 			      NL80211_EXT_FEATURE_MGMT_TX_RANDOM_TA))
394ebb5671cSchristos 		capa->flags |= WPA_DRIVER_FLAGS_MGMT_TX_RANDOM_TA;
395ebb5671cSchristos 	if (ext_feature_isset(ext_features, len,
396ebb5671cSchristos 			      NL80211_EXT_FEATURE_MGMT_TX_RANDOM_TA_CONNECTED))
397ebb5671cSchristos 		capa->flags |= WPA_DRIVER_FLAGS_MGMT_TX_RANDOM_TA_CONNECTED;
398ebb5671cSchristos 	if (ext_feature_isset(ext_features, len,
399ebb5671cSchristos 			      NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI))
400ebb5671cSchristos 		capa->flags |= WPA_DRIVER_FLAGS_SCHED_SCAN_RELATIVE_RSSI;
401ebb5671cSchristos 	if (ext_feature_isset(ext_features, len,
402ebb5671cSchristos 			      NL80211_EXT_FEATURE_FILS_SK_OFFLOAD))
403ebb5671cSchristos 		capa->flags |= WPA_DRIVER_FLAGS_FILS_SK_OFFLOAD;
404ebb5671cSchristos 
405ebb5671cSchristos 	if (ext_feature_isset(ext_features, len,
406*0d69f216Schristos 			      NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK))
407*0d69f216Schristos 		capa->flags |= WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK;
408*0d69f216Schristos 	if (ext_feature_isset(ext_features, len,
409ebb5671cSchristos 			      NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
410*0d69f216Schristos 		capa->flags |= WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X;
411ebb5671cSchristos 
412ebb5671cSchristos 	if (ext_feature_isset(ext_features, len,
413ebb5671cSchristos 			      NL80211_EXT_FEATURE_MFP_OPTIONAL))
414ebb5671cSchristos 		capa->flags |= WPA_DRIVER_FLAGS_MFP_OPTIONAL;
415ebb5671cSchristos 
416ebb5671cSchristos 	if (ext_feature_isset(ext_features, len,
417ebb5671cSchristos 			      NL80211_EXT_FEATURE_DFS_OFFLOAD))
418ebb5671cSchristos 		capa->flags |= WPA_DRIVER_FLAGS_DFS_OFFLOAD;
419ebb5671cSchristos 
420ebb5671cSchristos #ifdef CONFIG_MBO
421ebb5671cSchristos 	if (ext_feature_isset(ext_features, len,
422ebb5671cSchristos 			      NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME) &&
423ebb5671cSchristos 	    ext_feature_isset(ext_features, len,
424ebb5671cSchristos 			      NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP) &&
425ebb5671cSchristos 	    ext_feature_isset(ext_features, len,
426ebb5671cSchristos 			      NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE) &&
427ebb5671cSchristos 	    ext_feature_isset(
428ebb5671cSchristos 		    ext_features, len,
429ebb5671cSchristos 		    NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION))
430ebb5671cSchristos 		capa->flags |= WPA_DRIVER_FLAGS_OCE_STA;
431ebb5671cSchristos #endif /* CONFIG_MBO */
432*0d69f216Schristos 
433*0d69f216Schristos 	if (ext_feature_isset(ext_features, len,
434*0d69f216Schristos 			      NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER))
435*0d69f216Schristos 		capa->flags |= WPA_DRIVER_FLAGS_FTM_RESPONDER;
436928750b6Schristos }
437928750b6Schristos 
438928750b6Schristos 
wiphy_info_feature_flags(struct wiphy_info_data * info,struct nlattr * tb)4399a53cbbeSchristos static void wiphy_info_feature_flags(struct wiphy_info_data *info,
4409a53cbbeSchristos 				     struct nlattr *tb)
4419a53cbbeSchristos {
4429a53cbbeSchristos 	u32 flags;
4439a53cbbeSchristos 	struct wpa_driver_capa *capa = info->capa;
4449a53cbbeSchristos 
4459a53cbbeSchristos 	if (tb == NULL)
4469a53cbbeSchristos 		return;
4479a53cbbeSchristos 
4489a53cbbeSchristos 	flags = nla_get_u32(tb);
4499a53cbbeSchristos 
4509a53cbbeSchristos 	if (flags & NL80211_FEATURE_SK_TX_STATUS)
4519a53cbbeSchristos 		info->data_tx_status = 1;
4529a53cbbeSchristos 
4539a53cbbeSchristos 	if (flags & NL80211_FEATURE_INACTIVITY_TIMER)
4549a53cbbeSchristos 		capa->flags |= WPA_DRIVER_FLAGS_INACTIVITY_TIMER;
4559a53cbbeSchristos 
4569a53cbbeSchristos 	if (flags & NL80211_FEATURE_SAE)
4579a53cbbeSchristos 		capa->flags |= WPA_DRIVER_FLAGS_SAE;
4589a53cbbeSchristos 
4599a53cbbeSchristos 	if (flags & NL80211_FEATURE_NEED_OBSS_SCAN)
4609a53cbbeSchristos 		capa->flags |= WPA_DRIVER_FLAGS_OBSS_SCAN;
4619a53cbbeSchristos 
4629a53cbbeSchristos 	if (flags & NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)
4639a53cbbeSchristos 		capa->flags |= WPA_DRIVER_FLAGS_HT_2040_COEX;
4649a53cbbeSchristos 
4659a53cbbeSchristos 	if (flags & NL80211_FEATURE_TDLS_CHANNEL_SWITCH) {
4669a53cbbeSchristos 		wpa_printf(MSG_DEBUG, "nl80211: TDLS channel switch");
4679a53cbbeSchristos 		capa->flags |= WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH;
4689a53cbbeSchristos 	}
4699a53cbbeSchristos 
4709a53cbbeSchristos 	if (flags & NL80211_FEATURE_P2P_GO_CTWIN)
4719a53cbbeSchristos 		info->p2p_go_ctwindow_supported = 1;
4729a53cbbeSchristos 
4739a53cbbeSchristos 	if (flags & NL80211_FEATURE_LOW_PRIORITY_SCAN)
4749a53cbbeSchristos 		info->have_low_prio_scan = 1;
4759a53cbbeSchristos 
4769a53cbbeSchristos 	if (flags & NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)
4779a53cbbeSchristos 		info->mac_addr_rand_scan_supported = 1;
4789a53cbbeSchristos 
4799a53cbbeSchristos 	if (flags & NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR)
4809a53cbbeSchristos 		info->mac_addr_rand_sched_scan_supported = 1;
4819a53cbbeSchristos 
4829a53cbbeSchristos 	if (flags & NL80211_FEATURE_STATIC_SMPS)
4839a53cbbeSchristos 		capa->smps_modes |= WPA_DRIVER_SMPS_MODE_STATIC;
4849a53cbbeSchristos 
4859a53cbbeSchristos 	if (flags & NL80211_FEATURE_DYNAMIC_SMPS)
4869a53cbbeSchristos 		capa->smps_modes |= WPA_DRIVER_SMPS_MODE_DYNAMIC;
4879a53cbbeSchristos 
4889a53cbbeSchristos 	if (flags & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
4899a53cbbeSchristos 		info->wmm_ac_supported = 1;
4909a53cbbeSchristos 
4919a53cbbeSchristos 	if (flags & NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES)
4929a53cbbeSchristos 		capa->rrm_flags |= WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES;
4939a53cbbeSchristos 
4949a53cbbeSchristos 	if (flags & NL80211_FEATURE_WFA_TPC_IE_IN_PROBES)
4959a53cbbeSchristos 		capa->rrm_flags |= WPA_DRIVER_FLAGS_WFA_TPC_IE_IN_PROBES;
4969a53cbbeSchristos 
4979a53cbbeSchristos 	if (flags & NL80211_FEATURE_QUIET)
4989a53cbbeSchristos 		capa->rrm_flags |= WPA_DRIVER_FLAGS_QUIET;
4999a53cbbeSchristos 
5009a53cbbeSchristos 	if (flags & NL80211_FEATURE_TX_POWER_INSERTION)
5019a53cbbeSchristos 		capa->rrm_flags |= WPA_DRIVER_FLAGS_TX_POWER_INSERTION;
5029a53cbbeSchristos 
5039a53cbbeSchristos 	if (flags & NL80211_FEATURE_HT_IBSS)
5049a53cbbeSchristos 		capa->flags |= WPA_DRIVER_FLAGS_HT_IBSS;
505928750b6Schristos 
506928750b6Schristos 	if (flags & NL80211_FEATURE_FULL_AP_CLIENT_STATE)
507928750b6Schristos 		capa->flags |= WPA_DRIVER_FLAGS_FULL_AP_CLIENT_STATE;
5089a53cbbeSchristos }
5099a53cbbeSchristos 
5109a53cbbeSchristos 
wiphy_info_probe_resp_offload(struct wpa_driver_capa * capa,struct nlattr * tb)5119a53cbbeSchristos static void wiphy_info_probe_resp_offload(struct wpa_driver_capa *capa,
5129a53cbbeSchristos 					  struct nlattr *tb)
5139a53cbbeSchristos {
5149a53cbbeSchristos 	u32 protocols;
5159a53cbbeSchristos 
5169a53cbbeSchristos 	if (tb == NULL)
5179a53cbbeSchristos 		return;
5189a53cbbeSchristos 
5199a53cbbeSchristos 	protocols = nla_get_u32(tb);
5209a53cbbeSchristos 	wpa_printf(MSG_DEBUG, "nl80211: Supports Probe Response offload in AP "
5219a53cbbeSchristos 		   "mode");
5229a53cbbeSchristos 	capa->flags |= WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD;
5239a53cbbeSchristos 	capa->probe_resp_offloads = probe_resp_offload_support(protocols);
5249a53cbbeSchristos }
5259a53cbbeSchristos 
5269a53cbbeSchristos 
wiphy_info_wowlan_triggers(struct wpa_driver_capa * capa,struct nlattr * tb)5279a53cbbeSchristos static void wiphy_info_wowlan_triggers(struct wpa_driver_capa *capa,
5289a53cbbeSchristos 				       struct nlattr *tb)
5299a53cbbeSchristos {
5309a53cbbeSchristos 	struct nlattr *triggers[MAX_NL80211_WOWLAN_TRIG + 1];
5319a53cbbeSchristos 
5329a53cbbeSchristos 	if (tb == NULL)
5339a53cbbeSchristos 		return;
5349a53cbbeSchristos 
5359a53cbbeSchristos 	if (nla_parse_nested(triggers, MAX_NL80211_WOWLAN_TRIG,
5369a53cbbeSchristos 			     tb, NULL))
5379a53cbbeSchristos 		return;
5389a53cbbeSchristos 
5399a53cbbeSchristos 	if (triggers[NL80211_WOWLAN_TRIG_ANY])
5409a53cbbeSchristos 		capa->wowlan_triggers.any = 1;
5419a53cbbeSchristos 	if (triggers[NL80211_WOWLAN_TRIG_DISCONNECT])
5429a53cbbeSchristos 		capa->wowlan_triggers.disconnect = 1;
5439a53cbbeSchristos 	if (triggers[NL80211_WOWLAN_TRIG_MAGIC_PKT])
5449a53cbbeSchristos 		capa->wowlan_triggers.magic_pkt = 1;
5459a53cbbeSchristos 	if (triggers[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE])
5469a53cbbeSchristos 		capa->wowlan_triggers.gtk_rekey_failure = 1;
5479a53cbbeSchristos 	if (triggers[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST])
5489a53cbbeSchristos 		capa->wowlan_triggers.eap_identity_req = 1;
5499a53cbbeSchristos 	if (triggers[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE])
5509a53cbbeSchristos 		capa->wowlan_triggers.four_way_handshake = 1;
5519a53cbbeSchristos 	if (triggers[NL80211_WOWLAN_TRIG_RFKILL_RELEASE])
5529a53cbbeSchristos 		capa->wowlan_triggers.rfkill_release = 1;
5539a53cbbeSchristos }
5549a53cbbeSchristos 
5559a53cbbeSchristos 
wiphy_info_extended_capab(struct wpa_driver_nl80211_data * drv,struct nlattr * tb)556928750b6Schristos static void wiphy_info_extended_capab(struct wpa_driver_nl80211_data *drv,
557928750b6Schristos 				      struct nlattr *tb)
558928750b6Schristos {
559928750b6Schristos 	int rem = 0, i;
560928750b6Schristos 	struct nlattr *tb1[NL80211_ATTR_MAX + 1], *attr;
561928750b6Schristos 
562928750b6Schristos 	if (!tb || drv->num_iface_ext_capa == NL80211_IFTYPE_MAX)
563928750b6Schristos 		return;
564928750b6Schristos 
565928750b6Schristos 	nla_for_each_nested(attr, tb, rem) {
566928750b6Schristos 		unsigned int len;
567928750b6Schristos 		struct drv_nl80211_ext_capa *capa;
568928750b6Schristos 
569928750b6Schristos 		nla_parse(tb1, NL80211_ATTR_MAX, nla_data(attr),
570928750b6Schristos 			  nla_len(attr), NULL);
571928750b6Schristos 
572928750b6Schristos 		if (!tb1[NL80211_ATTR_IFTYPE] ||
573928750b6Schristos 		    !tb1[NL80211_ATTR_EXT_CAPA] ||
574928750b6Schristos 		    !tb1[NL80211_ATTR_EXT_CAPA_MASK])
575928750b6Schristos 			continue;
576928750b6Schristos 
577928750b6Schristos 		capa = &drv->iface_ext_capa[drv->num_iface_ext_capa];
578928750b6Schristos 		capa->iftype = nla_get_u32(tb1[NL80211_ATTR_IFTYPE]);
579928750b6Schristos 		wpa_printf(MSG_DEBUG,
580928750b6Schristos 			   "nl80211: Driver-advertised extended capabilities for interface type %s",
581928750b6Schristos 			   nl80211_iftype_str(capa->iftype));
582928750b6Schristos 
583928750b6Schristos 		len = nla_len(tb1[NL80211_ATTR_EXT_CAPA]);
584ebb5671cSchristos 		capa->ext_capa = os_memdup(nla_data(tb1[NL80211_ATTR_EXT_CAPA]),
585ebb5671cSchristos 					   len);
586928750b6Schristos 		if (!capa->ext_capa)
587928750b6Schristos 			goto err;
588928750b6Schristos 
589928750b6Schristos 		capa->ext_capa_len = len;
590928750b6Schristos 		wpa_hexdump(MSG_DEBUG, "nl80211: Extended capabilities",
591928750b6Schristos 			    capa->ext_capa, capa->ext_capa_len);
592928750b6Schristos 
593928750b6Schristos 		len = nla_len(tb1[NL80211_ATTR_EXT_CAPA_MASK]);
594ebb5671cSchristos 		capa->ext_capa_mask =
595ebb5671cSchristos 			os_memdup(nla_data(tb1[NL80211_ATTR_EXT_CAPA_MASK]),
596ebb5671cSchristos 				  len);
597928750b6Schristos 		if (!capa->ext_capa_mask)
598928750b6Schristos 			goto err;
599928750b6Schristos 
600928750b6Schristos 		wpa_hexdump(MSG_DEBUG, "nl80211: Extended capabilities mask",
601928750b6Schristos 			    capa->ext_capa_mask, capa->ext_capa_len);
602928750b6Schristos 
603928750b6Schristos 		drv->num_iface_ext_capa++;
604928750b6Schristos 		if (drv->num_iface_ext_capa == NL80211_IFTYPE_MAX)
605928750b6Schristos 			break;
606928750b6Schristos 	}
607928750b6Schristos 
608928750b6Schristos 	return;
609928750b6Schristos 
610928750b6Schristos err:
611928750b6Schristos 	/* Cleanup allocated memory on error */
612928750b6Schristos 	for (i = 0; i < NL80211_IFTYPE_MAX; i++) {
613928750b6Schristos 		os_free(drv->iface_ext_capa[i].ext_capa);
614928750b6Schristos 		drv->iface_ext_capa[i].ext_capa = NULL;
615928750b6Schristos 		os_free(drv->iface_ext_capa[i].ext_capa_mask);
616928750b6Schristos 		drv->iface_ext_capa[i].ext_capa_mask = NULL;
617928750b6Schristos 		drv->iface_ext_capa[i].ext_capa_len = 0;
618928750b6Schristos 	}
619928750b6Schristos 	drv->num_iface_ext_capa = 0;
620928750b6Schristos }
621928750b6Schristos 
622928750b6Schristos 
wiphy_info_handler(struct nl_msg * msg,void * arg)6239a53cbbeSchristos static int wiphy_info_handler(struct nl_msg *msg, void *arg)
6249a53cbbeSchristos {
6259a53cbbeSchristos 	struct nlattr *tb[NL80211_ATTR_MAX + 1];
6269a53cbbeSchristos 	struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
6279a53cbbeSchristos 	struct wiphy_info_data *info = arg;
6289a53cbbeSchristos 	struct wpa_driver_capa *capa = info->capa;
6299a53cbbeSchristos 	struct wpa_driver_nl80211_data *drv = info->drv;
6309a53cbbeSchristos 
6319a53cbbeSchristos 	nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
6329a53cbbeSchristos 		  genlmsg_attrlen(gnlh, 0), NULL);
6339a53cbbeSchristos 
634928750b6Schristos 	if (tb[NL80211_ATTR_WIPHY])
635928750b6Schristos 		drv->wiphy_idx = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
636928750b6Schristos 
6379a53cbbeSchristos 	if (tb[NL80211_ATTR_WIPHY_NAME])
6389a53cbbeSchristos 		os_strlcpy(drv->phyname,
6399a53cbbeSchristos 			   nla_get_string(tb[NL80211_ATTR_WIPHY_NAME]),
6409a53cbbeSchristos 			   sizeof(drv->phyname));
6419a53cbbeSchristos 	if (tb[NL80211_ATTR_MAX_NUM_SCAN_SSIDS])
6429a53cbbeSchristos 		capa->max_scan_ssids =
6439a53cbbeSchristos 			nla_get_u8(tb[NL80211_ATTR_MAX_NUM_SCAN_SSIDS]);
6449a53cbbeSchristos 
6459a53cbbeSchristos 	if (tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS])
6469a53cbbeSchristos 		capa->max_sched_scan_ssids =
6479a53cbbeSchristos 			nla_get_u8(tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS]);
6489a53cbbeSchristos 
649928750b6Schristos 	if (tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS] &&
650928750b6Schristos 	    tb[NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL] &&
651928750b6Schristos 	    tb[NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS]) {
652928750b6Schristos 		capa->max_sched_scan_plans =
653928750b6Schristos 			nla_get_u32(tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS]);
654928750b6Schristos 
655928750b6Schristos 		capa->max_sched_scan_plan_interval =
656928750b6Schristos 			nla_get_u32(tb[NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL]);
657928750b6Schristos 
658928750b6Schristos 		capa->max_sched_scan_plan_iterations =
659928750b6Schristos 			nla_get_u32(tb[NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS]);
660928750b6Schristos 	}
661928750b6Schristos 
6629a53cbbeSchristos 	if (tb[NL80211_ATTR_MAX_MATCH_SETS])
6639a53cbbeSchristos 		capa->max_match_sets =
6649a53cbbeSchristos 			nla_get_u8(tb[NL80211_ATTR_MAX_MATCH_SETS]);
6659a53cbbeSchristos 
6669a53cbbeSchristos 	if (tb[NL80211_ATTR_MAC_ACL_MAX])
6679a53cbbeSchristos 		capa->max_acl_mac_addrs =
6689a53cbbeSchristos 			nla_get_u8(tb[NL80211_ATTR_MAC_ACL_MAX]);
6699a53cbbeSchristos 
6709a53cbbeSchristos 	wiphy_info_supported_iftypes(info, tb[NL80211_ATTR_SUPPORTED_IFTYPES]);
6719a53cbbeSchristos 	wiphy_info_iface_comb(info, tb[NL80211_ATTR_INTERFACE_COMBINATIONS]);
6729a53cbbeSchristos 	wiphy_info_supp_cmds(info, tb[NL80211_ATTR_SUPPORTED_COMMANDS]);
6739a53cbbeSchristos 	wiphy_info_cipher_suites(info, tb[NL80211_ATTR_CIPHER_SUITES]);
6749a53cbbeSchristos 
6759a53cbbeSchristos 	if (tb[NL80211_ATTR_OFFCHANNEL_TX_OK]) {
6769a53cbbeSchristos 		wpa_printf(MSG_DEBUG, "nl80211: Using driver-based "
6779a53cbbeSchristos 			   "off-channel TX");
6789a53cbbeSchristos 		capa->flags |= WPA_DRIVER_FLAGS_OFFCHANNEL_TX;
6799a53cbbeSchristos 	}
6809a53cbbeSchristos 
6819a53cbbeSchristos 	if (tb[NL80211_ATTR_ROAM_SUPPORT]) {
6829a53cbbeSchristos 		wpa_printf(MSG_DEBUG, "nl80211: Using driver-based roaming");
6839a53cbbeSchristos 		capa->flags |= WPA_DRIVER_FLAGS_BSS_SELECTION;
6849a53cbbeSchristos 	}
6859a53cbbeSchristos 
6869a53cbbeSchristos 	wiphy_info_max_roc(capa,
6879a53cbbeSchristos 			   tb[NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION]);
6889a53cbbeSchristos 
6899a53cbbeSchristos 	if (tb[NL80211_ATTR_SUPPORT_AP_UAPSD])
6909a53cbbeSchristos 		capa->flags |= WPA_DRIVER_FLAGS_AP_UAPSD;
6919a53cbbeSchristos 
6929a53cbbeSchristos 	wiphy_info_tdls(capa, tb[NL80211_ATTR_TDLS_SUPPORT],
6939a53cbbeSchristos 			tb[NL80211_ATTR_TDLS_EXTERNAL_SETUP]);
6949a53cbbeSchristos 
6959a53cbbeSchristos 	if (tb[NL80211_ATTR_DEVICE_AP_SME])
6969a53cbbeSchristos 		info->device_ap_sme = 1;
6979a53cbbeSchristos 
6989a53cbbeSchristos 	wiphy_info_feature_flags(info, tb[NL80211_ATTR_FEATURE_FLAGS]);
699928750b6Schristos 	wiphy_info_ext_feature_flags(info, tb[NL80211_ATTR_EXT_FEATURES]);
7009a53cbbeSchristos 	wiphy_info_probe_resp_offload(capa,
7019a53cbbeSchristos 				      tb[NL80211_ATTR_PROBE_RESP_OFFLOAD]);
7029a53cbbeSchristos 
7039a53cbbeSchristos 	if (tb[NL80211_ATTR_EXT_CAPA] && tb[NL80211_ATTR_EXT_CAPA_MASK] &&
7049a53cbbeSchristos 	    drv->extended_capa == NULL) {
7059a53cbbeSchristos 		drv->extended_capa =
7069a53cbbeSchristos 			os_malloc(nla_len(tb[NL80211_ATTR_EXT_CAPA]));
7079a53cbbeSchristos 		if (drv->extended_capa) {
7089a53cbbeSchristos 			os_memcpy(drv->extended_capa,
7099a53cbbeSchristos 				  nla_data(tb[NL80211_ATTR_EXT_CAPA]),
7109a53cbbeSchristos 				  nla_len(tb[NL80211_ATTR_EXT_CAPA]));
7119a53cbbeSchristos 			drv->extended_capa_len =
7129a53cbbeSchristos 				nla_len(tb[NL80211_ATTR_EXT_CAPA]);
713928750b6Schristos 			wpa_hexdump(MSG_DEBUG,
714928750b6Schristos 				    "nl80211: Driver-advertised extended capabilities (default)",
715928750b6Schristos 				    drv->extended_capa, drv->extended_capa_len);
7169a53cbbeSchristos 		}
7179a53cbbeSchristos 		drv->extended_capa_mask =
7189a53cbbeSchristos 			os_malloc(nla_len(tb[NL80211_ATTR_EXT_CAPA_MASK]));
7199a53cbbeSchristos 		if (drv->extended_capa_mask) {
7209a53cbbeSchristos 			os_memcpy(drv->extended_capa_mask,
7219a53cbbeSchristos 				  nla_data(tb[NL80211_ATTR_EXT_CAPA_MASK]),
7229a53cbbeSchristos 				  nla_len(tb[NL80211_ATTR_EXT_CAPA_MASK]));
723928750b6Schristos 			wpa_hexdump(MSG_DEBUG,
724928750b6Schristos 				    "nl80211: Driver-advertised extended capabilities mask (default)",
725928750b6Schristos 				    drv->extended_capa_mask,
726928750b6Schristos 				    drv->extended_capa_len);
7279a53cbbeSchristos 		} else {
7289a53cbbeSchristos 			os_free(drv->extended_capa);
7299a53cbbeSchristos 			drv->extended_capa = NULL;
7309a53cbbeSchristos 			drv->extended_capa_len = 0;
7319a53cbbeSchristos 		}
7329a53cbbeSchristos 	}
7339a53cbbeSchristos 
734928750b6Schristos 	wiphy_info_extended_capab(drv, tb[NL80211_ATTR_IFTYPE_EXT_CAPA]);
735928750b6Schristos 
7369a53cbbeSchristos 	if (tb[NL80211_ATTR_VENDOR_DATA]) {
7379a53cbbeSchristos 		struct nlattr *nl;
7389a53cbbeSchristos 		int rem;
7399a53cbbeSchristos 
7409a53cbbeSchristos 		nla_for_each_nested(nl, tb[NL80211_ATTR_VENDOR_DATA], rem) {
7419a53cbbeSchristos 			struct nl80211_vendor_cmd_info *vinfo;
7429a53cbbeSchristos 			if (nla_len(nl) != sizeof(*vinfo)) {
7439a53cbbeSchristos 				wpa_printf(MSG_DEBUG, "nl80211: Unexpected vendor data info");
7449a53cbbeSchristos 				continue;
7459a53cbbeSchristos 			}
7469a53cbbeSchristos 			vinfo = nla_data(nl);
747928750b6Schristos 			if (vinfo->vendor_id == OUI_QCA) {
7489a53cbbeSchristos 				switch (vinfo->subcmd) {
7499a53cbbeSchristos 				case QCA_NL80211_VENDOR_SUBCMD_TEST:
7509a53cbbeSchristos 					drv->vendor_cmd_test_avail = 1;
7519a53cbbeSchristos 					break;
752928750b6Schristos #ifdef CONFIG_DRIVER_NL80211_QCA
7539a53cbbeSchristos 				case QCA_NL80211_VENDOR_SUBCMD_ROAMING:
7549a53cbbeSchristos 					drv->roaming_vendor_cmd_avail = 1;
7559a53cbbeSchristos 					break;
7569a53cbbeSchristos 				case QCA_NL80211_VENDOR_SUBCMD_DFS_CAPABILITY:
7579a53cbbeSchristos 					drv->dfs_vendor_cmd_avail = 1;
7589a53cbbeSchristos 					break;
7599a53cbbeSchristos 				case QCA_NL80211_VENDOR_SUBCMD_GET_FEATURES:
7609a53cbbeSchristos 					drv->get_features_vendor_cmd_avail = 1;
7619a53cbbeSchristos 					break;
762928750b6Schristos 				case QCA_NL80211_VENDOR_SUBCMD_GET_PREFERRED_FREQ_LIST:
763928750b6Schristos 					drv->get_pref_freq_list = 1;
7649a53cbbeSchristos 					break;
765928750b6Schristos 				case QCA_NL80211_VENDOR_SUBCMD_SET_PROBABLE_OPER_CHANNEL:
766928750b6Schristos 					drv->set_prob_oper_freq = 1;
767928750b6Schristos 					break;
768928750b6Schristos 				case QCA_NL80211_VENDOR_SUBCMD_DO_ACS:
769928750b6Schristos 					drv->capa.flags |=
770928750b6Schristos 						WPA_DRIVER_FLAGS_ACS_OFFLOAD;
771928750b6Schristos 					break;
772928750b6Schristos 				case QCA_NL80211_VENDOR_SUBCMD_SETBAND:
773928750b6Schristos 					drv->setband_vendor_cmd_avail = 1;
774928750b6Schristos 					break;
775928750b6Schristos 				case QCA_NL80211_VENDOR_SUBCMD_TRIGGER_SCAN:
776928750b6Schristos 					drv->scan_vendor_cmd_avail = 1;
777928750b6Schristos 					break;
778928750b6Schristos 				case QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION:
779928750b6Schristos 					drv->set_wifi_conf_vendor_cmd_avail = 1;
780928750b6Schristos 					break;
781ebb5671cSchristos 				case QCA_NL80211_VENDOR_SUBCMD_FETCH_BSS_TRANSITION_STATUS:
782ebb5671cSchristos 					drv->fetch_bss_trans_status = 1;
783ebb5671cSchristos 					break;
784ebb5671cSchristos 				case QCA_NL80211_VENDOR_SUBCMD_ROAM:
785ebb5671cSchristos 					drv->roam_vendor_cmd_avail = 1;
786ebb5671cSchristos 					break;
787*0d69f216Schristos 				case QCA_NL80211_VENDOR_SUBCMD_GET_SUPPORTED_AKMS:
788*0d69f216Schristos 					drv->get_supported_akm_suites_avail = 1;
789*0d69f216Schristos 					break;
790928750b6Schristos #endif /* CONFIG_DRIVER_NL80211_QCA */
791928750b6Schristos 				}
7929a53cbbeSchristos 			}
7939a53cbbeSchristos 
7949a53cbbeSchristos 			wpa_printf(MSG_DEBUG, "nl80211: Supported vendor command: vendor_id=0x%x subcmd=%u",
7959a53cbbeSchristos 				   vinfo->vendor_id, vinfo->subcmd);
7969a53cbbeSchristos 		}
7979a53cbbeSchristos 	}
7989a53cbbeSchristos 
7999a53cbbeSchristos 	if (tb[NL80211_ATTR_VENDOR_EVENTS]) {
8009a53cbbeSchristos 		struct nlattr *nl;
8019a53cbbeSchristos 		int rem;
8029a53cbbeSchristos 
8039a53cbbeSchristos 		nla_for_each_nested(nl, tb[NL80211_ATTR_VENDOR_EVENTS], rem) {
8049a53cbbeSchristos 			struct nl80211_vendor_cmd_info *vinfo;
8059a53cbbeSchristos 			if (nla_len(nl) != sizeof(*vinfo)) {
8069a53cbbeSchristos 				wpa_printf(MSG_DEBUG, "nl80211: Unexpected vendor data info");
8079a53cbbeSchristos 				continue;
8089a53cbbeSchristos 			}
8099a53cbbeSchristos 			vinfo = nla_data(nl);
8109a53cbbeSchristos 			wpa_printf(MSG_DEBUG, "nl80211: Supported vendor event: vendor_id=0x%x subcmd=%u",
8119a53cbbeSchristos 				   vinfo->vendor_id, vinfo->subcmd);
8129a53cbbeSchristos 		}
8139a53cbbeSchristos 	}
8149a53cbbeSchristos 
8159a53cbbeSchristos 	wiphy_info_wowlan_triggers(capa,
8169a53cbbeSchristos 				   tb[NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED]);
8179a53cbbeSchristos 
8189a53cbbeSchristos 	if (tb[NL80211_ATTR_MAX_AP_ASSOC_STA])
8199a53cbbeSchristos 		capa->max_stations =
8209a53cbbeSchristos 			nla_get_u32(tb[NL80211_ATTR_MAX_AP_ASSOC_STA]);
8219a53cbbeSchristos 
822928750b6Schristos 	if (tb[NL80211_ATTR_MAX_CSA_COUNTERS])
823928750b6Schristos 		capa->max_csa_counters =
824928750b6Schristos 			nla_get_u8(tb[NL80211_ATTR_MAX_CSA_COUNTERS]);
825928750b6Schristos 
826ebb5671cSchristos 	if (tb[NL80211_ATTR_WIPHY_SELF_MANAGED_REG])
827ebb5671cSchristos 		capa->flags |= WPA_DRIVER_FLAGS_SELF_MANAGED_REGULATORY;
828ebb5671cSchristos 
8299a53cbbeSchristos 	return NL_SKIP;
8309a53cbbeSchristos }
8319a53cbbeSchristos 
8329a53cbbeSchristos 
wpa_driver_nl80211_get_info(struct wpa_driver_nl80211_data * drv,struct wiphy_info_data * info)8339a53cbbeSchristos static int wpa_driver_nl80211_get_info(struct wpa_driver_nl80211_data *drv,
8349a53cbbeSchristos 				       struct wiphy_info_data *info)
8359a53cbbeSchristos {
8369a53cbbeSchristos 	u32 feat;
8379a53cbbeSchristos 	struct nl_msg *msg;
8389a53cbbeSchristos 	int flags = 0;
8399a53cbbeSchristos 
8409a53cbbeSchristos 	os_memset(info, 0, sizeof(*info));
8419a53cbbeSchristos 	info->capa = &drv->capa;
8429a53cbbeSchristos 	info->drv = drv;
8439a53cbbeSchristos 
8449a53cbbeSchristos 	feat = get_nl80211_protocol_features(drv);
8459a53cbbeSchristos 	if (feat & NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)
8469a53cbbeSchristos 		flags = NLM_F_DUMP;
8479a53cbbeSchristos 	msg = nl80211_cmd_msg(drv->first_bss, flags, NL80211_CMD_GET_WIPHY);
8489a53cbbeSchristos 	if (!msg || nla_put_flag(msg, NL80211_ATTR_SPLIT_WIPHY_DUMP)) {
8499a53cbbeSchristos 		nlmsg_free(msg);
8509a53cbbeSchristos 		return -1;
8519a53cbbeSchristos 	}
8529a53cbbeSchristos 
8539a53cbbeSchristos 	if (send_and_recv_msgs(drv, msg, wiphy_info_handler, info))
8549a53cbbeSchristos 		return -1;
8559a53cbbeSchristos 
8569a53cbbeSchristos 	if (info->auth_supported)
8579a53cbbeSchristos 		drv->capa.flags |= WPA_DRIVER_FLAGS_SME;
8589a53cbbeSchristos 	else if (!info->connect_supported) {
8599a53cbbeSchristos 		wpa_printf(MSG_INFO, "nl80211: Driver does not support "
8609a53cbbeSchristos 			   "authentication/association or connect commands");
8619a53cbbeSchristos 		info->error = 1;
8629a53cbbeSchristos 	}
8639a53cbbeSchristos 
8649a53cbbeSchristos 	if (info->p2p_go_supported && info->p2p_client_supported)
8659a53cbbeSchristos 		drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CAPABLE;
8669a53cbbeSchristos 	if (info->p2p_concurrent) {
8679a53cbbeSchristos 		wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group "
8689a53cbbeSchristos 			   "interface (driver advertised support)");
8699a53cbbeSchristos 		drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT;
8709a53cbbeSchristos 		drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P;
8719a53cbbeSchristos 	}
8729a53cbbeSchristos 	if (info->num_multichan_concurrent > 1) {
8739a53cbbeSchristos 		wpa_printf(MSG_DEBUG, "nl80211: Enable multi-channel "
8749a53cbbeSchristos 			   "concurrent (driver advertised support)");
8759a53cbbeSchristos 		drv->capa.num_multichan_concurrent =
8769a53cbbeSchristos 			info->num_multichan_concurrent;
8779a53cbbeSchristos 	}
8789a53cbbeSchristos 	if (drv->capa.flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)
8799a53cbbeSchristos 		wpa_printf(MSG_DEBUG, "nl80211: use P2P_DEVICE support");
8809a53cbbeSchristos 
8819a53cbbeSchristos 	/* default to 5000 since early versions of mac80211 don't set it */
8829a53cbbeSchristos 	if (!drv->capa.max_remain_on_chan)
8839a53cbbeSchristos 		drv->capa.max_remain_on_chan = 5000;
8849a53cbbeSchristos 
8859a53cbbeSchristos 	drv->capa.wmm_ac_supported = info->wmm_ac_supported;
8869a53cbbeSchristos 
8879a53cbbeSchristos 	drv->capa.mac_addr_rand_sched_scan_supported =
8889a53cbbeSchristos 		info->mac_addr_rand_sched_scan_supported;
8899a53cbbeSchristos 	drv->capa.mac_addr_rand_scan_supported =
8909a53cbbeSchristos 		info->mac_addr_rand_scan_supported;
8919a53cbbeSchristos 
892928750b6Schristos 	if (info->channel_switch_supported) {
893928750b6Schristos 		drv->capa.flags |= WPA_DRIVER_FLAGS_AP_CSA;
894928750b6Schristos 		if (!drv->capa.max_csa_counters)
895928750b6Schristos 			drv->capa.max_csa_counters = 1;
896928750b6Schristos 	}
897928750b6Schristos 
898928750b6Schristos 	if (!drv->capa.max_sched_scan_plans) {
899928750b6Schristos 		drv->capa.max_sched_scan_plans = 1;
900928750b6Schristos 		drv->capa.max_sched_scan_plan_interval = UINT32_MAX;
901928750b6Schristos 		drv->capa.max_sched_scan_plan_iterations = 0;
902928750b6Schristos 	}
903928750b6Schristos 
9049a53cbbeSchristos 	return 0;
9059a53cbbeSchristos }
9069a53cbbeSchristos 
9079a53cbbeSchristos 
908928750b6Schristos #ifdef CONFIG_DRIVER_NL80211_QCA
909928750b6Schristos 
dfs_info_handler(struct nl_msg * msg,void * arg)9109a53cbbeSchristos static int dfs_info_handler(struct nl_msg *msg, void *arg)
9119a53cbbeSchristos {
9129a53cbbeSchristos 	struct nlattr *tb[NL80211_ATTR_MAX + 1];
9139a53cbbeSchristos 	struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
9149a53cbbeSchristos 	int *dfs_capability_ptr = arg;
9159a53cbbeSchristos 
9169a53cbbeSchristos 	nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
9179a53cbbeSchristos 		  genlmsg_attrlen(gnlh, 0), NULL);
9189a53cbbeSchristos 
9199a53cbbeSchristos 	if (tb[NL80211_ATTR_VENDOR_DATA]) {
9209a53cbbeSchristos 		struct nlattr *nl_vend = tb[NL80211_ATTR_VENDOR_DATA];
9219a53cbbeSchristos 		struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1];
9229a53cbbeSchristos 
9239a53cbbeSchristos 		nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX,
9249a53cbbeSchristos 			  nla_data(nl_vend), nla_len(nl_vend), NULL);
9259a53cbbeSchristos 
9269a53cbbeSchristos 		if (tb_vendor[QCA_WLAN_VENDOR_ATTR_DFS]) {
9279a53cbbeSchristos 			u32 val;
9289a53cbbeSchristos 			val = nla_get_u32(tb_vendor[QCA_WLAN_VENDOR_ATTR_DFS]);
9299a53cbbeSchristos 			wpa_printf(MSG_DEBUG, "nl80211: DFS offload capability: %u",
9309a53cbbeSchristos 				   val);
9319a53cbbeSchristos 			*dfs_capability_ptr = val;
9329a53cbbeSchristos 		}
9339a53cbbeSchristos 	}
9349a53cbbeSchristos 
9359a53cbbeSchristos 	return NL_SKIP;
9369a53cbbeSchristos }
9379a53cbbeSchristos 
9389a53cbbeSchristos 
qca_nl80211_check_dfs_capa(struct wpa_driver_nl80211_data * drv)9399a53cbbeSchristos static void qca_nl80211_check_dfs_capa(struct wpa_driver_nl80211_data *drv)
9409a53cbbeSchristos {
9419a53cbbeSchristos 	struct nl_msg *msg;
9429a53cbbeSchristos 	int dfs_capability = 0;
9439a53cbbeSchristos 	int ret;
9449a53cbbeSchristos 
9459a53cbbeSchristos 	if (!drv->dfs_vendor_cmd_avail)
9469a53cbbeSchristos 		return;
9479a53cbbeSchristos 
9489a53cbbeSchristos 	if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
9499a53cbbeSchristos 	    nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9509a53cbbeSchristos 	    nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9519a53cbbeSchristos 			QCA_NL80211_VENDOR_SUBCMD_DFS_CAPABILITY)) {
9529a53cbbeSchristos 		nlmsg_free(msg);
9539a53cbbeSchristos 		return;
9549a53cbbeSchristos 	}
9559a53cbbeSchristos 
9569a53cbbeSchristos 	ret = send_and_recv_msgs(drv, msg, dfs_info_handler, &dfs_capability);
9579a53cbbeSchristos 	if (!ret && dfs_capability)
9589a53cbbeSchristos 		drv->capa.flags |= WPA_DRIVER_FLAGS_DFS_OFFLOAD;
9599a53cbbeSchristos }
9609a53cbbeSchristos 
9619a53cbbeSchristos 
get_akm_suites_info(struct nlattr * tb)962*0d69f216Schristos static unsigned int get_akm_suites_info(struct nlattr *tb)
963*0d69f216Schristos {
964*0d69f216Schristos 	int i, num;
965*0d69f216Schristos 	unsigned int key_mgmt = 0;
966*0d69f216Schristos 	u32 *akms;
967*0d69f216Schristos 
968*0d69f216Schristos 	if (!tb)
969*0d69f216Schristos 		return 0;
970*0d69f216Schristos 
971*0d69f216Schristos 	num = nla_len(tb) / sizeof(u32);
972*0d69f216Schristos 	akms = nla_data(tb);
973*0d69f216Schristos 	for (i = 0; i < num; i++) {
974*0d69f216Schristos 		u32 a = akms[i];
975*0d69f216Schristos 
976*0d69f216Schristos 		wpa_printf(MSG_DEBUG,
977*0d69f216Schristos 			   "nl80211: Supported AKM %02x-%02x-%02x:%u",
978*0d69f216Schristos 			   a >> 24, (a >> 16) & 0xff,
979*0d69f216Schristos 			   (a >> 8) & 0xff, a & 0xff);
980*0d69f216Schristos 		switch (a) {
981*0d69f216Schristos 		case RSN_AUTH_KEY_MGMT_UNSPEC_802_1X:
982*0d69f216Schristos 			key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_WPA |
983*0d69f216Schristos 				WPA_DRIVER_CAPA_KEY_MGMT_WPA2;
984*0d69f216Schristos 			break;
985*0d69f216Schristos 		case RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X:
986*0d69f216Schristos 			key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
987*0d69f216Schristos 				WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK;
988*0d69f216Schristos 			break;
989*0d69f216Schristos 		case RSN_AUTH_KEY_MGMT_FT_802_1X:
990*0d69f216Schristos 			key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT;
991*0d69f216Schristos 			break;
992*0d69f216Schristos 		case RSN_AUTH_KEY_MGMT_FT_PSK:
993*0d69f216Schristos 			key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK;
994*0d69f216Schristos 			break;
995*0d69f216Schristos 		case RSN_AUTH_KEY_MGMT_802_1X_SUITE_B:
996*0d69f216Schristos 			key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B;
997*0d69f216Schristos 			break;
998*0d69f216Schristos 		case RSN_AUTH_KEY_MGMT_802_1X_SUITE_B_192:
999*0d69f216Schristos 			key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192;
1000*0d69f216Schristos 			break;
1001*0d69f216Schristos 		case RSN_AUTH_KEY_MGMT_OWE:
1002*0d69f216Schristos 			key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_OWE;
1003*0d69f216Schristos 			break;
1004*0d69f216Schristos 		case RSN_AUTH_KEY_MGMT_DPP:
1005*0d69f216Schristos 			key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_DPP;
1006*0d69f216Schristos 			break;
1007*0d69f216Schristos 		case RSN_AUTH_KEY_MGMT_FILS_SHA256:
1008*0d69f216Schristos 			key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256;
1009*0d69f216Schristos 			break;
1010*0d69f216Schristos 		case RSN_AUTH_KEY_MGMT_FILS_SHA384:
1011*0d69f216Schristos 			key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384;
1012*0d69f216Schristos 			break;
1013*0d69f216Schristos 		case RSN_AUTH_KEY_MGMT_FT_FILS_SHA256:
1014*0d69f216Schristos 			key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA256;
1015*0d69f216Schristos 			break;
1016*0d69f216Schristos 		case RSN_AUTH_KEY_MGMT_FT_FILS_SHA384:
1017*0d69f216Schristos 			key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA384;
1018*0d69f216Schristos 			break;
1019*0d69f216Schristos 		case RSN_AUTH_KEY_MGMT_SAE:
1020*0d69f216Schristos 			key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_SAE;
1021*0d69f216Schristos 			break;
1022*0d69f216Schristos 		}
1023*0d69f216Schristos 	}
1024*0d69f216Schristos 
1025*0d69f216Schristos 	return key_mgmt;
1026*0d69f216Schristos }
1027*0d69f216Schristos 
1028*0d69f216Schristos 
get_akm_suites_handler(struct nl_msg * msg,void * arg)1029*0d69f216Schristos static int get_akm_suites_handler(struct nl_msg *msg, void *arg)
1030ebb5671cSchristos {
1031ebb5671cSchristos 	struct nlattr *tb[NL80211_ATTR_MAX + 1];
1032ebb5671cSchristos 	struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1033*0d69f216Schristos 	unsigned int *key_mgmt = arg;
1034ebb5671cSchristos 
1035ebb5671cSchristos 	nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1036ebb5671cSchristos 		  genlmsg_attrlen(gnlh, 0), NULL);
1037ebb5671cSchristos 
1038*0d69f216Schristos 	if (tb[NL80211_ATTR_VENDOR_DATA]) {
1039*0d69f216Schristos 		struct nlattr *nl_vend = tb[NL80211_ATTR_VENDOR_DATA];
1040*0d69f216Schristos 		struct nlattr *tb_data[NL80211_ATTR_MAX + 1];
1041ebb5671cSchristos 
1042*0d69f216Schristos 		nla_parse(tb_data, NL80211_ATTR_MAX,
1043ebb5671cSchristos 			  nla_data(nl_vend), nla_len(nl_vend), NULL);
1044ebb5671cSchristos 
1045*0d69f216Schristos 		*key_mgmt =
1046*0d69f216Schristos 			get_akm_suites_info(tb_data[NL80211_ATTR_AKM_SUITES]);
1047ebb5671cSchristos 	}
1048ebb5671cSchristos 
1049ebb5671cSchristos 	return NL_SKIP;
1050ebb5671cSchristos }
1051ebb5671cSchristos 
1052ebb5671cSchristos 
qca_nl80211_get_akm_suites(struct wpa_driver_nl80211_data * drv)1053*0d69f216Schristos static int qca_nl80211_get_akm_suites(struct wpa_driver_nl80211_data *drv)
1054ebb5671cSchristos {
1055ebb5671cSchristos 	struct nl_msg *msg;
1056*0d69f216Schristos 	unsigned int key_mgmt = 0;
1057ebb5671cSchristos 	int ret;
1058ebb5671cSchristos 
1059*0d69f216Schristos 	if (!drv->get_supported_akm_suites_avail)
1060*0d69f216Schristos 		return -1;
1061ebb5671cSchristos 
1062ebb5671cSchristos 	if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
1063ebb5671cSchristos 	    nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
1064ebb5671cSchristos 	    nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
1065*0d69f216Schristos 			QCA_NL80211_VENDOR_SUBCMD_GET_SUPPORTED_AKMS)) {
1066ebb5671cSchristos 		nlmsg_free(msg);
1067*0d69f216Schristos 		return -1;
1068ebb5671cSchristos 	}
1069ebb5671cSchristos 
1070*0d69f216Schristos 	ret = send_and_recv_msgs(drv, msg, get_akm_suites_handler, &key_mgmt);
1071*0d69f216Schristos 	if (!ret) {
1072*0d69f216Schristos 		wpa_printf(MSG_DEBUG,
1073*0d69f216Schristos 			   "nl80211: Replace capa.key_mgmt based on driver advertised capabilities: 0x%x",
1074*0d69f216Schristos 			   key_mgmt);
1075*0d69f216Schristos 		drv->capa.key_mgmt = key_mgmt;
1076*0d69f216Schristos 	}
1077*0d69f216Schristos 
1078*0d69f216Schristos 	return ret;
1079ebb5671cSchristos }
1080ebb5671cSchristos 
1081ebb5671cSchristos 
10829a53cbbeSchristos struct features_info {
10839a53cbbeSchristos 	u8 *flags;
10849a53cbbeSchristos 	size_t flags_len;
1085928750b6Schristos 	struct wpa_driver_capa *capa;
10869a53cbbeSchristos };
10879a53cbbeSchristos 
10889a53cbbeSchristos 
features_info_handler(struct nl_msg * msg,void * arg)10899a53cbbeSchristos static int features_info_handler(struct nl_msg *msg, void *arg)
10909a53cbbeSchristos {
10919a53cbbeSchristos 	struct nlattr *tb[NL80211_ATTR_MAX + 1];
10929a53cbbeSchristos 	struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
10939a53cbbeSchristos 	struct features_info *info = arg;
10949a53cbbeSchristos 	struct nlattr *nl_vend, *attr;
10959a53cbbeSchristos 
10969a53cbbeSchristos 	nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
10979a53cbbeSchristos 		  genlmsg_attrlen(gnlh, 0), NULL);
10989a53cbbeSchristos 
10999a53cbbeSchristos 	nl_vend = tb[NL80211_ATTR_VENDOR_DATA];
11009a53cbbeSchristos 	if (nl_vend) {
11019a53cbbeSchristos 		struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1];
11029a53cbbeSchristos 
11039a53cbbeSchristos 		nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX,
11049a53cbbeSchristos 			  nla_data(nl_vend), nla_len(nl_vend), NULL);
11059a53cbbeSchristos 
11069a53cbbeSchristos 		attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_FEATURE_FLAGS];
11079a53cbbeSchristos 		if (attr) {
1108928750b6Schristos 			int len = nla_len(attr);
1109928750b6Schristos 			info->flags = os_malloc(len);
1110928750b6Schristos 			if (info->flags != NULL) {
1111928750b6Schristos 				os_memcpy(info->flags, nla_data(attr), len);
1112928750b6Schristos 				info->flags_len = len;
11139a53cbbeSchristos 			}
11149a53cbbeSchristos 		}
1115928750b6Schristos 		attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_CONCURRENCY_CAPA];
1116928750b6Schristos 		if (attr)
1117928750b6Schristos 			info->capa->conc_capab = nla_get_u32(attr);
1118928750b6Schristos 
1119928750b6Schristos 		attr = tb_vendor[
1120928750b6Schristos 			QCA_WLAN_VENDOR_ATTR_MAX_CONCURRENT_CHANNELS_2_4_BAND];
1121928750b6Schristos 		if (attr)
1122928750b6Schristos 			info->capa->max_conc_chan_2_4 = nla_get_u32(attr);
1123928750b6Schristos 
1124928750b6Schristos 		attr = tb_vendor[
1125928750b6Schristos 			QCA_WLAN_VENDOR_ATTR_MAX_CONCURRENT_CHANNELS_5_0_BAND];
1126928750b6Schristos 		if (attr)
1127928750b6Schristos 			info->capa->max_conc_chan_5_0 = nla_get_u32(attr);
1128928750b6Schristos 	}
11299a53cbbeSchristos 
11309a53cbbeSchristos 	return NL_SKIP;
11319a53cbbeSchristos }
11329a53cbbeSchristos 
11339a53cbbeSchristos 
check_feature(enum qca_wlan_vendor_features feature,struct features_info * info)11349a53cbbeSchristos static int check_feature(enum qca_wlan_vendor_features feature,
11359a53cbbeSchristos 			 struct features_info *info)
11369a53cbbeSchristos {
11379a53cbbeSchristos 	size_t idx = feature / 8;
11389a53cbbeSchristos 
11399a53cbbeSchristos 	return (idx < info->flags_len) &&
11409a53cbbeSchristos 		(info->flags[idx] & BIT(feature % 8));
11419a53cbbeSchristos }
11429a53cbbeSchristos 
11439a53cbbeSchristos 
qca_nl80211_get_features(struct wpa_driver_nl80211_data * drv)11449a53cbbeSchristos static void qca_nl80211_get_features(struct wpa_driver_nl80211_data *drv)
11459a53cbbeSchristos {
11469a53cbbeSchristos 	struct nl_msg *msg;
11479a53cbbeSchristos 	struct features_info info;
11489a53cbbeSchristos 	int ret;
11499a53cbbeSchristos 
11509a53cbbeSchristos 	if (!drv->get_features_vendor_cmd_avail)
11519a53cbbeSchristos 		return;
11529a53cbbeSchristos 
11539a53cbbeSchristos 	if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
11549a53cbbeSchristos 	    nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
11559a53cbbeSchristos 	    nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
11569a53cbbeSchristos 			QCA_NL80211_VENDOR_SUBCMD_GET_FEATURES)) {
11579a53cbbeSchristos 		nlmsg_free(msg);
11589a53cbbeSchristos 		return;
11599a53cbbeSchristos 	}
11609a53cbbeSchristos 
11619a53cbbeSchristos 	os_memset(&info, 0, sizeof(info));
1162928750b6Schristos 	info.capa = &drv->capa;
11639a53cbbeSchristos 	ret = send_and_recv_msgs(drv, msg, features_info_handler, &info);
11649a53cbbeSchristos 	if (ret || !info.flags)
11659a53cbbeSchristos 		return;
11669a53cbbeSchristos 
11679a53cbbeSchristos 	if (check_feature(QCA_WLAN_VENDOR_FEATURE_KEY_MGMT_OFFLOAD, &info))
11689a53cbbeSchristos 		drv->capa.flags |= WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD;
1169928750b6Schristos 
1170928750b6Schristos 	if (check_feature(QCA_WLAN_VENDOR_FEATURE_SUPPORT_HW_MODE_ANY, &info))
1171928750b6Schristos 		drv->capa.flags |= WPA_DRIVER_FLAGS_SUPPORT_HW_MODE_ANY;
1172928750b6Schristos 
1173928750b6Schristos 	if (check_feature(QCA_WLAN_VENDOR_FEATURE_OFFCHANNEL_SIMULTANEOUS,
1174928750b6Schristos 			  &info))
1175928750b6Schristos 		drv->capa.flags |= WPA_DRIVER_FLAGS_OFFCHANNEL_SIMULTANEOUS;
1176928750b6Schristos 	if (check_feature(QCA_WLAN_VENDOR_FEATURE_P2P_LISTEN_OFFLOAD, &info))
1177928750b6Schristos 		drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD;
1178ebb5671cSchristos 	if (check_feature(QCA_WLAN_VENDOR_FEATURE_OCE_STA, &info))
1179ebb5671cSchristos 		drv->capa.flags |= WPA_DRIVER_FLAGS_OCE_STA;
1180ebb5671cSchristos 	if (check_feature(QCA_WLAN_VENDOR_FEATURE_OCE_AP, &info))
1181ebb5671cSchristos 		drv->capa.flags |= WPA_DRIVER_FLAGS_OCE_AP;
1182ebb5671cSchristos 	if (check_feature(QCA_WLAN_VENDOR_FEATURE_OCE_STA_CFON, &info))
1183ebb5671cSchristos 		drv->capa.flags |= WPA_DRIVER_FLAGS_OCE_STA_CFON;
1184928750b6Schristos 	os_free(info.flags);
11859a53cbbeSchristos }
11869a53cbbeSchristos 
1187928750b6Schristos #endif /* CONFIG_DRIVER_NL80211_QCA */
1188928750b6Schristos 
11899a53cbbeSchristos 
wpa_driver_nl80211_capa(struct wpa_driver_nl80211_data * drv)11909a53cbbeSchristos int wpa_driver_nl80211_capa(struct wpa_driver_nl80211_data *drv)
11919a53cbbeSchristos {
11929a53cbbeSchristos 	struct wiphy_info_data info;
11939a53cbbeSchristos 	if (wpa_driver_nl80211_get_info(drv, &info))
11949a53cbbeSchristos 		return -1;
11959a53cbbeSchristos 
11969a53cbbeSchristos 	if (info.error)
11979a53cbbeSchristos 		return -1;
11989a53cbbeSchristos 
11999a53cbbeSchristos 	drv->has_capability = 1;
12009a53cbbeSchristos 	drv->capa.key_mgmt = WPA_DRIVER_CAPA_KEY_MGMT_WPA |
12019a53cbbeSchristos 		WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
12029a53cbbeSchristos 		WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
12039a53cbbeSchristos 		WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK |
12049a53cbbeSchristos 		WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B |
1205ebb5671cSchristos 		WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192 |
1206ebb5671cSchristos 		WPA_DRIVER_CAPA_KEY_MGMT_OWE |
1207ebb5671cSchristos 		WPA_DRIVER_CAPA_KEY_MGMT_DPP;
1208ebb5671cSchristos 
1209ebb5671cSchristos 	if (drv->capa.flags & WPA_DRIVER_FLAGS_SME)
1210ebb5671cSchristos 		drv->capa.key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256 |
1211ebb5671cSchristos 			WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384 |
1212ebb5671cSchristos 			WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA256 |
1213*0d69f216Schristos 			WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA384 |
1214*0d69f216Schristos 			WPA_DRIVER_CAPA_KEY_MGMT_SAE;
1215ebb5671cSchristos 	else if (drv->capa.flags & WPA_DRIVER_FLAGS_FILS_SK_OFFLOAD)
1216ebb5671cSchristos 		drv->capa.key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256 |
1217ebb5671cSchristos 			WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384;
1218ebb5671cSchristos 
1219*0d69f216Schristos #ifdef CONFIG_DRIVER_NL80211_QCA
1220*0d69f216Schristos 	/* Override drv->capa.key_mgmt based on driver advertised capability
1221*0d69f216Schristos 	 * constraints, if available. */
1222*0d69f216Schristos 	qca_nl80211_get_akm_suites(drv);
1223*0d69f216Schristos #endif /* CONFIG_DRIVER_NL80211_QCA */
1224*0d69f216Schristos 
12259a53cbbeSchristos 	drv->capa.auth = WPA_DRIVER_AUTH_OPEN |
12269a53cbbeSchristos 		WPA_DRIVER_AUTH_SHARED |
12279a53cbbeSchristos 		WPA_DRIVER_AUTH_LEAP;
12289a53cbbeSchristos 
12299a53cbbeSchristos 	drv->capa.flags |= WPA_DRIVER_FLAGS_SANE_ERROR_CODES;
12309a53cbbeSchristos 	drv->capa.flags |= WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE;
12319a53cbbeSchristos 	drv->capa.flags |= WPA_DRIVER_FLAGS_EAPOL_TX_STATUS;
12329a53cbbeSchristos 
12339a53cbbeSchristos 	/*
12349a53cbbeSchristos 	 * As all cfg80211 drivers must support cases where the AP interface is
12359a53cbbeSchristos 	 * removed without the knowledge of wpa_supplicant/hostapd, e.g., in
12369a53cbbeSchristos 	 * case that the user space daemon has crashed, they must be able to
12379a53cbbeSchristos 	 * cleanup all stations and key entries in the AP tear down flow. Thus,
12389a53cbbeSchristos 	 * this flag can/should always be set for cfg80211 drivers.
12399a53cbbeSchristos 	 */
12409a53cbbeSchristos 	drv->capa.flags |= WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT;
12419a53cbbeSchristos 
12429a53cbbeSchristos 	if (!info.device_ap_sme) {
12439a53cbbeSchristos 		drv->capa.flags |= WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS;
12449a53cbbeSchristos 
12459a53cbbeSchristos 		/*
12469a53cbbeSchristos 		 * No AP SME is currently assumed to also indicate no AP MLME
12479a53cbbeSchristos 		 * in the driver/firmware.
12489a53cbbeSchristos 		 */
12499a53cbbeSchristos 		drv->capa.flags |= WPA_DRIVER_FLAGS_AP_MLME;
12509a53cbbeSchristos 	}
12519a53cbbeSchristos 
12529a53cbbeSchristos 	drv->device_ap_sme = info.device_ap_sme;
12539a53cbbeSchristos 	drv->poll_command_supported = info.poll_command_supported;
12549a53cbbeSchristos 	drv->data_tx_status = info.data_tx_status;
12559a53cbbeSchristos 	drv->p2p_go_ctwindow_supported = info.p2p_go_ctwindow_supported;
12569a53cbbeSchristos 	if (info.set_qos_map_supported)
12579a53cbbeSchristos 		drv->capa.flags |= WPA_DRIVER_FLAGS_QOS_MAPPING;
12589a53cbbeSchristos 	drv->have_low_prio_scan = info.have_low_prio_scan;
12599a53cbbeSchristos 
12609a53cbbeSchristos 	/*
12619a53cbbeSchristos 	 * If poll command and tx status are supported, mac80211 is new enough
12629a53cbbeSchristos 	 * to have everything we need to not need monitor interfaces.
12639a53cbbeSchristos 	 */
1264928750b6Schristos 	drv->use_monitor = !info.device_ap_sme &&
1265928750b6Schristos 		(!info.poll_command_supported || !info.data_tx_status);
12669a53cbbeSchristos 
12679a53cbbeSchristos 	/*
12689a53cbbeSchristos 	 * If we aren't going to use monitor interfaces, but the
12699a53cbbeSchristos 	 * driver doesn't support data TX status, we won't get TX
12709a53cbbeSchristos 	 * status for EAPOL frames.
12719a53cbbeSchristos 	 */
12729a53cbbeSchristos 	if (!drv->use_monitor && !info.data_tx_status)
12739a53cbbeSchristos 		drv->capa.flags &= ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS;
12749a53cbbeSchristos 
1275928750b6Schristos #ifdef CONFIG_DRIVER_NL80211_QCA
1276ebb5671cSchristos 	if (!(info.capa->flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD))
12779a53cbbeSchristos 		qca_nl80211_check_dfs_capa(drv);
12789a53cbbeSchristos 	qca_nl80211_get_features(drv);
12799a53cbbeSchristos 
1280928750b6Schristos 	/*
1281928750b6Schristos 	 * To enable offchannel simultaneous support in wpa_supplicant, the
1282928750b6Schristos 	 * underlying driver needs to support the same along with offchannel TX.
1283928750b6Schristos 	 * Offchannel TX support is needed since remain_on_channel and
1284928750b6Schristos 	 * action_tx use some common data structures and hence cannot be
1285928750b6Schristos 	 * scheduled simultaneously.
1286928750b6Schristos 	 */
1287928750b6Schristos 	if (!(drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX))
1288928750b6Schristos 		drv->capa.flags &= ~WPA_DRIVER_FLAGS_OFFCHANNEL_SIMULTANEOUS;
1289928750b6Schristos #endif /* CONFIG_DRIVER_NL80211_QCA */
1290928750b6Schristos 
12919a53cbbeSchristos 	return 0;
12929a53cbbeSchristos }
12939a53cbbeSchristos 
12949a53cbbeSchristos 
12959a53cbbeSchristos struct phy_info_arg {
12969a53cbbeSchristos 	u16 *num_modes;
12979a53cbbeSchristos 	struct hostapd_hw_modes *modes;
12989a53cbbeSchristos 	int last_mode, last_chan_idx;
1299928750b6Schristos 	int failed;
1300ebb5671cSchristos 	u8 dfs_domain;
13019a53cbbeSchristos };
13029a53cbbeSchristos 
phy_info_ht_capa(struct hostapd_hw_modes * mode,struct nlattr * capa,struct nlattr * ampdu_factor,struct nlattr * ampdu_density,struct nlattr * mcs_set)13039a53cbbeSchristos static void phy_info_ht_capa(struct hostapd_hw_modes *mode, struct nlattr *capa,
13049a53cbbeSchristos 			     struct nlattr *ampdu_factor,
13059a53cbbeSchristos 			     struct nlattr *ampdu_density,
13069a53cbbeSchristos 			     struct nlattr *mcs_set)
13079a53cbbeSchristos {
13089a53cbbeSchristos 	if (capa)
13099a53cbbeSchristos 		mode->ht_capab = nla_get_u16(capa);
13109a53cbbeSchristos 
13119a53cbbeSchristos 	if (ampdu_factor)
13129a53cbbeSchristos 		mode->a_mpdu_params |= nla_get_u8(ampdu_factor) & 0x03;
13139a53cbbeSchristos 
13149a53cbbeSchristos 	if (ampdu_density)
13159a53cbbeSchristos 		mode->a_mpdu_params |= nla_get_u8(ampdu_density) << 2;
13169a53cbbeSchristos 
13179a53cbbeSchristos 	if (mcs_set && nla_len(mcs_set) >= 16) {
13189a53cbbeSchristos 		u8 *mcs;
13199a53cbbeSchristos 		mcs = nla_data(mcs_set);
13209a53cbbeSchristos 		os_memcpy(mode->mcs_set, mcs, 16);
13219a53cbbeSchristos 	}
13229a53cbbeSchristos }
13239a53cbbeSchristos 
13249a53cbbeSchristos 
phy_info_vht_capa(struct hostapd_hw_modes * mode,struct nlattr * capa,struct nlattr * mcs_set)13259a53cbbeSchristos static void phy_info_vht_capa(struct hostapd_hw_modes *mode,
13269a53cbbeSchristos 			      struct nlattr *capa,
13279a53cbbeSchristos 			      struct nlattr *mcs_set)
13289a53cbbeSchristos {
13299a53cbbeSchristos 	if (capa)
13309a53cbbeSchristos 		mode->vht_capab = nla_get_u32(capa);
13319a53cbbeSchristos 
13329a53cbbeSchristos 	if (mcs_set && nla_len(mcs_set) >= 8) {
13339a53cbbeSchristos 		u8 *mcs;
13349a53cbbeSchristos 		mcs = nla_data(mcs_set);
13359a53cbbeSchristos 		os_memcpy(mode->vht_mcs_set, mcs, 8);
13369a53cbbeSchristos 	}
13379a53cbbeSchristos }
13389a53cbbeSchristos 
13399a53cbbeSchristos 
phy_info_freq(struct hostapd_hw_modes * mode,struct hostapd_channel_data * chan,struct nlattr * tb_freq[])13409a53cbbeSchristos static void phy_info_freq(struct hostapd_hw_modes *mode,
13419a53cbbeSchristos 			  struct hostapd_channel_data *chan,
13429a53cbbeSchristos 			  struct nlattr *tb_freq[])
13439a53cbbeSchristos {
13449a53cbbeSchristos 	u8 channel;
13459a53cbbeSchristos 	chan->freq = nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_FREQ]);
13469a53cbbeSchristos 	chan->flag = 0;
1347*0d69f216Schristos 	chan->allowed_bw = ~0;
13489a53cbbeSchristos 	chan->dfs_cac_ms = 0;
13499a53cbbeSchristos 	if (ieee80211_freq_to_chan(chan->freq, &channel) != NUM_HOSTAPD_MODES)
13509a53cbbeSchristos 		chan->chan = channel;
13519a53cbbeSchristos 
13529a53cbbeSchristos 	if (tb_freq[NL80211_FREQUENCY_ATTR_DISABLED])
13539a53cbbeSchristos 		chan->flag |= HOSTAPD_CHAN_DISABLED;
13549a53cbbeSchristos 	if (tb_freq[NL80211_FREQUENCY_ATTR_NO_IR])
13559a53cbbeSchristos 		chan->flag |= HOSTAPD_CHAN_NO_IR;
13569a53cbbeSchristos 	if (tb_freq[NL80211_FREQUENCY_ATTR_RADAR])
13579a53cbbeSchristos 		chan->flag |= HOSTAPD_CHAN_RADAR;
13589a53cbbeSchristos 	if (tb_freq[NL80211_FREQUENCY_ATTR_INDOOR_ONLY])
13599a53cbbeSchristos 		chan->flag |= HOSTAPD_CHAN_INDOOR_ONLY;
13609a53cbbeSchristos 	if (tb_freq[NL80211_FREQUENCY_ATTR_GO_CONCURRENT])
13619a53cbbeSchristos 		chan->flag |= HOSTAPD_CHAN_GO_CONCURRENT;
13629a53cbbeSchristos 
1363*0d69f216Schristos 	if (tb_freq[NL80211_FREQUENCY_ATTR_NO_10MHZ])
1364*0d69f216Schristos 		chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_10;
1365*0d69f216Schristos 	if (tb_freq[NL80211_FREQUENCY_ATTR_NO_20MHZ])
1366*0d69f216Schristos 		chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_20;
1367*0d69f216Schristos 	if (tb_freq[NL80211_FREQUENCY_ATTR_NO_HT40_PLUS])
1368*0d69f216Schristos 		chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_40P;
1369*0d69f216Schristos 	if (tb_freq[NL80211_FREQUENCY_ATTR_NO_HT40_MINUS])
1370*0d69f216Schristos 		chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_40M;
1371*0d69f216Schristos 	if (tb_freq[NL80211_FREQUENCY_ATTR_NO_80MHZ])
1372*0d69f216Schristos 		chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_80;
1373*0d69f216Schristos 	if (tb_freq[NL80211_FREQUENCY_ATTR_NO_160MHZ])
1374*0d69f216Schristos 		chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_160;
1375*0d69f216Schristos 
13769a53cbbeSchristos 	if (tb_freq[NL80211_FREQUENCY_ATTR_DFS_STATE]) {
13779a53cbbeSchristos 		enum nl80211_dfs_state state =
13789a53cbbeSchristos 			nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_DFS_STATE]);
13799a53cbbeSchristos 
13809a53cbbeSchristos 		switch (state) {
13819a53cbbeSchristos 		case NL80211_DFS_USABLE:
13829a53cbbeSchristos 			chan->flag |= HOSTAPD_CHAN_DFS_USABLE;
13839a53cbbeSchristos 			break;
13849a53cbbeSchristos 		case NL80211_DFS_AVAILABLE:
13859a53cbbeSchristos 			chan->flag |= HOSTAPD_CHAN_DFS_AVAILABLE;
13869a53cbbeSchristos 			break;
13879a53cbbeSchristos 		case NL80211_DFS_UNAVAILABLE:
13889a53cbbeSchristos 			chan->flag |= HOSTAPD_CHAN_DFS_UNAVAILABLE;
13899a53cbbeSchristos 			break;
13909a53cbbeSchristos 		}
13919a53cbbeSchristos 	}
13929a53cbbeSchristos 
13939a53cbbeSchristos 	if (tb_freq[NL80211_FREQUENCY_ATTR_DFS_CAC_TIME]) {
13949a53cbbeSchristos 		chan->dfs_cac_ms = nla_get_u32(
13959a53cbbeSchristos 			tb_freq[NL80211_FREQUENCY_ATTR_DFS_CAC_TIME]);
13969a53cbbeSchristos 	}
1397*0d69f216Schristos 
1398*0d69f216Schristos 	chan->wmm_rules_valid = 0;
1399*0d69f216Schristos 	if (tb_freq[NL80211_FREQUENCY_ATTR_WMM]) {
1400*0d69f216Schristos 		static struct nla_policy wmm_policy[NL80211_WMMR_MAX + 1] = {
1401*0d69f216Schristos 			[NL80211_WMMR_CW_MIN] = { .type = NLA_U16 },
1402*0d69f216Schristos 			[NL80211_WMMR_CW_MAX] = { .type = NLA_U16 },
1403*0d69f216Schristos 			[NL80211_WMMR_AIFSN] = { .type = NLA_U8 },
1404*0d69f216Schristos 			[NL80211_WMMR_TXOP] = { .type = NLA_U16 },
1405*0d69f216Schristos 		};
1406*0d69f216Schristos 		struct nlattr *nl_wmm;
1407*0d69f216Schristos 		struct nlattr *tb_wmm[NL80211_WMMR_MAX + 1];
1408*0d69f216Schristos 		int rem_wmm, ac, count = 0;
1409*0d69f216Schristos 
1410*0d69f216Schristos 		nla_for_each_nested(nl_wmm, tb_freq[NL80211_FREQUENCY_ATTR_WMM],
1411*0d69f216Schristos 				    rem_wmm) {
1412*0d69f216Schristos 			if (nla_parse_nested(tb_wmm, NL80211_WMMR_MAX, nl_wmm,
1413*0d69f216Schristos 					     wmm_policy)) {
1414*0d69f216Schristos 				wpa_printf(MSG_DEBUG,
1415*0d69f216Schristos 					   "nl80211: Failed to parse WMM rules attribute");
1416*0d69f216Schristos 				return;
1417*0d69f216Schristos 			}
1418*0d69f216Schristos 			if (!tb_wmm[NL80211_WMMR_CW_MIN] ||
1419*0d69f216Schristos 			    !tb_wmm[NL80211_WMMR_CW_MAX] ||
1420*0d69f216Schristos 			    !tb_wmm[NL80211_WMMR_AIFSN] ||
1421*0d69f216Schristos 			    !tb_wmm[NL80211_WMMR_TXOP]) {
1422*0d69f216Schristos 				wpa_printf(MSG_DEBUG,
1423*0d69f216Schristos 					   "nl80211: Channel is missing WMM rule attribute");
1424*0d69f216Schristos 				return;
1425*0d69f216Schristos 			}
1426*0d69f216Schristos 			ac = nl_wmm->nla_type;
1427*0d69f216Schristos 			if (ac < 0 || ac >= WMM_AC_NUM) {
1428*0d69f216Schristos 				wpa_printf(MSG_DEBUG,
1429*0d69f216Schristos 					   "nl80211: Invalid AC value %d", ac);
1430*0d69f216Schristos 				return;
1431*0d69f216Schristos 			}
1432*0d69f216Schristos 
1433*0d69f216Schristos 			chan->wmm_rules[ac].min_cwmin =
1434*0d69f216Schristos 				nla_get_u16(tb_wmm[NL80211_WMMR_CW_MIN]);
1435*0d69f216Schristos 			chan->wmm_rules[ac].min_cwmax =
1436*0d69f216Schristos 				nla_get_u16(tb_wmm[NL80211_WMMR_CW_MAX]);
1437*0d69f216Schristos 			chan->wmm_rules[ac].min_aifs =
1438*0d69f216Schristos 				nla_get_u8(tb_wmm[NL80211_WMMR_AIFSN]);
1439*0d69f216Schristos 			chan->wmm_rules[ac].max_txop =
1440*0d69f216Schristos 				nla_get_u16(tb_wmm[NL80211_WMMR_TXOP]) / 32;
1441*0d69f216Schristos 			count++;
1442*0d69f216Schristos 		}
1443*0d69f216Schristos 
1444*0d69f216Schristos 		/* Set valid flag if all the AC rules are present */
1445*0d69f216Schristos 		if (count == WMM_AC_NUM)
1446*0d69f216Schristos 			chan->wmm_rules_valid = 1;
1447*0d69f216Schristos 	}
14489a53cbbeSchristos }
14499a53cbbeSchristos 
14509a53cbbeSchristos 
phy_info_freqs(struct phy_info_arg * phy_info,struct hostapd_hw_modes * mode,struct nlattr * tb)14519a53cbbeSchristos static int phy_info_freqs(struct phy_info_arg *phy_info,
14529a53cbbeSchristos 			  struct hostapd_hw_modes *mode, struct nlattr *tb)
14539a53cbbeSchristos {
14549a53cbbeSchristos 	static struct nla_policy freq_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = {
14559a53cbbeSchristos 		[NL80211_FREQUENCY_ATTR_FREQ] = { .type = NLA_U32 },
14569a53cbbeSchristos 		[NL80211_FREQUENCY_ATTR_DISABLED] = { .type = NLA_FLAG },
14579a53cbbeSchristos 		[NL80211_FREQUENCY_ATTR_NO_IR] = { .type = NLA_FLAG },
14589a53cbbeSchristos 		[NL80211_FREQUENCY_ATTR_RADAR] = { .type = NLA_FLAG },
14599a53cbbeSchristos 		[NL80211_FREQUENCY_ATTR_MAX_TX_POWER] = { .type = NLA_U32 },
14609a53cbbeSchristos 		[NL80211_FREQUENCY_ATTR_DFS_STATE] = { .type = NLA_U32 },
1461*0d69f216Schristos 		[NL80211_FREQUENCY_ATTR_NO_10MHZ] = { .type = NLA_FLAG },
1462*0d69f216Schristos 		[NL80211_FREQUENCY_ATTR_NO_20MHZ] = { .type = NLA_FLAG },
1463*0d69f216Schristos 		[NL80211_FREQUENCY_ATTR_NO_HT40_PLUS] = { .type = NLA_FLAG },
1464*0d69f216Schristos 		[NL80211_FREQUENCY_ATTR_NO_HT40_MINUS] = { .type = NLA_FLAG },
1465*0d69f216Schristos 		[NL80211_FREQUENCY_ATTR_NO_80MHZ] = { .type = NLA_FLAG },
1466*0d69f216Schristos 		[NL80211_FREQUENCY_ATTR_NO_160MHZ] = { .type = NLA_FLAG },
14679a53cbbeSchristos 	};
14689a53cbbeSchristos 	int new_channels = 0;
14699a53cbbeSchristos 	struct hostapd_channel_data *channel;
14709a53cbbeSchristos 	struct nlattr *tb_freq[NL80211_FREQUENCY_ATTR_MAX + 1];
14719a53cbbeSchristos 	struct nlattr *nl_freq;
14729a53cbbeSchristos 	int rem_freq, idx;
14739a53cbbeSchristos 
14749a53cbbeSchristos 	if (tb == NULL)
14759a53cbbeSchristos 		return NL_OK;
14769a53cbbeSchristos 
14779a53cbbeSchristos 	nla_for_each_nested(nl_freq, tb, rem_freq) {
14789a53cbbeSchristos 		nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX,
14799a53cbbeSchristos 			  nla_data(nl_freq), nla_len(nl_freq), freq_policy);
14809a53cbbeSchristos 		if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ])
14819a53cbbeSchristos 			continue;
14829a53cbbeSchristos 		new_channels++;
14839a53cbbeSchristos 	}
14849a53cbbeSchristos 
14859a53cbbeSchristos 	channel = os_realloc_array(mode->channels,
14869a53cbbeSchristos 				   mode->num_channels + new_channels,
14879a53cbbeSchristos 				   sizeof(struct hostapd_channel_data));
14889a53cbbeSchristos 	if (!channel)
1489928750b6Schristos 		return NL_STOP;
14909a53cbbeSchristos 
14919a53cbbeSchristos 	mode->channels = channel;
14929a53cbbeSchristos 	mode->num_channels += new_channels;
14939a53cbbeSchristos 
14949a53cbbeSchristos 	idx = phy_info->last_chan_idx;
14959a53cbbeSchristos 
14969a53cbbeSchristos 	nla_for_each_nested(nl_freq, tb, rem_freq) {
14979a53cbbeSchristos 		nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX,
14989a53cbbeSchristos 			  nla_data(nl_freq), nla_len(nl_freq), freq_policy);
14999a53cbbeSchristos 		if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ])
15009a53cbbeSchristos 			continue;
15019a53cbbeSchristos 		phy_info_freq(mode, &mode->channels[idx], tb_freq);
15029a53cbbeSchristos 		idx++;
15039a53cbbeSchristos 	}
15049a53cbbeSchristos 	phy_info->last_chan_idx = idx;
15059a53cbbeSchristos 
15069a53cbbeSchristos 	return NL_OK;
15079a53cbbeSchristos }
15089a53cbbeSchristos 
15099a53cbbeSchristos 
phy_info_rates(struct hostapd_hw_modes * mode,struct nlattr * tb)15109a53cbbeSchristos static int phy_info_rates(struct hostapd_hw_modes *mode, struct nlattr *tb)
15119a53cbbeSchristos {
15129a53cbbeSchristos 	static struct nla_policy rate_policy[NL80211_BITRATE_ATTR_MAX + 1] = {
15139a53cbbeSchristos 		[NL80211_BITRATE_ATTR_RATE] = { .type = NLA_U32 },
15149a53cbbeSchristos 		[NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE] =
15159a53cbbeSchristos 		{ .type = NLA_FLAG },
15169a53cbbeSchristos 	};
15179a53cbbeSchristos 	struct nlattr *tb_rate[NL80211_BITRATE_ATTR_MAX + 1];
15189a53cbbeSchristos 	struct nlattr *nl_rate;
15199a53cbbeSchristos 	int rem_rate, idx;
15209a53cbbeSchristos 
15219a53cbbeSchristos 	if (tb == NULL)
15229a53cbbeSchristos 		return NL_OK;
15239a53cbbeSchristos 
15249a53cbbeSchristos 	nla_for_each_nested(nl_rate, tb, rem_rate) {
15259a53cbbeSchristos 		nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX,
15269a53cbbeSchristos 			  nla_data(nl_rate), nla_len(nl_rate),
15279a53cbbeSchristos 			  rate_policy);
15289a53cbbeSchristos 		if (!tb_rate[NL80211_BITRATE_ATTR_RATE])
15299a53cbbeSchristos 			continue;
15309a53cbbeSchristos 		mode->num_rates++;
15319a53cbbeSchristos 	}
15329a53cbbeSchristos 
15339a53cbbeSchristos 	mode->rates = os_calloc(mode->num_rates, sizeof(int));
15349a53cbbeSchristos 	if (!mode->rates)
1535928750b6Schristos 		return NL_STOP;
15369a53cbbeSchristos 
15379a53cbbeSchristos 	idx = 0;
15389a53cbbeSchristos 
15399a53cbbeSchristos 	nla_for_each_nested(nl_rate, tb, rem_rate) {
15409a53cbbeSchristos 		nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX,
15419a53cbbeSchristos 			  nla_data(nl_rate), nla_len(nl_rate),
15429a53cbbeSchristos 			  rate_policy);
15439a53cbbeSchristos 		if (!tb_rate[NL80211_BITRATE_ATTR_RATE])
15449a53cbbeSchristos 			continue;
15459a53cbbeSchristos 		mode->rates[idx] = nla_get_u32(
15469a53cbbeSchristos 			tb_rate[NL80211_BITRATE_ATTR_RATE]);
15479a53cbbeSchristos 		idx++;
15489a53cbbeSchristos 	}
15499a53cbbeSchristos 
15509a53cbbeSchristos 	return NL_OK;
15519a53cbbeSchristos }
15529a53cbbeSchristos 
15539a53cbbeSchristos 
phy_info_iftype_copy(struct he_capabilities * he_capab,enum ieee80211_op_mode opmode,struct nlattr ** tb,struct nlattr ** tb_flags)1554*0d69f216Schristos static void phy_info_iftype_copy(struct he_capabilities *he_capab,
1555*0d69f216Schristos 				 enum ieee80211_op_mode opmode,
1556*0d69f216Schristos 				 struct nlattr **tb, struct nlattr **tb_flags)
1557*0d69f216Schristos {
1558*0d69f216Schristos 	enum nl80211_iftype iftype;
1559*0d69f216Schristos 	size_t len;
1560*0d69f216Schristos 
1561*0d69f216Schristos 	switch (opmode) {
1562*0d69f216Schristos 	case IEEE80211_MODE_INFRA:
1563*0d69f216Schristos 		iftype = NL80211_IFTYPE_STATION;
1564*0d69f216Schristos 		break;
1565*0d69f216Schristos 	case IEEE80211_MODE_IBSS:
1566*0d69f216Schristos 		iftype = NL80211_IFTYPE_ADHOC;
1567*0d69f216Schristos 		break;
1568*0d69f216Schristos 	case IEEE80211_MODE_AP:
1569*0d69f216Schristos 		iftype = NL80211_IFTYPE_AP;
1570*0d69f216Schristos 		break;
1571*0d69f216Schristos 	case IEEE80211_MODE_MESH:
1572*0d69f216Schristos 		iftype = NL80211_IFTYPE_MESH_POINT;
1573*0d69f216Schristos 		break;
1574*0d69f216Schristos 	default:
1575*0d69f216Schristos 		return;
1576*0d69f216Schristos 	}
1577*0d69f216Schristos 
1578*0d69f216Schristos 	if (!nla_get_flag(tb_flags[iftype]))
1579*0d69f216Schristos 		return;
1580*0d69f216Schristos 
1581*0d69f216Schristos 	he_capab->he_supported = 1;
1582*0d69f216Schristos 
1583*0d69f216Schristos 	if (tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY]) {
1584*0d69f216Schristos 		len = nla_len(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY]);
1585*0d69f216Schristos 
1586*0d69f216Schristos 		if (len > sizeof(he_capab->phy_cap))
1587*0d69f216Schristos 			len = sizeof(he_capab->phy_cap);
1588*0d69f216Schristos 		os_memcpy(he_capab->phy_cap,
1589*0d69f216Schristos 			  nla_data(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY]),
1590*0d69f216Schristos 			  len);
1591*0d69f216Schristos 	}
1592*0d69f216Schristos 
1593*0d69f216Schristos 	if (tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC]) {
1594*0d69f216Schristos 		len = nla_len(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC]);
1595*0d69f216Schristos 
1596*0d69f216Schristos 		if (len > sizeof(he_capab->mac_cap))
1597*0d69f216Schristos 			len = sizeof(he_capab->mac_cap);
1598*0d69f216Schristos 		os_memcpy(he_capab->mac_cap,
1599*0d69f216Schristos 			  nla_data(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC]),
1600*0d69f216Schristos 			  len);
1601*0d69f216Schristos 	}
1602*0d69f216Schristos 
1603*0d69f216Schristos 	if (tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET]) {
1604*0d69f216Schristos 		len = nla_len(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET]);
1605*0d69f216Schristos 
1606*0d69f216Schristos 		if (len > sizeof(he_capab->mcs))
1607*0d69f216Schristos 			len = sizeof(he_capab->mcs);
1608*0d69f216Schristos 		os_memcpy(he_capab->mcs,
1609*0d69f216Schristos 			  nla_data(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET]),
1610*0d69f216Schristos 			  len);
1611*0d69f216Schristos 	}
1612*0d69f216Schristos 
1613*0d69f216Schristos 	if (tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE]) {
1614*0d69f216Schristos 		len = nla_len(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE]);
1615*0d69f216Schristos 
1616*0d69f216Schristos 		if (len > sizeof(he_capab->ppet))
1617*0d69f216Schristos 			len = sizeof(he_capab->ppet);
1618*0d69f216Schristos 		os_memcpy(&he_capab->ppet,
1619*0d69f216Schristos 			  nla_data(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE]),
1620*0d69f216Schristos 			  len);
1621*0d69f216Schristos 	}
1622*0d69f216Schristos }
1623*0d69f216Schristos 
1624*0d69f216Schristos 
phy_info_iftype(struct hostapd_hw_modes * mode,struct nlattr * nl_iftype)1625*0d69f216Schristos static int phy_info_iftype(struct hostapd_hw_modes *mode,
1626*0d69f216Schristos 			   struct nlattr *nl_iftype)
1627*0d69f216Schristos {
1628*0d69f216Schristos 	struct nlattr *tb[NL80211_BAND_IFTYPE_ATTR_MAX + 1];
1629*0d69f216Schristos 	struct nlattr *tb_flags[NL80211_IFTYPE_MAX + 1];
1630*0d69f216Schristos 	unsigned int i;
1631*0d69f216Schristos 
1632*0d69f216Schristos 	nla_parse(tb, NL80211_BAND_IFTYPE_ATTR_MAX,
1633*0d69f216Schristos 		  nla_data(nl_iftype), nla_len(nl_iftype), NULL);
1634*0d69f216Schristos 
1635*0d69f216Schristos 	if (!tb[NL80211_BAND_IFTYPE_ATTR_IFTYPES])
1636*0d69f216Schristos 		return NL_STOP;
1637*0d69f216Schristos 
1638*0d69f216Schristos 	if (nla_parse_nested(tb_flags, NL80211_IFTYPE_MAX,
1639*0d69f216Schristos 			     tb[NL80211_BAND_IFTYPE_ATTR_IFTYPES], NULL))
1640*0d69f216Schristos 		return NL_STOP;
1641*0d69f216Schristos 
1642*0d69f216Schristos 	for (i = 0; i < IEEE80211_MODE_NUM; i++)
1643*0d69f216Schristos 		phy_info_iftype_copy(&mode->he_capab[i], i, tb, tb_flags);
1644*0d69f216Schristos 
1645*0d69f216Schristos 	return NL_OK;
1646*0d69f216Schristos }
1647*0d69f216Schristos 
1648*0d69f216Schristos 
phy_info_band(struct phy_info_arg * phy_info,struct nlattr * nl_band)16499a53cbbeSchristos static int phy_info_band(struct phy_info_arg *phy_info, struct nlattr *nl_band)
16509a53cbbeSchristos {
16519a53cbbeSchristos 	struct nlattr *tb_band[NL80211_BAND_ATTR_MAX + 1];
16529a53cbbeSchristos 	struct hostapd_hw_modes *mode;
16539a53cbbeSchristos 	int ret;
16549a53cbbeSchristos 
16559a53cbbeSchristos 	if (phy_info->last_mode != nl_band->nla_type) {
16569a53cbbeSchristos 		mode = os_realloc_array(phy_info->modes,
16579a53cbbeSchristos 					*phy_info->num_modes + 1,
16589a53cbbeSchristos 					sizeof(*mode));
1659928750b6Schristos 		if (!mode) {
1660928750b6Schristos 			phy_info->failed = 1;
1661928750b6Schristos 			return NL_STOP;
1662928750b6Schristos 		}
16639a53cbbeSchristos 		phy_info->modes = mode;
16649a53cbbeSchristos 
16659a53cbbeSchristos 		mode = &phy_info->modes[*(phy_info->num_modes)];
16669a53cbbeSchristos 		os_memset(mode, 0, sizeof(*mode));
16679a53cbbeSchristos 		mode->mode = NUM_HOSTAPD_MODES;
16689a53cbbeSchristos 		mode->flags = HOSTAPD_MODE_FLAG_HT_INFO_KNOWN |
16699a53cbbeSchristos 			HOSTAPD_MODE_FLAG_VHT_INFO_KNOWN;
16709a53cbbeSchristos 
16719a53cbbeSchristos 		/*
16729a53cbbeSchristos 		 * Unsupported VHT MCS stream is defined as value 3, so the VHT
16739a53cbbeSchristos 		 * MCS RX/TX map must be initialized with 0xffff to mark all 8
16749a53cbbeSchristos 		 * possible streams as unsupported. This will be overridden if
16759a53cbbeSchristos 		 * driver advertises VHT support.
16769a53cbbeSchristos 		 */
16779a53cbbeSchristos 		mode->vht_mcs_set[0] = 0xff;
16789a53cbbeSchristos 		mode->vht_mcs_set[1] = 0xff;
16799a53cbbeSchristos 		mode->vht_mcs_set[4] = 0xff;
16809a53cbbeSchristos 		mode->vht_mcs_set[5] = 0xff;
16819a53cbbeSchristos 
16829a53cbbeSchristos 		*(phy_info->num_modes) += 1;
16839a53cbbeSchristos 		phy_info->last_mode = nl_band->nla_type;
16849a53cbbeSchristos 		phy_info->last_chan_idx = 0;
16859a53cbbeSchristos 	} else
16869a53cbbeSchristos 		mode = &phy_info->modes[*(phy_info->num_modes) - 1];
16879a53cbbeSchristos 
16889a53cbbeSchristos 	nla_parse(tb_band, NL80211_BAND_ATTR_MAX, nla_data(nl_band),
16899a53cbbeSchristos 		  nla_len(nl_band), NULL);
16909a53cbbeSchristos 
16919a53cbbeSchristos 	phy_info_ht_capa(mode, tb_band[NL80211_BAND_ATTR_HT_CAPA],
16929a53cbbeSchristos 			 tb_band[NL80211_BAND_ATTR_HT_AMPDU_FACTOR],
16939a53cbbeSchristos 			 tb_band[NL80211_BAND_ATTR_HT_AMPDU_DENSITY],
16949a53cbbeSchristos 			 tb_band[NL80211_BAND_ATTR_HT_MCS_SET]);
16959a53cbbeSchristos 	phy_info_vht_capa(mode, tb_band[NL80211_BAND_ATTR_VHT_CAPA],
16969a53cbbeSchristos 			  tb_band[NL80211_BAND_ATTR_VHT_MCS_SET]);
16979a53cbbeSchristos 	ret = phy_info_freqs(phy_info, mode, tb_band[NL80211_BAND_ATTR_FREQS]);
1698928750b6Schristos 	if (ret == NL_OK)
16999a53cbbeSchristos 		ret = phy_info_rates(mode, tb_band[NL80211_BAND_ATTR_RATES]);
1700928750b6Schristos 	if (ret != NL_OK) {
1701928750b6Schristos 		phy_info->failed = 1;
17029a53cbbeSchristos 		return ret;
1703928750b6Schristos 	}
17049a53cbbeSchristos 
1705*0d69f216Schristos 	if (tb_band[NL80211_BAND_ATTR_IFTYPE_DATA]) {
1706*0d69f216Schristos 		struct nlattr *nl_iftype;
1707*0d69f216Schristos 		int rem_band;
1708*0d69f216Schristos 
1709*0d69f216Schristos 		nla_for_each_nested(nl_iftype,
1710*0d69f216Schristos 				    tb_band[NL80211_BAND_ATTR_IFTYPE_DATA],
1711*0d69f216Schristos 				    rem_band) {
1712*0d69f216Schristos 			ret = phy_info_iftype(mode, nl_iftype);
1713*0d69f216Schristos 			if (ret != NL_OK)
1714*0d69f216Schristos 				return ret;
1715*0d69f216Schristos 		}
1716*0d69f216Schristos 	}
1717*0d69f216Schristos 
17189a53cbbeSchristos 	return NL_OK;
17199a53cbbeSchristos }
17209a53cbbeSchristos 
17219a53cbbeSchristos 
phy_info_handler(struct nl_msg * msg,void * arg)17229a53cbbeSchristos static int phy_info_handler(struct nl_msg *msg, void *arg)
17239a53cbbeSchristos {
17249a53cbbeSchristos 	struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
17259a53cbbeSchristos 	struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
17269a53cbbeSchristos 	struct phy_info_arg *phy_info = arg;
17279a53cbbeSchristos 	struct nlattr *nl_band;
17289a53cbbeSchristos 	int rem_band;
17299a53cbbeSchristos 
17309a53cbbeSchristos 	nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
17319a53cbbeSchristos 		  genlmsg_attrlen(gnlh, 0), NULL);
17329a53cbbeSchristos 
17339a53cbbeSchristos 	if (!tb_msg[NL80211_ATTR_WIPHY_BANDS])
17349a53cbbeSchristos 		return NL_SKIP;
17359a53cbbeSchristos 
17369a53cbbeSchristos 	nla_for_each_nested(nl_band, tb_msg[NL80211_ATTR_WIPHY_BANDS], rem_band)
17379a53cbbeSchristos 	{
17389a53cbbeSchristos 		int res = phy_info_band(phy_info, nl_band);
17399a53cbbeSchristos 		if (res != NL_OK)
17409a53cbbeSchristos 			return res;
17419a53cbbeSchristos 	}
17429a53cbbeSchristos 
17439a53cbbeSchristos 	return NL_SKIP;
17449a53cbbeSchristos }
17459a53cbbeSchristos 
17469a53cbbeSchristos 
17479a53cbbeSchristos static struct hostapd_hw_modes *
wpa_driver_nl80211_postprocess_modes(struct hostapd_hw_modes * modes,u16 * num_modes)17489a53cbbeSchristos wpa_driver_nl80211_postprocess_modes(struct hostapd_hw_modes *modes,
17499a53cbbeSchristos 				     u16 *num_modes)
17509a53cbbeSchristos {
17519a53cbbeSchristos 	u16 m;
17529a53cbbeSchristos 	struct hostapd_hw_modes *mode11g = NULL, *nmodes, *mode;
17539a53cbbeSchristos 	int i, mode11g_idx = -1;
17549a53cbbeSchristos 
17559a53cbbeSchristos 	/* heuristic to set up modes */
17569a53cbbeSchristos 	for (m = 0; m < *num_modes; m++) {
17579a53cbbeSchristos 		if (!modes[m].num_channels)
17589a53cbbeSchristos 			continue;
17599a53cbbeSchristos 		if (modes[m].channels[0].freq < 4000) {
17609a53cbbeSchristos 			modes[m].mode = HOSTAPD_MODE_IEEE80211B;
17619a53cbbeSchristos 			for (i = 0; i < modes[m].num_rates; i++) {
17629a53cbbeSchristos 				if (modes[m].rates[i] > 200) {
17639a53cbbeSchristos 					modes[m].mode = HOSTAPD_MODE_IEEE80211G;
17649a53cbbeSchristos 					break;
17659a53cbbeSchristos 				}
17669a53cbbeSchristos 			}
17679a53cbbeSchristos 		} else if (modes[m].channels[0].freq > 50000)
17689a53cbbeSchristos 			modes[m].mode = HOSTAPD_MODE_IEEE80211AD;
17699a53cbbeSchristos 		else
17709a53cbbeSchristos 			modes[m].mode = HOSTAPD_MODE_IEEE80211A;
17719a53cbbeSchristos 	}
17729a53cbbeSchristos 
17739a53cbbeSchristos 	/* If only 802.11g mode is included, use it to construct matching
17749a53cbbeSchristos 	 * 802.11b mode data. */
17759a53cbbeSchristos 
17769a53cbbeSchristos 	for (m = 0; m < *num_modes; m++) {
17779a53cbbeSchristos 		if (modes[m].mode == HOSTAPD_MODE_IEEE80211B)
17789a53cbbeSchristos 			return modes; /* 802.11b already included */
17799a53cbbeSchristos 		if (modes[m].mode == HOSTAPD_MODE_IEEE80211G)
17809a53cbbeSchristos 			mode11g_idx = m;
17819a53cbbeSchristos 	}
17829a53cbbeSchristos 
17839a53cbbeSchristos 	if (mode11g_idx < 0)
17849a53cbbeSchristos 		return modes; /* 2.4 GHz band not supported at all */
17859a53cbbeSchristos 
17869a53cbbeSchristos 	nmodes = os_realloc_array(modes, *num_modes + 1, sizeof(*nmodes));
17879a53cbbeSchristos 	if (nmodes == NULL)
17889a53cbbeSchristos 		return modes; /* Could not add 802.11b mode */
17899a53cbbeSchristos 
17909a53cbbeSchristos 	mode = &nmodes[*num_modes];
17919a53cbbeSchristos 	os_memset(mode, 0, sizeof(*mode));
17929a53cbbeSchristos 	(*num_modes)++;
17939a53cbbeSchristos 	modes = nmodes;
17949a53cbbeSchristos 
17959a53cbbeSchristos 	mode->mode = HOSTAPD_MODE_IEEE80211B;
17969a53cbbeSchristos 
17979a53cbbeSchristos 	mode11g = &modes[mode11g_idx];
17989a53cbbeSchristos 	mode->num_channels = mode11g->num_channels;
1799ebb5671cSchristos 	mode->channels = os_memdup(mode11g->channels,
1800ebb5671cSchristos 				   mode11g->num_channels *
18019a53cbbeSchristos 				   sizeof(struct hostapd_channel_data));
18029a53cbbeSchristos 	if (mode->channels == NULL) {
18039a53cbbeSchristos 		(*num_modes)--;
18049a53cbbeSchristos 		return modes; /* Could not add 802.11b mode */
18059a53cbbeSchristos 	}
18069a53cbbeSchristos 
18079a53cbbeSchristos 	mode->num_rates = 0;
18089a53cbbeSchristos 	mode->rates = os_malloc(4 * sizeof(int));
18099a53cbbeSchristos 	if (mode->rates == NULL) {
18109a53cbbeSchristos 		os_free(mode->channels);
18119a53cbbeSchristos 		(*num_modes)--;
18129a53cbbeSchristos 		return modes; /* Could not add 802.11b mode */
18139a53cbbeSchristos 	}
18149a53cbbeSchristos 
18159a53cbbeSchristos 	for (i = 0; i < mode11g->num_rates; i++) {
18169a53cbbeSchristos 		if (mode11g->rates[i] != 10 && mode11g->rates[i] != 20 &&
18179a53cbbeSchristos 		    mode11g->rates[i] != 55 && mode11g->rates[i] != 110)
18189a53cbbeSchristos 			continue;
18199a53cbbeSchristos 		mode->rates[mode->num_rates] = mode11g->rates[i];
18209a53cbbeSchristos 		mode->num_rates++;
18219a53cbbeSchristos 		if (mode->num_rates == 4)
18229a53cbbeSchristos 			break;
18239a53cbbeSchristos 	}
18249a53cbbeSchristos 
18259a53cbbeSchristos 	if (mode->num_rates == 0) {
18269a53cbbeSchristos 		os_free(mode->channels);
18279a53cbbeSchristos 		os_free(mode->rates);
18289a53cbbeSchristos 		(*num_modes)--;
18299a53cbbeSchristos 		return modes; /* No 802.11b rates */
18309a53cbbeSchristos 	}
18319a53cbbeSchristos 
18329a53cbbeSchristos 	wpa_printf(MSG_DEBUG, "nl80211: Added 802.11b mode based on 802.11g "
18339a53cbbeSchristos 		   "information");
18349a53cbbeSchristos 
18359a53cbbeSchristos 	return modes;
18369a53cbbeSchristos }
18379a53cbbeSchristos 
18389a53cbbeSchristos 
nl80211_set_ht40_mode(struct hostapd_hw_modes * mode,int start,int end)18399a53cbbeSchristos static void nl80211_set_ht40_mode(struct hostapd_hw_modes *mode, int start,
18409a53cbbeSchristos 				  int end)
18419a53cbbeSchristos {
18429a53cbbeSchristos 	int c;
18439a53cbbeSchristos 
18449a53cbbeSchristos 	for (c = 0; c < mode->num_channels; c++) {
18459a53cbbeSchristos 		struct hostapd_channel_data *chan = &mode->channels[c];
18469a53cbbeSchristos 		if (chan->freq - 10 >= start && chan->freq + 10 <= end)
18479a53cbbeSchristos 			chan->flag |= HOSTAPD_CHAN_HT40;
18489a53cbbeSchristos 	}
18499a53cbbeSchristos }
18509a53cbbeSchristos 
18519a53cbbeSchristos 
nl80211_set_ht40_mode_sec(struct hostapd_hw_modes * mode,int start,int end)18529a53cbbeSchristos static void nl80211_set_ht40_mode_sec(struct hostapd_hw_modes *mode, int start,
18539a53cbbeSchristos 				      int end)
18549a53cbbeSchristos {
18559a53cbbeSchristos 	int c;
18569a53cbbeSchristos 
18579a53cbbeSchristos 	for (c = 0; c < mode->num_channels; c++) {
18589a53cbbeSchristos 		struct hostapd_channel_data *chan = &mode->channels[c];
18599a53cbbeSchristos 		if (!(chan->flag & HOSTAPD_CHAN_HT40))
18609a53cbbeSchristos 			continue;
18619a53cbbeSchristos 		if (chan->freq - 30 >= start && chan->freq - 10 <= end)
18629a53cbbeSchristos 			chan->flag |= HOSTAPD_CHAN_HT40MINUS;
18639a53cbbeSchristos 		if (chan->freq + 10 >= start && chan->freq + 30 <= end)
18649a53cbbeSchristos 			chan->flag |= HOSTAPD_CHAN_HT40PLUS;
18659a53cbbeSchristos 	}
18669a53cbbeSchristos }
18679a53cbbeSchristos 
18689a53cbbeSchristos 
nl80211_reg_rule_max_eirp(u32 start,u32 end,u32 max_eirp,struct phy_info_arg * results)18699a53cbbeSchristos static void nl80211_reg_rule_max_eirp(u32 start, u32 end, u32 max_eirp,
18709a53cbbeSchristos 				      struct phy_info_arg *results)
18719a53cbbeSchristos {
18729a53cbbeSchristos 	u16 m;
18739a53cbbeSchristos 
18749a53cbbeSchristos 	for (m = 0; m < *results->num_modes; m++) {
18759a53cbbeSchristos 		int c;
18769a53cbbeSchristos 		struct hostapd_hw_modes *mode = &results->modes[m];
18779a53cbbeSchristos 
18789a53cbbeSchristos 		for (c = 0; c < mode->num_channels; c++) {
18799a53cbbeSchristos 			struct hostapd_channel_data *chan = &mode->channels[c];
18809a53cbbeSchristos 			if ((u32) chan->freq - 10 >= start &&
18819a53cbbeSchristos 			    (u32) chan->freq + 10 <= end)
18829a53cbbeSchristos 				chan->max_tx_power = max_eirp;
18839a53cbbeSchristos 		}
18849a53cbbeSchristos 	}
18859a53cbbeSchristos }
18869a53cbbeSchristos 
18879a53cbbeSchristos 
nl80211_reg_rule_ht40(u32 start,u32 end,struct phy_info_arg * results)18889a53cbbeSchristos static void nl80211_reg_rule_ht40(u32 start, u32 end,
18899a53cbbeSchristos 				  struct phy_info_arg *results)
18909a53cbbeSchristos {
18919a53cbbeSchristos 	u16 m;
18929a53cbbeSchristos 
18939a53cbbeSchristos 	for (m = 0; m < *results->num_modes; m++) {
18949a53cbbeSchristos 		if (!(results->modes[m].ht_capab &
18959a53cbbeSchristos 		      HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET))
18969a53cbbeSchristos 			continue;
18979a53cbbeSchristos 		nl80211_set_ht40_mode(&results->modes[m], start, end);
18989a53cbbeSchristos 	}
18999a53cbbeSchristos }
19009a53cbbeSchristos 
19019a53cbbeSchristos 
nl80211_reg_rule_sec(struct nlattr * tb[],struct phy_info_arg * results)19029a53cbbeSchristos static void nl80211_reg_rule_sec(struct nlattr *tb[],
19039a53cbbeSchristos 				 struct phy_info_arg *results)
19049a53cbbeSchristos {
19059a53cbbeSchristos 	u32 start, end, max_bw;
19069a53cbbeSchristos 	u16 m;
19079a53cbbeSchristos 
19089a53cbbeSchristos 	if (tb[NL80211_ATTR_FREQ_RANGE_START] == NULL ||
19099a53cbbeSchristos 	    tb[NL80211_ATTR_FREQ_RANGE_END] == NULL ||
19109a53cbbeSchristos 	    tb[NL80211_ATTR_FREQ_RANGE_MAX_BW] == NULL)
19119a53cbbeSchristos 		return;
19129a53cbbeSchristos 
19139a53cbbeSchristos 	start = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]) / 1000;
19149a53cbbeSchristos 	end = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]) / 1000;
19159a53cbbeSchristos 	max_bw = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) / 1000;
19169a53cbbeSchristos 
19179a53cbbeSchristos 	if (max_bw < 20)
19189a53cbbeSchristos 		return;
19199a53cbbeSchristos 
19209a53cbbeSchristos 	for (m = 0; m < *results->num_modes; m++) {
19219a53cbbeSchristos 		if (!(results->modes[m].ht_capab &
19229a53cbbeSchristos 		      HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET))
19239a53cbbeSchristos 			continue;
19249a53cbbeSchristos 		nl80211_set_ht40_mode_sec(&results->modes[m], start, end);
19259a53cbbeSchristos 	}
19269a53cbbeSchristos }
19279a53cbbeSchristos 
19289a53cbbeSchristos 
nl80211_set_vht_mode(struct hostapd_hw_modes * mode,int start,int end,int max_bw)19299a53cbbeSchristos static void nl80211_set_vht_mode(struct hostapd_hw_modes *mode, int start,
1930928750b6Schristos 				 int end, int max_bw)
19319a53cbbeSchristos {
19329a53cbbeSchristos 	int c;
19339a53cbbeSchristos 
19349a53cbbeSchristos 	for (c = 0; c < mode->num_channels; c++) {
19359a53cbbeSchristos 		struct hostapd_channel_data *chan = &mode->channels[c];
19369a53cbbeSchristos 		if (chan->freq - 10 >= start && chan->freq + 70 <= end)
19379a53cbbeSchristos 			chan->flag |= HOSTAPD_CHAN_VHT_10_70;
19389a53cbbeSchristos 
19399a53cbbeSchristos 		if (chan->freq - 30 >= start && chan->freq + 50 <= end)
19409a53cbbeSchristos 			chan->flag |= HOSTAPD_CHAN_VHT_30_50;
19419a53cbbeSchristos 
19429a53cbbeSchristos 		if (chan->freq - 50 >= start && chan->freq + 30 <= end)
19439a53cbbeSchristos 			chan->flag |= HOSTAPD_CHAN_VHT_50_30;
19449a53cbbeSchristos 
19459a53cbbeSchristos 		if (chan->freq - 70 >= start && chan->freq + 10 <= end)
19469a53cbbeSchristos 			chan->flag |= HOSTAPD_CHAN_VHT_70_10;
1947928750b6Schristos 
1948928750b6Schristos 		if (max_bw >= 160) {
1949928750b6Schristos 			if (chan->freq - 10 >= start && chan->freq + 150 <= end)
1950928750b6Schristos 				chan->flag |= HOSTAPD_CHAN_VHT_10_150;
1951928750b6Schristos 
1952928750b6Schristos 			if (chan->freq - 30 >= start && chan->freq + 130 <= end)
1953928750b6Schristos 				chan->flag |= HOSTAPD_CHAN_VHT_30_130;
1954928750b6Schristos 
1955928750b6Schristos 			if (chan->freq - 50 >= start && chan->freq + 110 <= end)
1956928750b6Schristos 				chan->flag |= HOSTAPD_CHAN_VHT_50_110;
1957928750b6Schristos 
1958928750b6Schristos 			if (chan->freq - 70 >= start && chan->freq + 90 <= end)
1959928750b6Schristos 				chan->flag |= HOSTAPD_CHAN_VHT_70_90;
1960928750b6Schristos 
1961928750b6Schristos 			if (chan->freq - 90 >= start && chan->freq + 70 <= end)
1962928750b6Schristos 				chan->flag |= HOSTAPD_CHAN_VHT_90_70;
1963928750b6Schristos 
1964928750b6Schristos 			if (chan->freq - 110 >= start && chan->freq + 50 <= end)
1965928750b6Schristos 				chan->flag |= HOSTAPD_CHAN_VHT_110_50;
1966928750b6Schristos 
1967928750b6Schristos 			if (chan->freq - 130 >= start && chan->freq + 30 <= end)
1968928750b6Schristos 				chan->flag |= HOSTAPD_CHAN_VHT_130_30;
1969928750b6Schristos 
1970928750b6Schristos 			if (chan->freq - 150 >= start && chan->freq + 10 <= end)
1971928750b6Schristos 				chan->flag |= HOSTAPD_CHAN_VHT_150_10;
1972928750b6Schristos 		}
19739a53cbbeSchristos 	}
19749a53cbbeSchristos }
19759a53cbbeSchristos 
19769a53cbbeSchristos 
nl80211_reg_rule_vht(struct nlattr * tb[],struct phy_info_arg * results)19779a53cbbeSchristos static void nl80211_reg_rule_vht(struct nlattr *tb[],
19789a53cbbeSchristos 				 struct phy_info_arg *results)
19799a53cbbeSchristos {
19809a53cbbeSchristos 	u32 start, end, max_bw;
19819a53cbbeSchristos 	u16 m;
19829a53cbbeSchristos 
19839a53cbbeSchristos 	if (tb[NL80211_ATTR_FREQ_RANGE_START] == NULL ||
19849a53cbbeSchristos 	    tb[NL80211_ATTR_FREQ_RANGE_END] == NULL ||
19859a53cbbeSchristos 	    tb[NL80211_ATTR_FREQ_RANGE_MAX_BW] == NULL)
19869a53cbbeSchristos 		return;
19879a53cbbeSchristos 
19889a53cbbeSchristos 	start = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]) / 1000;
19899a53cbbeSchristos 	end = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]) / 1000;
19909a53cbbeSchristos 	max_bw = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) / 1000;
19919a53cbbeSchristos 
19929a53cbbeSchristos 	if (max_bw < 80)
19939a53cbbeSchristos 		return;
19949a53cbbeSchristos 
19959a53cbbeSchristos 	for (m = 0; m < *results->num_modes; m++) {
19969a53cbbeSchristos 		if (!(results->modes[m].ht_capab &
19979a53cbbeSchristos 		      HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET))
19989a53cbbeSchristos 			continue;
19999a53cbbeSchristos 		/* TODO: use a real VHT support indication */
20009a53cbbeSchristos 		if (!results->modes[m].vht_capab)
20019a53cbbeSchristos 			continue;
20029a53cbbeSchristos 
2003928750b6Schristos 		nl80211_set_vht_mode(&results->modes[m], start, end, max_bw);
20049a53cbbeSchristos 	}
20059a53cbbeSchristos }
20069a53cbbeSchristos 
20079a53cbbeSchristos 
nl80211_set_dfs_domain(enum nl80211_dfs_regions region,u8 * dfs_domain)2008ebb5671cSchristos static void nl80211_set_dfs_domain(enum nl80211_dfs_regions region,
2009ebb5671cSchristos 				   u8 *dfs_domain)
2010ebb5671cSchristos {
2011ebb5671cSchristos 	if (region == NL80211_DFS_FCC)
2012ebb5671cSchristos 		*dfs_domain = HOSTAPD_DFS_REGION_FCC;
2013ebb5671cSchristos 	else if (region == NL80211_DFS_ETSI)
2014ebb5671cSchristos 		*dfs_domain = HOSTAPD_DFS_REGION_ETSI;
2015ebb5671cSchristos 	else if (region == NL80211_DFS_JP)
2016ebb5671cSchristos 		*dfs_domain = HOSTAPD_DFS_REGION_JP;
2017ebb5671cSchristos 	else
2018ebb5671cSchristos 		*dfs_domain = 0;
2019ebb5671cSchristos }
2020ebb5671cSchristos 
2021ebb5671cSchristos 
dfs_domain_name(enum nl80211_dfs_regions region)20229a53cbbeSchristos static const char * dfs_domain_name(enum nl80211_dfs_regions region)
20239a53cbbeSchristos {
20249a53cbbeSchristos 	switch (region) {
20259a53cbbeSchristos 	case NL80211_DFS_UNSET:
20269a53cbbeSchristos 		return "DFS-UNSET";
20279a53cbbeSchristos 	case NL80211_DFS_FCC:
20289a53cbbeSchristos 		return "DFS-FCC";
20299a53cbbeSchristos 	case NL80211_DFS_ETSI:
20309a53cbbeSchristos 		return "DFS-ETSI";
20319a53cbbeSchristos 	case NL80211_DFS_JP:
20329a53cbbeSchristos 		return "DFS-JP";
20339a53cbbeSchristos 	default:
20349a53cbbeSchristos 		return "DFS-invalid";
20359a53cbbeSchristos 	}
20369a53cbbeSchristos }
20379a53cbbeSchristos 
20389a53cbbeSchristos 
nl80211_get_reg(struct nl_msg * msg,void * arg)20399a53cbbeSchristos static int nl80211_get_reg(struct nl_msg *msg, void *arg)
20409a53cbbeSchristos {
20419a53cbbeSchristos 	struct phy_info_arg *results = arg;
20429a53cbbeSchristos 	struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
20439a53cbbeSchristos 	struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
20449a53cbbeSchristos 	struct nlattr *nl_rule;
20459a53cbbeSchristos 	struct nlattr *tb_rule[NL80211_FREQUENCY_ATTR_MAX + 1];
20469a53cbbeSchristos 	int rem_rule;
20479a53cbbeSchristos 	static struct nla_policy reg_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = {
20489a53cbbeSchristos 		[NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
20499a53cbbeSchristos 		[NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
20509a53cbbeSchristos 		[NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
20519a53cbbeSchristos 		[NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
20529a53cbbeSchristos 		[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
20539a53cbbeSchristos 		[NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
20549a53cbbeSchristos 	};
20559a53cbbeSchristos 
20569a53cbbeSchristos 	nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
20579a53cbbeSchristos 		  genlmsg_attrlen(gnlh, 0), NULL);
20589a53cbbeSchristos 	if (!tb_msg[NL80211_ATTR_REG_ALPHA2] ||
20599a53cbbeSchristos 	    !tb_msg[NL80211_ATTR_REG_RULES]) {
20609a53cbbeSchristos 		wpa_printf(MSG_DEBUG, "nl80211: No regulatory information "
20619a53cbbeSchristos 			   "available");
20629a53cbbeSchristos 		return NL_SKIP;
20639a53cbbeSchristos 	}
20649a53cbbeSchristos 
20659a53cbbeSchristos 	if (tb_msg[NL80211_ATTR_DFS_REGION]) {
20669a53cbbeSchristos 		enum nl80211_dfs_regions dfs_domain;
20679a53cbbeSchristos 		dfs_domain = nla_get_u8(tb_msg[NL80211_ATTR_DFS_REGION]);
2068ebb5671cSchristos 		nl80211_set_dfs_domain(dfs_domain, &results->dfs_domain);
20699a53cbbeSchristos 		wpa_printf(MSG_DEBUG, "nl80211: Regulatory information - country=%s (%s)",
20709a53cbbeSchristos 			   (char *) nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]),
20719a53cbbeSchristos 			   dfs_domain_name(dfs_domain));
20729a53cbbeSchristos 	} else {
20739a53cbbeSchristos 		wpa_printf(MSG_DEBUG, "nl80211: Regulatory information - country=%s",
20749a53cbbeSchristos 			   (char *) nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]));
20759a53cbbeSchristos 	}
20769a53cbbeSchristos 
20779a53cbbeSchristos 	nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule)
20789a53cbbeSchristos 	{
20799a53cbbeSchristos 		u32 start, end, max_eirp = 0, max_bw = 0, flags = 0;
20809a53cbbeSchristos 		nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX,
20819a53cbbeSchristos 			  nla_data(nl_rule), nla_len(nl_rule), reg_policy);
20829a53cbbeSchristos 		if (tb_rule[NL80211_ATTR_FREQ_RANGE_START] == NULL ||
20839a53cbbeSchristos 		    tb_rule[NL80211_ATTR_FREQ_RANGE_END] == NULL)
20849a53cbbeSchristos 			continue;
20859a53cbbeSchristos 		start = nla_get_u32(tb_rule[NL80211_ATTR_FREQ_RANGE_START]) / 1000;
20869a53cbbeSchristos 		end = nla_get_u32(tb_rule[NL80211_ATTR_FREQ_RANGE_END]) / 1000;
20879a53cbbeSchristos 		if (tb_rule[NL80211_ATTR_POWER_RULE_MAX_EIRP])
20889a53cbbeSchristos 			max_eirp = nla_get_u32(tb_rule[NL80211_ATTR_POWER_RULE_MAX_EIRP]) / 100;
20899a53cbbeSchristos 		if (tb_rule[NL80211_ATTR_FREQ_RANGE_MAX_BW])
20909a53cbbeSchristos 			max_bw = nla_get_u32(tb_rule[NL80211_ATTR_FREQ_RANGE_MAX_BW]) / 1000;
20919a53cbbeSchristos 		if (tb_rule[NL80211_ATTR_REG_RULE_FLAGS])
20929a53cbbeSchristos 			flags = nla_get_u32(tb_rule[NL80211_ATTR_REG_RULE_FLAGS]);
20939a53cbbeSchristos 
20949a53cbbeSchristos 		wpa_printf(MSG_DEBUG, "nl80211: %u-%u @ %u MHz %u mBm%s%s%s%s%s%s%s%s",
20959a53cbbeSchristos 			   start, end, max_bw, max_eirp,
20969a53cbbeSchristos 			   flags & NL80211_RRF_NO_OFDM ? " (no OFDM)" : "",
20979a53cbbeSchristos 			   flags & NL80211_RRF_NO_CCK ? " (no CCK)" : "",
20989a53cbbeSchristos 			   flags & NL80211_RRF_NO_INDOOR ? " (no indoor)" : "",
20999a53cbbeSchristos 			   flags & NL80211_RRF_NO_OUTDOOR ? " (no outdoor)" :
21009a53cbbeSchristos 			   "",
21019a53cbbeSchristos 			   flags & NL80211_RRF_DFS ? " (DFS)" : "",
21029a53cbbeSchristos 			   flags & NL80211_RRF_PTP_ONLY ? " (PTP only)" : "",
21039a53cbbeSchristos 			   flags & NL80211_RRF_PTMP_ONLY ? " (PTMP only)" : "",
21049a53cbbeSchristos 			   flags & NL80211_RRF_NO_IR ? " (no IR)" : "");
21059a53cbbeSchristos 		if (max_bw >= 40)
21069a53cbbeSchristos 			nl80211_reg_rule_ht40(start, end, results);
21079a53cbbeSchristos 		if (tb_rule[NL80211_ATTR_POWER_RULE_MAX_EIRP])
21089a53cbbeSchristos 			nl80211_reg_rule_max_eirp(start, end, max_eirp,
21099a53cbbeSchristos 						  results);
21109a53cbbeSchristos 	}
21119a53cbbeSchristos 
21129a53cbbeSchristos 	nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule)
21139a53cbbeSchristos 	{
21149a53cbbeSchristos 		nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX,
21159a53cbbeSchristos 			  nla_data(nl_rule), nla_len(nl_rule), reg_policy);
21169a53cbbeSchristos 		nl80211_reg_rule_sec(tb_rule, results);
21179a53cbbeSchristos 	}
21189a53cbbeSchristos 
21199a53cbbeSchristos 	nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule)
21209a53cbbeSchristos 	{
21219a53cbbeSchristos 		nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX,
21229a53cbbeSchristos 			  nla_data(nl_rule), nla_len(nl_rule), reg_policy);
21239a53cbbeSchristos 		nl80211_reg_rule_vht(tb_rule, results);
21249a53cbbeSchristos 	}
21259a53cbbeSchristos 
21269a53cbbeSchristos 	return NL_SKIP;
21279a53cbbeSchristos }
21289a53cbbeSchristos 
21299a53cbbeSchristos 
nl80211_set_regulatory_flags(struct wpa_driver_nl80211_data * drv,struct phy_info_arg * results)21309a53cbbeSchristos static int nl80211_set_regulatory_flags(struct wpa_driver_nl80211_data *drv,
21319a53cbbeSchristos 					struct phy_info_arg *results)
21329a53cbbeSchristos {
21339a53cbbeSchristos 	struct nl_msg *msg;
21349a53cbbeSchristos 
21359a53cbbeSchristos 	msg = nlmsg_alloc();
21369a53cbbeSchristos 	if (!msg)
21379a53cbbeSchristos 		return -ENOMEM;
21389a53cbbeSchristos 
21399a53cbbeSchristos 	nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG);
2140ebb5671cSchristos 	if (drv->capa.flags & WPA_DRIVER_FLAGS_SELF_MANAGED_REGULATORY) {
2141ebb5671cSchristos 		if (nla_put_u32(msg, NL80211_ATTR_WIPHY, drv->wiphy_idx)) {
2142ebb5671cSchristos 			nlmsg_free(msg);
2143ebb5671cSchristos 			return -1;
2144ebb5671cSchristos 		}
2145ebb5671cSchristos 	}
2146ebb5671cSchristos 
21479a53cbbeSchristos 	return send_and_recv_msgs(drv, msg, nl80211_get_reg, results);
21489a53cbbeSchristos }
21499a53cbbeSchristos 
21509a53cbbeSchristos 
modestr(enum hostapd_hw_mode mode)2151*0d69f216Schristos static const char * modestr(enum hostapd_hw_mode mode)
2152*0d69f216Schristos {
2153*0d69f216Schristos 	switch (mode) {
2154*0d69f216Schristos 	case HOSTAPD_MODE_IEEE80211B:
2155*0d69f216Schristos 		return "802.11b";
2156*0d69f216Schristos 	case HOSTAPD_MODE_IEEE80211G:
2157*0d69f216Schristos 		return "802.11g";
2158*0d69f216Schristos 	case HOSTAPD_MODE_IEEE80211A:
2159*0d69f216Schristos 		return "802.11a";
2160*0d69f216Schristos 	case HOSTAPD_MODE_IEEE80211AD:
2161*0d69f216Schristos 		return "802.11ad";
2162*0d69f216Schristos 	default:
2163*0d69f216Schristos 		return "?";
2164*0d69f216Schristos 	}
2165*0d69f216Schristos }
2166*0d69f216Schristos 
2167*0d69f216Schristos 
nl80211_dump_chan_list(struct hostapd_hw_modes * modes,u16 num_modes)2168*0d69f216Schristos static void nl80211_dump_chan_list(struct hostapd_hw_modes *modes,
2169*0d69f216Schristos 				   u16 num_modes)
2170*0d69f216Schristos {
2171*0d69f216Schristos 	int i;
2172*0d69f216Schristos 
2173*0d69f216Schristos 	if (!modes)
2174*0d69f216Schristos 		return;
2175*0d69f216Schristos 
2176*0d69f216Schristos 	for (i = 0; i < num_modes; i++) {
2177*0d69f216Schristos 		struct hostapd_hw_modes *mode = &modes[i];
2178*0d69f216Schristos 		char str[200];
2179*0d69f216Schristos 		char *pos = str;
2180*0d69f216Schristos 		char *end = pos + sizeof(str);
2181*0d69f216Schristos 		int j, res;
2182*0d69f216Schristos 
2183*0d69f216Schristos 		for (j = 0; j < mode->num_channels; j++) {
2184*0d69f216Schristos 			struct hostapd_channel_data *chan = &mode->channels[j];
2185*0d69f216Schristos 
2186*0d69f216Schristos 			res = os_snprintf(pos, end - pos, " %d%s%s%s",
2187*0d69f216Schristos 					  chan->freq,
2188*0d69f216Schristos 					  (chan->flag & HOSTAPD_CHAN_DISABLED) ?
2189*0d69f216Schristos 					  "[DISABLED]" : "",
2190*0d69f216Schristos 					  (chan->flag & HOSTAPD_CHAN_NO_IR) ?
2191*0d69f216Schristos 					  "[NO_IR]" : "",
2192*0d69f216Schristos 					  (chan->flag & HOSTAPD_CHAN_RADAR) ?
2193*0d69f216Schristos 					  "[RADAR]" : "");
2194*0d69f216Schristos 			if (os_snprintf_error(end - pos, res))
2195*0d69f216Schristos 				break;
2196*0d69f216Schristos 			pos += res;
2197*0d69f216Schristos 		}
2198*0d69f216Schristos 
2199*0d69f216Schristos 		*pos = '\0';
2200*0d69f216Schristos 		wpa_printf(MSG_DEBUG, "nl80211: Mode IEEE %s:%s",
2201*0d69f216Schristos 			   modestr(mode->mode), str);
2202*0d69f216Schristos 	}
2203*0d69f216Schristos }
2204*0d69f216Schristos 
2205*0d69f216Schristos 
22069a53cbbeSchristos struct hostapd_hw_modes *
nl80211_get_hw_feature_data(void * priv,u16 * num_modes,u16 * flags,u8 * dfs_domain)2207ebb5671cSchristos nl80211_get_hw_feature_data(void *priv, u16 *num_modes, u16 *flags,
2208ebb5671cSchristos 			    u8 *dfs_domain)
22099a53cbbeSchristos {
22109a53cbbeSchristos 	u32 feat;
22119a53cbbeSchristos 	struct i802_bss *bss = priv;
22129a53cbbeSchristos 	struct wpa_driver_nl80211_data *drv = bss->drv;
22139a53cbbeSchristos 	int nl_flags = 0;
22149a53cbbeSchristos 	struct nl_msg *msg;
22159a53cbbeSchristos 	struct phy_info_arg result = {
22169a53cbbeSchristos 		.num_modes = num_modes,
22179a53cbbeSchristos 		.modes = NULL,
22189a53cbbeSchristos 		.last_mode = -1,
2219928750b6Schristos 		.failed = 0,
2220ebb5671cSchristos 		.dfs_domain = 0,
22219a53cbbeSchristos 	};
22229a53cbbeSchristos 
22239a53cbbeSchristos 	*num_modes = 0;
22249a53cbbeSchristos 	*flags = 0;
2225ebb5671cSchristos 	*dfs_domain = 0;
22269a53cbbeSchristos 
22279a53cbbeSchristos 	feat = get_nl80211_protocol_features(drv);
22289a53cbbeSchristos 	if (feat & NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)
22299a53cbbeSchristos 		nl_flags = NLM_F_DUMP;
22309a53cbbeSchristos 	if (!(msg = nl80211_cmd_msg(bss, nl_flags, NL80211_CMD_GET_WIPHY)) ||
22319a53cbbeSchristos 	    nla_put_flag(msg, NL80211_ATTR_SPLIT_WIPHY_DUMP)) {
22329a53cbbeSchristos 		nlmsg_free(msg);
22339a53cbbeSchristos 		return NULL;
22349a53cbbeSchristos 	}
22359a53cbbeSchristos 
22369a53cbbeSchristos 	if (send_and_recv_msgs(drv, msg, phy_info_handler, &result) == 0) {
2237*0d69f216Schristos 		struct hostapd_hw_modes *modes;
2238*0d69f216Schristos 
22399a53cbbeSchristos 		nl80211_set_regulatory_flags(drv, &result);
2240928750b6Schristos 		if (result.failed) {
2241928750b6Schristos 			int i;
2242928750b6Schristos 
2243928750b6Schristos 			for (i = 0; result.modes && i < *num_modes; i++) {
2244928750b6Schristos 				os_free(result.modes[i].channels);
2245928750b6Schristos 				os_free(result.modes[i].rates);
2246928750b6Schristos 			}
2247928750b6Schristos 			os_free(result.modes);
2248ebb5671cSchristos 			*num_modes = 0;
2249928750b6Schristos 			return NULL;
2250928750b6Schristos 		}
2251ebb5671cSchristos 
2252ebb5671cSchristos 		*dfs_domain = result.dfs_domain;
2253ebb5671cSchristos 
2254*0d69f216Schristos 		modes = wpa_driver_nl80211_postprocess_modes(result.modes,
22559a53cbbeSchristos 							     num_modes);
2256*0d69f216Schristos 		nl80211_dump_chan_list(modes, *num_modes);
2257*0d69f216Schristos 		return modes;
22589a53cbbeSchristos 	}
22599a53cbbeSchristos 
22609a53cbbeSchristos 	return NULL;
22619a53cbbeSchristos }
2262