15b9c547cSRui Paulo /*
25b9c547cSRui Paulo * Driver interaction with Linux nl80211/cfg80211 - Capabilities
35b9c547cSRui Paulo * Copyright (c) 2002-2015, Jouni Malinen <j@w1.fi>
45b9c547cSRui Paulo * Copyright (c) 2007, Johannes Berg <johannes@sipsolutions.net>
55b9c547cSRui Paulo * Copyright (c) 2009-2010, Atheros Communications
65b9c547cSRui Paulo *
75b9c547cSRui Paulo * This software may be distributed under the terms of the BSD license.
85b9c547cSRui Paulo * See README for more details.
95b9c547cSRui Paulo */
105b9c547cSRui Paulo
115b9c547cSRui Paulo #include "includes.h"
125b9c547cSRui Paulo #include <netlink/genl/genl.h>
135b9c547cSRui Paulo
145b9c547cSRui Paulo #include "utils/common.h"
155b9c547cSRui Paulo #include "common/ieee802_11_common.h"
1685732ac8SCy Schubert #include "common/wpa_common.h"
175b9c547cSRui Paulo #include "common/qca-vendor.h"
185b9c547cSRui Paulo #include "common/qca-vendor-attr.h"
19c1d255d3SCy Schubert #include "common/brcm_vendor.h"
205b9c547cSRui Paulo #include "driver_nl80211.h"
215b9c547cSRui Paulo
225b9c547cSRui Paulo
protocol_feature_handler(struct nl_msg * msg,void * arg)235b9c547cSRui Paulo static int protocol_feature_handler(struct nl_msg *msg, void *arg)
245b9c547cSRui Paulo {
255b9c547cSRui Paulo u32 *feat = arg;
265b9c547cSRui Paulo struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
275b9c547cSRui Paulo struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
285b9c547cSRui Paulo
295b9c547cSRui Paulo nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
305b9c547cSRui Paulo genlmsg_attrlen(gnlh, 0), NULL);
315b9c547cSRui Paulo
325b9c547cSRui Paulo if (tb_msg[NL80211_ATTR_PROTOCOL_FEATURES])
335b9c547cSRui Paulo *feat = nla_get_u32(tb_msg[NL80211_ATTR_PROTOCOL_FEATURES]);
345b9c547cSRui Paulo
355b9c547cSRui Paulo return NL_SKIP;
365b9c547cSRui Paulo }
375b9c547cSRui Paulo
385b9c547cSRui Paulo
get_nl80211_protocol_features(struct wpa_driver_nl80211_data * drv)395b9c547cSRui Paulo static u32 get_nl80211_protocol_features(struct wpa_driver_nl80211_data *drv)
405b9c547cSRui Paulo {
415b9c547cSRui Paulo u32 feat = 0;
425b9c547cSRui Paulo struct nl_msg *msg;
435b9c547cSRui Paulo
445b9c547cSRui Paulo msg = nlmsg_alloc();
455b9c547cSRui Paulo if (!msg)
465b9c547cSRui Paulo return 0;
475b9c547cSRui Paulo
485b9c547cSRui Paulo if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_PROTOCOL_FEATURES)) {
495b9c547cSRui Paulo nlmsg_free(msg);
505b9c547cSRui Paulo return 0;
515b9c547cSRui Paulo }
525b9c547cSRui Paulo
53*a90b9d01SCy Schubert if (send_and_recv_resp(drv, msg, protocol_feature_handler, &feat) == 0)
545b9c547cSRui Paulo return feat;
555b9c547cSRui Paulo
565b9c547cSRui Paulo return 0;
575b9c547cSRui Paulo }
585b9c547cSRui Paulo
595b9c547cSRui Paulo
605b9c547cSRui Paulo struct wiphy_info_data {
615b9c547cSRui Paulo struct wpa_driver_nl80211_data *drv;
625b9c547cSRui Paulo struct wpa_driver_capa *capa;
635b9c547cSRui Paulo
645b9c547cSRui Paulo unsigned int num_multichan_concurrent;
655b9c547cSRui Paulo
665b9c547cSRui Paulo unsigned int error:1;
675b9c547cSRui Paulo unsigned int device_ap_sme:1;
685b9c547cSRui Paulo unsigned int poll_command_supported:1;
695b9c547cSRui Paulo unsigned int data_tx_status:1;
705b9c547cSRui Paulo unsigned int auth_supported:1;
715b9c547cSRui Paulo unsigned int connect_supported:1;
725b9c547cSRui Paulo unsigned int p2p_go_supported:1;
735b9c547cSRui Paulo unsigned int p2p_client_supported:1;
745b9c547cSRui Paulo unsigned int p2p_go_ctwindow_supported:1;
755b9c547cSRui Paulo unsigned int p2p_concurrent:1;
765b9c547cSRui Paulo unsigned int channel_switch_supported:1;
775b9c547cSRui Paulo unsigned int set_qos_map_supported:1;
785b9c547cSRui Paulo unsigned int have_low_prio_scan:1;
795b9c547cSRui Paulo unsigned int wmm_ac_supported:1;
805b9c547cSRui Paulo unsigned int mac_addr_rand_scan_supported:1;
815b9c547cSRui Paulo unsigned int mac_addr_rand_sched_scan_supported:1;
82c1d255d3SCy Schubert unsigned int update_ft_ies_supported:1;
83c1d255d3SCy Schubert unsigned int has_key_mgmt:1;
84c1d255d3SCy Schubert unsigned int has_key_mgmt_iftype:1;
855b9c547cSRui Paulo };
865b9c547cSRui Paulo
875b9c547cSRui Paulo
probe_resp_offload_support(int supp_protocols)885b9c547cSRui Paulo static unsigned int probe_resp_offload_support(int supp_protocols)
895b9c547cSRui Paulo {
905b9c547cSRui Paulo unsigned int prot = 0;
915b9c547cSRui Paulo
925b9c547cSRui Paulo if (supp_protocols & NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS)
935b9c547cSRui Paulo prot |= WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS;
945b9c547cSRui Paulo if (supp_protocols & NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2)
955b9c547cSRui Paulo prot |= WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2;
965b9c547cSRui Paulo if (supp_protocols & NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P)
975b9c547cSRui Paulo prot |= WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P;
985b9c547cSRui Paulo if (supp_protocols & NL80211_PROBE_RESP_OFFLOAD_SUPPORT_80211U)
995b9c547cSRui Paulo prot |= WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING;
1005b9c547cSRui Paulo
1015b9c547cSRui Paulo return prot;
1025b9c547cSRui Paulo }
1035b9c547cSRui Paulo
1045b9c547cSRui Paulo
wiphy_info_supported_iftypes(struct wiphy_info_data * info,struct nlattr * tb)1055b9c547cSRui Paulo static void wiphy_info_supported_iftypes(struct wiphy_info_data *info,
1065b9c547cSRui Paulo struct nlattr *tb)
1075b9c547cSRui Paulo {
1085b9c547cSRui Paulo struct nlattr *nl_mode;
1095b9c547cSRui Paulo int i;
1105b9c547cSRui Paulo
1115b9c547cSRui Paulo if (tb == NULL)
1125b9c547cSRui Paulo return;
1135b9c547cSRui Paulo
1145b9c547cSRui Paulo nla_for_each_nested(nl_mode, tb, i) {
1155b9c547cSRui Paulo switch (nla_type(nl_mode)) {
1165b9c547cSRui Paulo case NL80211_IFTYPE_AP:
1175b9c547cSRui Paulo info->capa->flags |= WPA_DRIVER_FLAGS_AP;
1185b9c547cSRui Paulo break;
1195b9c547cSRui Paulo case NL80211_IFTYPE_MESH_POINT:
1205b9c547cSRui Paulo info->capa->flags |= WPA_DRIVER_FLAGS_MESH;
1215b9c547cSRui Paulo break;
1225b9c547cSRui Paulo case NL80211_IFTYPE_ADHOC:
1235b9c547cSRui Paulo info->capa->flags |= WPA_DRIVER_FLAGS_IBSS;
1245b9c547cSRui Paulo break;
1255b9c547cSRui Paulo case NL80211_IFTYPE_P2P_DEVICE:
1265b9c547cSRui Paulo info->capa->flags |=
1275b9c547cSRui Paulo WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE;
1285b9c547cSRui Paulo break;
1295b9c547cSRui Paulo case NL80211_IFTYPE_P2P_GO:
1305b9c547cSRui Paulo info->p2p_go_supported = 1;
1315b9c547cSRui Paulo break;
1325b9c547cSRui Paulo case NL80211_IFTYPE_P2P_CLIENT:
1335b9c547cSRui Paulo info->p2p_client_supported = 1;
1345b9c547cSRui Paulo break;
1355b9c547cSRui Paulo }
1365b9c547cSRui Paulo }
1375b9c547cSRui Paulo }
1385b9c547cSRui Paulo
1395b9c547cSRui Paulo
wiphy_info_iface_comb_process(struct wiphy_info_data * info,struct nlattr * nl_combi)1405b9c547cSRui Paulo static int wiphy_info_iface_comb_process(struct wiphy_info_data *info,
1415b9c547cSRui Paulo struct nlattr *nl_combi)
1425b9c547cSRui Paulo {
1435b9c547cSRui Paulo struct nlattr *tb_comb[NUM_NL80211_IFACE_COMB];
1445b9c547cSRui Paulo struct nlattr *tb_limit[NUM_NL80211_IFACE_LIMIT];
1455b9c547cSRui Paulo struct nlattr *nl_limit, *nl_mode;
1465b9c547cSRui Paulo int err, rem_limit, rem_mode;
1475b9c547cSRui Paulo int combination_has_p2p = 0, combination_has_mgd = 0;
1485b9c547cSRui Paulo static struct nla_policy
1495b9c547cSRui Paulo iface_combination_policy[NUM_NL80211_IFACE_COMB] = {
1505b9c547cSRui Paulo [NL80211_IFACE_COMB_LIMITS] = { .type = NLA_NESTED },
1515b9c547cSRui Paulo [NL80211_IFACE_COMB_MAXNUM] = { .type = NLA_U32 },
1525b9c547cSRui Paulo [NL80211_IFACE_COMB_STA_AP_BI_MATCH] = { .type = NLA_FLAG },
1535b9c547cSRui Paulo [NL80211_IFACE_COMB_NUM_CHANNELS] = { .type = NLA_U32 },
1545b9c547cSRui Paulo [NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS] = { .type = NLA_U32 },
1555b9c547cSRui Paulo },
1565b9c547cSRui Paulo iface_limit_policy[NUM_NL80211_IFACE_LIMIT] = {
1575b9c547cSRui Paulo [NL80211_IFACE_LIMIT_TYPES] = { .type = NLA_NESTED },
1585b9c547cSRui Paulo [NL80211_IFACE_LIMIT_MAX] = { .type = NLA_U32 },
1595b9c547cSRui Paulo };
1605b9c547cSRui Paulo
1615b9c547cSRui Paulo err = nla_parse_nested(tb_comb, MAX_NL80211_IFACE_COMB,
1625b9c547cSRui Paulo nl_combi, iface_combination_policy);
1635b9c547cSRui Paulo if (err || !tb_comb[NL80211_IFACE_COMB_LIMITS] ||
1645b9c547cSRui Paulo !tb_comb[NL80211_IFACE_COMB_MAXNUM] ||
1655b9c547cSRui Paulo !tb_comb[NL80211_IFACE_COMB_NUM_CHANNELS])
1665b9c547cSRui Paulo return 0; /* broken combination */
1675b9c547cSRui Paulo
1685b9c547cSRui Paulo if (tb_comb[NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS])
1695b9c547cSRui Paulo info->capa->flags |= WPA_DRIVER_FLAGS_RADAR;
1705b9c547cSRui Paulo
1715b9c547cSRui Paulo nla_for_each_nested(nl_limit, tb_comb[NL80211_IFACE_COMB_LIMITS],
1725b9c547cSRui Paulo rem_limit) {
1735b9c547cSRui Paulo err = nla_parse_nested(tb_limit, MAX_NL80211_IFACE_LIMIT,
1745b9c547cSRui Paulo nl_limit, iface_limit_policy);
1755b9c547cSRui Paulo if (err || !tb_limit[NL80211_IFACE_LIMIT_TYPES])
1765b9c547cSRui Paulo return 0; /* broken combination */
1775b9c547cSRui Paulo
1785b9c547cSRui Paulo nla_for_each_nested(nl_mode,
1795b9c547cSRui Paulo tb_limit[NL80211_IFACE_LIMIT_TYPES],
1805b9c547cSRui Paulo rem_mode) {
1815b9c547cSRui Paulo int ift = nla_type(nl_mode);
1825b9c547cSRui Paulo if (ift == NL80211_IFTYPE_P2P_GO ||
1835b9c547cSRui Paulo ift == NL80211_IFTYPE_P2P_CLIENT)
1845b9c547cSRui Paulo combination_has_p2p = 1;
1855b9c547cSRui Paulo if (ift == NL80211_IFTYPE_STATION)
1865b9c547cSRui Paulo combination_has_mgd = 1;
1875b9c547cSRui Paulo }
1885b9c547cSRui Paulo if (combination_has_p2p && combination_has_mgd)
1895b9c547cSRui Paulo break;
1905b9c547cSRui Paulo }
1915b9c547cSRui Paulo
1925b9c547cSRui Paulo if (combination_has_p2p && combination_has_mgd) {
1935b9c547cSRui Paulo unsigned int num_channels =
1945b9c547cSRui Paulo nla_get_u32(tb_comb[NL80211_IFACE_COMB_NUM_CHANNELS]);
1955b9c547cSRui Paulo
1965b9c547cSRui Paulo info->p2p_concurrent = 1;
1975b9c547cSRui Paulo if (info->num_multichan_concurrent < num_channels)
1985b9c547cSRui Paulo info->num_multichan_concurrent = num_channels;
1995b9c547cSRui Paulo }
2005b9c547cSRui Paulo
2015b9c547cSRui Paulo return 0;
2025b9c547cSRui Paulo }
2035b9c547cSRui Paulo
2045b9c547cSRui Paulo
wiphy_info_iface_comb(struct wiphy_info_data * info,struct nlattr * tb)2055b9c547cSRui Paulo static void wiphy_info_iface_comb(struct wiphy_info_data *info,
2065b9c547cSRui Paulo struct nlattr *tb)
2075b9c547cSRui Paulo {
2085b9c547cSRui Paulo struct nlattr *nl_combi;
2095b9c547cSRui Paulo int rem_combi;
2105b9c547cSRui Paulo
2115b9c547cSRui Paulo if (tb == NULL)
2125b9c547cSRui Paulo return;
2135b9c547cSRui Paulo
2145b9c547cSRui Paulo nla_for_each_nested(nl_combi, tb, rem_combi) {
2155b9c547cSRui Paulo if (wiphy_info_iface_comb_process(info, nl_combi) > 0)
2165b9c547cSRui Paulo break;
2175b9c547cSRui Paulo }
2185b9c547cSRui Paulo }
2195b9c547cSRui Paulo
2205b9c547cSRui Paulo
wiphy_info_supp_cmds(struct wiphy_info_data * info,struct nlattr * tb)2215b9c547cSRui Paulo static void wiphy_info_supp_cmds(struct wiphy_info_data *info,
2225b9c547cSRui Paulo struct nlattr *tb)
2235b9c547cSRui Paulo {
2245b9c547cSRui Paulo struct nlattr *nl_cmd;
2255b9c547cSRui Paulo int i;
2265b9c547cSRui Paulo
2275b9c547cSRui Paulo if (tb == NULL)
2285b9c547cSRui Paulo return;
2295b9c547cSRui Paulo
2305b9c547cSRui Paulo nla_for_each_nested(nl_cmd, tb, i) {
2315b9c547cSRui Paulo switch (nla_get_u32(nl_cmd)) {
2325b9c547cSRui Paulo case NL80211_CMD_AUTHENTICATE:
2335b9c547cSRui Paulo info->auth_supported = 1;
2345b9c547cSRui Paulo break;
2355b9c547cSRui Paulo case NL80211_CMD_CONNECT:
2365b9c547cSRui Paulo info->connect_supported = 1;
2375b9c547cSRui Paulo break;
2385b9c547cSRui Paulo case NL80211_CMD_START_SCHED_SCAN:
2395b9c547cSRui Paulo info->capa->sched_scan_supported = 1;
2405b9c547cSRui Paulo break;
2415b9c547cSRui Paulo case NL80211_CMD_PROBE_CLIENT:
2425b9c547cSRui Paulo info->poll_command_supported = 1;
2435b9c547cSRui Paulo break;
2445b9c547cSRui Paulo case NL80211_CMD_CHANNEL_SWITCH:
2455b9c547cSRui Paulo info->channel_switch_supported = 1;
2465b9c547cSRui Paulo break;
2475b9c547cSRui Paulo case NL80211_CMD_SET_QOS_MAP:
2485b9c547cSRui Paulo info->set_qos_map_supported = 1;
2495b9c547cSRui Paulo break;
250c1d255d3SCy Schubert case NL80211_CMD_UPDATE_FT_IES:
251c1d255d3SCy Schubert info->update_ft_ies_supported = 1;
252c1d255d3SCy Schubert break;
2535b9c547cSRui Paulo }
2545b9c547cSRui Paulo }
2555b9c547cSRui Paulo }
2565b9c547cSRui Paulo
2575b9c547cSRui Paulo
get_akm_suites_info(struct nlattr * tb)258c1d255d3SCy Schubert static unsigned int get_akm_suites_info(struct nlattr *tb)
259c1d255d3SCy Schubert {
260c1d255d3SCy Schubert int i, num;
261c1d255d3SCy Schubert unsigned int key_mgmt = 0;
262c1d255d3SCy Schubert u32 *akms;
263c1d255d3SCy Schubert
264c1d255d3SCy Schubert if (!tb)
265c1d255d3SCy Schubert return 0;
266c1d255d3SCy Schubert
267c1d255d3SCy Schubert num = nla_len(tb) / sizeof(u32);
268c1d255d3SCy Schubert akms = nla_data(tb);
269c1d255d3SCy Schubert for (i = 0; i < num; i++) {
270c1d255d3SCy Schubert switch (akms[i]) {
271c1d255d3SCy Schubert case RSN_AUTH_KEY_MGMT_UNSPEC_802_1X:
272c1d255d3SCy Schubert key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_WPA |
273c1d255d3SCy Schubert WPA_DRIVER_CAPA_KEY_MGMT_WPA2;
274c1d255d3SCy Schubert break;
275c1d255d3SCy Schubert case RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X:
276c1d255d3SCy Schubert key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
277c1d255d3SCy Schubert WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK;
278c1d255d3SCy Schubert break;
279c1d255d3SCy Schubert case RSN_AUTH_KEY_MGMT_FT_802_1X:
280c1d255d3SCy Schubert key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT;
281c1d255d3SCy Schubert break;
282c1d255d3SCy Schubert case RSN_AUTH_KEY_MGMT_FT_PSK:
283c1d255d3SCy Schubert key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK;
284c1d255d3SCy Schubert break;
285c1d255d3SCy Schubert case RSN_AUTH_KEY_MGMT_802_1X_SHA256:
286c1d255d3SCy Schubert key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_802_1X_SHA256;
287c1d255d3SCy Schubert break;
288c1d255d3SCy Schubert case RSN_AUTH_KEY_MGMT_PSK_SHA256:
289c1d255d3SCy Schubert key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_PSK_SHA256;
290c1d255d3SCy Schubert break;
291c1d255d3SCy Schubert case RSN_AUTH_KEY_MGMT_TPK_HANDSHAKE:
292c1d255d3SCy Schubert key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_TPK_HANDSHAKE;
293c1d255d3SCy Schubert break;
294c1d255d3SCy Schubert case RSN_AUTH_KEY_MGMT_FT_SAE:
295c1d255d3SCy Schubert key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT_SAE;
296c1d255d3SCy Schubert break;
297*a90b9d01SCy Schubert case RSN_AUTH_KEY_MGMT_FT_SAE_EXT_KEY:
298*a90b9d01SCy Schubert key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT_SAE_EXT_KEY;
299*a90b9d01SCy Schubert break;
300c1d255d3SCy Schubert case RSN_AUTH_KEY_MGMT_FT_802_1X_SHA384:
301c1d255d3SCy Schubert key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT_802_1X_SHA384;
302c1d255d3SCy Schubert break;
303c1d255d3SCy Schubert case RSN_AUTH_KEY_MGMT_CCKM:
304c1d255d3SCy Schubert key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_CCKM;
305c1d255d3SCy Schubert break;
306c1d255d3SCy Schubert case RSN_AUTH_KEY_MGMT_OSEN:
307c1d255d3SCy Schubert key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_OSEN;
308c1d255d3SCy Schubert break;
309c1d255d3SCy Schubert case RSN_AUTH_KEY_MGMT_802_1X_SUITE_B:
310c1d255d3SCy Schubert key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B;
311c1d255d3SCy Schubert break;
312c1d255d3SCy Schubert case RSN_AUTH_KEY_MGMT_802_1X_SUITE_B_192:
313c1d255d3SCy Schubert key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192;
314c1d255d3SCy Schubert break;
315c1d255d3SCy Schubert case RSN_AUTH_KEY_MGMT_OWE:
316c1d255d3SCy Schubert key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_OWE;
317c1d255d3SCy Schubert break;
318c1d255d3SCy Schubert case RSN_AUTH_KEY_MGMT_DPP:
319c1d255d3SCy Schubert key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_DPP;
320c1d255d3SCy Schubert break;
321c1d255d3SCy Schubert case RSN_AUTH_KEY_MGMT_FILS_SHA256:
322c1d255d3SCy Schubert key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256;
323c1d255d3SCy Schubert break;
324c1d255d3SCy Schubert case RSN_AUTH_KEY_MGMT_FILS_SHA384:
325c1d255d3SCy Schubert key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384;
326c1d255d3SCy Schubert break;
327c1d255d3SCy Schubert case RSN_AUTH_KEY_MGMT_FT_FILS_SHA256:
328c1d255d3SCy Schubert key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA256;
329c1d255d3SCy Schubert break;
330c1d255d3SCy Schubert case RSN_AUTH_KEY_MGMT_FT_FILS_SHA384:
331c1d255d3SCy Schubert key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA384;
332c1d255d3SCy Schubert break;
333c1d255d3SCy Schubert case RSN_AUTH_KEY_MGMT_SAE:
334c1d255d3SCy Schubert key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_SAE;
335c1d255d3SCy Schubert break;
336*a90b9d01SCy Schubert case RSN_AUTH_KEY_MGMT_SAE_EXT_KEY:
337*a90b9d01SCy Schubert key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_SAE_EXT_KEY;
338*a90b9d01SCy Schubert break;
339c1d255d3SCy Schubert }
340c1d255d3SCy Schubert }
341c1d255d3SCy Schubert
342c1d255d3SCy Schubert return key_mgmt;
343c1d255d3SCy Schubert }
344c1d255d3SCy Schubert
345c1d255d3SCy Schubert
get_iface_akm_suites_info(struct wiphy_info_data * info,struct nlattr * nl_akms)346c1d255d3SCy Schubert static void get_iface_akm_suites_info(struct wiphy_info_data *info,
347c1d255d3SCy Schubert struct nlattr *nl_akms)
348c1d255d3SCy Schubert {
349c1d255d3SCy Schubert struct nlattr *tb[NL80211_IFTYPE_AKM_ATTR_MAX + 1];
350c1d255d3SCy Schubert struct nlattr *nl_iftype;
351c1d255d3SCy Schubert unsigned int key_mgmt;
352c1d255d3SCy Schubert int i;
353c1d255d3SCy Schubert
354c1d255d3SCy Schubert if (!nl_akms)
355c1d255d3SCy Schubert return;
356c1d255d3SCy Schubert
357c1d255d3SCy Schubert nla_parse(tb, NL80211_IFTYPE_AKM_ATTR_MAX,
358c1d255d3SCy Schubert nla_data(nl_akms), nla_len(nl_akms), NULL);
359c1d255d3SCy Schubert
360c1d255d3SCy Schubert if (!tb[NL80211_IFTYPE_AKM_ATTR_IFTYPES] ||
361c1d255d3SCy Schubert !tb[NL80211_IFTYPE_AKM_ATTR_SUITES])
362c1d255d3SCy Schubert return;
363c1d255d3SCy Schubert
364c1d255d3SCy Schubert info->has_key_mgmt_iftype = 1;
365c1d255d3SCy Schubert key_mgmt = get_akm_suites_info(tb[NL80211_IFTYPE_AKM_ATTR_SUITES]);
366c1d255d3SCy Schubert
367c1d255d3SCy Schubert nla_for_each_nested(nl_iftype, tb[NL80211_IFTYPE_AKM_ATTR_IFTYPES], i) {
368c1d255d3SCy Schubert switch (nla_type(nl_iftype)) {
369c1d255d3SCy Schubert case NL80211_IFTYPE_ADHOC:
370c1d255d3SCy Schubert info->drv->capa.key_mgmt_iftype[WPA_IF_IBSS] = key_mgmt;
371c1d255d3SCy Schubert break;
372c1d255d3SCy Schubert case NL80211_IFTYPE_STATION:
373c1d255d3SCy Schubert info->drv->capa.key_mgmt_iftype[WPA_IF_STATION] =
374c1d255d3SCy Schubert key_mgmt;
375c1d255d3SCy Schubert break;
376c1d255d3SCy Schubert case NL80211_IFTYPE_AP:
377c1d255d3SCy Schubert info->drv->capa.key_mgmt_iftype[WPA_IF_AP_BSS] =
378c1d255d3SCy Schubert key_mgmt;
379c1d255d3SCy Schubert break;
380c1d255d3SCy Schubert case NL80211_IFTYPE_AP_VLAN:
381c1d255d3SCy Schubert info->drv->capa.key_mgmt_iftype[WPA_IF_AP_VLAN] =
382c1d255d3SCy Schubert key_mgmt;
383c1d255d3SCy Schubert break;
384c1d255d3SCy Schubert case NL80211_IFTYPE_MESH_POINT:
385c1d255d3SCy Schubert info->drv->capa.key_mgmt_iftype[WPA_IF_MESH] = key_mgmt;
386c1d255d3SCy Schubert break;
387c1d255d3SCy Schubert case NL80211_IFTYPE_P2P_CLIENT:
388c1d255d3SCy Schubert info->drv->capa.key_mgmt_iftype[WPA_IF_P2P_CLIENT] =
389c1d255d3SCy Schubert key_mgmt;
390c1d255d3SCy Schubert break;
391c1d255d3SCy Schubert case NL80211_IFTYPE_P2P_GO:
392c1d255d3SCy Schubert info->drv->capa.key_mgmt_iftype[WPA_IF_P2P_GO] =
393c1d255d3SCy Schubert key_mgmt;
394c1d255d3SCy Schubert break;
395c1d255d3SCy Schubert case NL80211_IFTYPE_P2P_DEVICE:
396c1d255d3SCy Schubert info->drv->capa.key_mgmt_iftype[WPA_IF_P2P_DEVICE] =
397c1d255d3SCy Schubert key_mgmt;
398c1d255d3SCy Schubert break;
399c1d255d3SCy Schubert case NL80211_IFTYPE_NAN:
400c1d255d3SCy Schubert info->drv->capa.key_mgmt_iftype[WPA_IF_NAN] = key_mgmt;
401c1d255d3SCy Schubert break;
402c1d255d3SCy Schubert }
403c1d255d3SCy Schubert wpa_printf(MSG_DEBUG, "nl80211: %s supported key_mgmt 0x%x",
404c1d255d3SCy Schubert nl80211_iftype_str(nla_type(nl_iftype)),
405c1d255d3SCy Schubert key_mgmt);
406c1d255d3SCy Schubert }
407c1d255d3SCy Schubert }
408c1d255d3SCy Schubert
409c1d255d3SCy Schubert
wiphy_info_iftype_akm_suites(struct wiphy_info_data * info,struct nlattr * tb)410c1d255d3SCy Schubert static void wiphy_info_iftype_akm_suites(struct wiphy_info_data *info,
411c1d255d3SCy Schubert struct nlattr *tb)
412c1d255d3SCy Schubert {
413c1d255d3SCy Schubert struct nlattr *nl_if;
414c1d255d3SCy Schubert int rem_if;
415c1d255d3SCy Schubert
416c1d255d3SCy Schubert if (!tb)
417c1d255d3SCy Schubert return;
418c1d255d3SCy Schubert
419c1d255d3SCy Schubert nla_for_each_nested(nl_if, tb, rem_if)
420c1d255d3SCy Schubert get_iface_akm_suites_info(info, nl_if);
421c1d255d3SCy Schubert }
422c1d255d3SCy Schubert
423c1d255d3SCy Schubert
wiphy_info_akm_suites(struct wiphy_info_data * info,struct nlattr * tb)424c1d255d3SCy Schubert static void wiphy_info_akm_suites(struct wiphy_info_data *info,
425c1d255d3SCy Schubert struct nlattr *tb)
426c1d255d3SCy Schubert {
427c1d255d3SCy Schubert if (!tb)
428c1d255d3SCy Schubert return;
429c1d255d3SCy Schubert
430c1d255d3SCy Schubert info->has_key_mgmt = 1;
431c1d255d3SCy Schubert info->capa->key_mgmt = get_akm_suites_info(tb);
432c1d255d3SCy Schubert wpa_printf(MSG_DEBUG, "nl80211: wiphy supported key_mgmt 0x%x",
433c1d255d3SCy Schubert info->capa->key_mgmt);
434c1d255d3SCy Schubert }
435c1d255d3SCy Schubert
436c1d255d3SCy Schubert
wiphy_info_cipher_suites(struct wiphy_info_data * info,struct nlattr * tb)4375b9c547cSRui Paulo static void wiphy_info_cipher_suites(struct wiphy_info_data *info,
4385b9c547cSRui Paulo struct nlattr *tb)
4395b9c547cSRui Paulo {
4405b9c547cSRui Paulo int i, num;
4415b9c547cSRui Paulo u32 *ciphers;
4425b9c547cSRui Paulo
4435b9c547cSRui Paulo if (tb == NULL)
4445b9c547cSRui Paulo return;
4455b9c547cSRui Paulo
4465b9c547cSRui Paulo num = nla_len(tb) / sizeof(u32);
4475b9c547cSRui Paulo ciphers = nla_data(tb);
4485b9c547cSRui Paulo for (i = 0; i < num; i++) {
4495b9c547cSRui Paulo u32 c = ciphers[i];
4505b9c547cSRui Paulo
4515b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "nl80211: Supported cipher %02x-%02x-%02x:%d",
4525b9c547cSRui Paulo c >> 24, (c >> 16) & 0xff,
4535b9c547cSRui Paulo (c >> 8) & 0xff, c & 0xff);
4545b9c547cSRui Paulo switch (c) {
45585732ac8SCy Schubert case RSN_CIPHER_SUITE_CCMP_256:
4565b9c547cSRui Paulo info->capa->enc |= WPA_DRIVER_CAPA_ENC_CCMP_256;
4575b9c547cSRui Paulo break;
45885732ac8SCy Schubert case RSN_CIPHER_SUITE_GCMP_256:
4595b9c547cSRui Paulo info->capa->enc |= WPA_DRIVER_CAPA_ENC_GCMP_256;
4605b9c547cSRui Paulo break;
46185732ac8SCy Schubert case RSN_CIPHER_SUITE_CCMP:
4625b9c547cSRui Paulo info->capa->enc |= WPA_DRIVER_CAPA_ENC_CCMP;
4635b9c547cSRui Paulo break;
46485732ac8SCy Schubert case RSN_CIPHER_SUITE_GCMP:
4655b9c547cSRui Paulo info->capa->enc |= WPA_DRIVER_CAPA_ENC_GCMP;
4665b9c547cSRui Paulo break;
46785732ac8SCy Schubert case RSN_CIPHER_SUITE_TKIP:
4685b9c547cSRui Paulo info->capa->enc |= WPA_DRIVER_CAPA_ENC_TKIP;
4695b9c547cSRui Paulo break;
47085732ac8SCy Schubert case RSN_CIPHER_SUITE_WEP104:
4715b9c547cSRui Paulo info->capa->enc |= WPA_DRIVER_CAPA_ENC_WEP104;
4725b9c547cSRui Paulo break;
47385732ac8SCy Schubert case RSN_CIPHER_SUITE_WEP40:
4745b9c547cSRui Paulo info->capa->enc |= WPA_DRIVER_CAPA_ENC_WEP40;
4755b9c547cSRui Paulo break;
47685732ac8SCy Schubert case RSN_CIPHER_SUITE_AES_128_CMAC:
4775b9c547cSRui Paulo info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP;
4785b9c547cSRui Paulo break;
47985732ac8SCy Schubert case RSN_CIPHER_SUITE_BIP_GMAC_128:
4805b9c547cSRui Paulo info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP_GMAC_128;
4815b9c547cSRui Paulo break;
48285732ac8SCy Schubert case RSN_CIPHER_SUITE_BIP_GMAC_256:
4835b9c547cSRui Paulo info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP_GMAC_256;
4845b9c547cSRui Paulo break;
48585732ac8SCy Schubert case RSN_CIPHER_SUITE_BIP_CMAC_256:
4865b9c547cSRui Paulo info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP_CMAC_256;
4875b9c547cSRui Paulo break;
48885732ac8SCy Schubert case RSN_CIPHER_SUITE_NO_GROUP_ADDRESSED:
4895b9c547cSRui Paulo info->capa->enc |= WPA_DRIVER_CAPA_ENC_GTK_NOT_USED;
4905b9c547cSRui Paulo break;
4915b9c547cSRui Paulo }
4925b9c547cSRui Paulo }
4935b9c547cSRui Paulo }
4945b9c547cSRui Paulo
4955b9c547cSRui Paulo
wiphy_info_max_roc(struct wpa_driver_capa * capa,struct nlattr * tb)4965b9c547cSRui Paulo static void wiphy_info_max_roc(struct wpa_driver_capa *capa,
4975b9c547cSRui Paulo struct nlattr *tb)
4985b9c547cSRui Paulo {
4995b9c547cSRui Paulo if (tb)
5005b9c547cSRui Paulo capa->max_remain_on_chan = nla_get_u32(tb);
5015b9c547cSRui Paulo }
5025b9c547cSRui Paulo
5035b9c547cSRui Paulo
wiphy_info_tdls(struct wpa_driver_capa * capa,struct nlattr * tdls,struct nlattr * ext_setup)5045b9c547cSRui Paulo static void wiphy_info_tdls(struct wpa_driver_capa *capa, struct nlattr *tdls,
5055b9c547cSRui Paulo struct nlattr *ext_setup)
5065b9c547cSRui Paulo {
5075b9c547cSRui Paulo if (tdls == NULL)
5085b9c547cSRui Paulo return;
5095b9c547cSRui Paulo
5105b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "nl80211: TDLS supported");
5115b9c547cSRui Paulo capa->flags |= WPA_DRIVER_FLAGS_TDLS_SUPPORT;
5125b9c547cSRui Paulo
5135b9c547cSRui Paulo if (ext_setup) {
5145b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "nl80211: TDLS external setup");
5155b9c547cSRui Paulo capa->flags |= WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP;
5165b9c547cSRui Paulo }
5175b9c547cSRui Paulo }
5185b9c547cSRui Paulo
5195b9c547cSRui Paulo
ext_feature_isset(const u8 * ext_features,int ext_features_len,enum nl80211_ext_feature_index ftidx)520325151a3SRui Paulo static int ext_feature_isset(const u8 *ext_features, int ext_features_len,
521325151a3SRui Paulo enum nl80211_ext_feature_index ftidx)
522325151a3SRui Paulo {
523325151a3SRui Paulo u8 ft_byte;
524325151a3SRui Paulo
525325151a3SRui Paulo if ((int) ftidx / 8 >= ext_features_len)
526325151a3SRui Paulo return 0;
527325151a3SRui Paulo
528325151a3SRui Paulo ft_byte = ext_features[ftidx / 8];
529325151a3SRui Paulo return (ft_byte & BIT(ftidx % 8)) != 0;
530325151a3SRui Paulo }
531325151a3SRui Paulo
532325151a3SRui Paulo
wiphy_info_ext_feature_flags(struct wiphy_info_data * info,struct nlattr * tb)533325151a3SRui Paulo static void wiphy_info_ext_feature_flags(struct wiphy_info_data *info,
534325151a3SRui Paulo struct nlattr *tb)
535325151a3SRui Paulo {
536325151a3SRui Paulo struct wpa_driver_capa *capa = info->capa;
537780fb4a2SCy Schubert u8 *ext_features;
538780fb4a2SCy Schubert int len;
539325151a3SRui Paulo
540325151a3SRui Paulo if (tb == NULL)
541325151a3SRui Paulo return;
542325151a3SRui Paulo
543780fb4a2SCy Schubert ext_features = nla_data(tb);
544780fb4a2SCy Schubert len = nla_len(tb);
545780fb4a2SCy Schubert
546780fb4a2SCy Schubert if (ext_feature_isset(ext_features, len, NL80211_EXT_FEATURE_VHT_IBSS))
547325151a3SRui Paulo capa->flags |= WPA_DRIVER_FLAGS_VHT_IBSS;
548780fb4a2SCy Schubert
549780fb4a2SCy Schubert if (ext_feature_isset(ext_features, len, NL80211_EXT_FEATURE_RRM))
550780fb4a2SCy Schubert capa->rrm_flags |= WPA_DRIVER_FLAGS_SUPPORT_RRM;
55185732ac8SCy Schubert
55285732ac8SCy Schubert if (ext_feature_isset(ext_features, len, NL80211_EXT_FEATURE_FILS_STA))
55385732ac8SCy Schubert capa->flags |= WPA_DRIVER_FLAGS_SUPPORT_FILS;
55485732ac8SCy Schubert
55585732ac8SCy Schubert if (ext_feature_isset(ext_features, len,
55685732ac8SCy Schubert NL80211_EXT_FEATURE_BEACON_RATE_LEGACY))
55785732ac8SCy Schubert capa->flags |= WPA_DRIVER_FLAGS_BEACON_RATE_LEGACY;
55885732ac8SCy Schubert
55985732ac8SCy Schubert if (ext_feature_isset(ext_features, len,
56085732ac8SCy Schubert NL80211_EXT_FEATURE_BEACON_RATE_HT))
56185732ac8SCy Schubert capa->flags |= WPA_DRIVER_FLAGS_BEACON_RATE_HT;
56285732ac8SCy Schubert
56385732ac8SCy Schubert if (ext_feature_isset(ext_features, len,
56485732ac8SCy Schubert NL80211_EXT_FEATURE_BEACON_RATE_VHT))
56585732ac8SCy Schubert capa->flags |= WPA_DRIVER_FLAGS_BEACON_RATE_VHT;
56685732ac8SCy Schubert
56785732ac8SCy Schubert if (ext_feature_isset(ext_features, len,
568c1d255d3SCy Schubert NL80211_EXT_FEATURE_BEACON_RATE_HE))
569c1d255d3SCy Schubert capa->flags2 |= WPA_DRIVER_FLAGS2_BEACON_RATE_HE;
570c1d255d3SCy Schubert
571c1d255d3SCy Schubert if (ext_feature_isset(ext_features, len,
57285732ac8SCy Schubert NL80211_EXT_FEATURE_SET_SCAN_DWELL))
57385732ac8SCy Schubert capa->rrm_flags |= WPA_DRIVER_FLAGS_SUPPORT_SET_SCAN_DWELL;
57485732ac8SCy Schubert
57585732ac8SCy Schubert if (ext_feature_isset(ext_features, len,
57685732ac8SCy Schubert NL80211_EXT_FEATURE_SCAN_START_TIME) &&
57785732ac8SCy Schubert ext_feature_isset(ext_features, len,
57885732ac8SCy Schubert NL80211_EXT_FEATURE_BSS_PARENT_TSF) &&
57985732ac8SCy Schubert ext_feature_isset(ext_features, len,
58085732ac8SCy Schubert NL80211_EXT_FEATURE_SET_SCAN_DWELL))
58185732ac8SCy Schubert capa->rrm_flags |= WPA_DRIVER_FLAGS_SUPPORT_BEACON_REPORT;
58285732ac8SCy Schubert if (ext_feature_isset(ext_features, len,
58385732ac8SCy Schubert NL80211_EXT_FEATURE_MGMT_TX_RANDOM_TA))
58485732ac8SCy Schubert capa->flags |= WPA_DRIVER_FLAGS_MGMT_TX_RANDOM_TA;
58585732ac8SCy Schubert if (ext_feature_isset(ext_features, len,
58685732ac8SCy Schubert NL80211_EXT_FEATURE_MGMT_TX_RANDOM_TA_CONNECTED))
58785732ac8SCy Schubert capa->flags |= WPA_DRIVER_FLAGS_MGMT_TX_RANDOM_TA_CONNECTED;
58885732ac8SCy Schubert if (ext_feature_isset(ext_features, len,
58985732ac8SCy Schubert NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI))
59085732ac8SCy Schubert capa->flags |= WPA_DRIVER_FLAGS_SCHED_SCAN_RELATIVE_RSSI;
59185732ac8SCy Schubert if (ext_feature_isset(ext_features, len,
59285732ac8SCy Schubert NL80211_EXT_FEATURE_FILS_SK_OFFLOAD))
59385732ac8SCy Schubert capa->flags |= WPA_DRIVER_FLAGS_FILS_SK_OFFLOAD;
59485732ac8SCy Schubert
59585732ac8SCy Schubert if (ext_feature_isset(ext_features, len,
5964bc52338SCy Schubert NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK))
5974bc52338SCy Schubert capa->flags |= WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK;
5984bc52338SCy Schubert if (ext_feature_isset(ext_features, len,
59985732ac8SCy Schubert NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
6004bc52338SCy Schubert capa->flags |= WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X;
60185732ac8SCy Schubert
60285732ac8SCy Schubert if (ext_feature_isset(ext_features, len,
603*a90b9d01SCy Schubert NL80211_EXT_FEATURE_SAE_OFFLOAD))
604*a90b9d01SCy Schubert capa->flags2 |= WPA_DRIVER_FLAGS2_SAE_OFFLOAD_STA;
605*a90b9d01SCy Schubert
606*a90b9d01SCy Schubert if (ext_feature_isset(ext_features, len,
60785732ac8SCy Schubert NL80211_EXT_FEATURE_MFP_OPTIONAL))
60885732ac8SCy Schubert capa->flags |= WPA_DRIVER_FLAGS_MFP_OPTIONAL;
60985732ac8SCy Schubert
61085732ac8SCy Schubert if (ext_feature_isset(ext_features, len,
61185732ac8SCy Schubert NL80211_EXT_FEATURE_DFS_OFFLOAD))
61285732ac8SCy Schubert capa->flags |= WPA_DRIVER_FLAGS_DFS_OFFLOAD;
61385732ac8SCy Schubert
61485732ac8SCy Schubert #ifdef CONFIG_MBO
61585732ac8SCy Schubert if (ext_feature_isset(ext_features, len,
61685732ac8SCy Schubert NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME) &&
61785732ac8SCy Schubert ext_feature_isset(ext_features, len,
61885732ac8SCy Schubert NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP) &&
61985732ac8SCy Schubert ext_feature_isset(ext_features, len,
62085732ac8SCy Schubert NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE) &&
62185732ac8SCy Schubert ext_feature_isset(
62285732ac8SCy Schubert ext_features, len,
62385732ac8SCy Schubert NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION))
62485732ac8SCy Schubert capa->flags |= WPA_DRIVER_FLAGS_OCE_STA;
62585732ac8SCy Schubert #endif /* CONFIG_MBO */
6264bc52338SCy Schubert
6274bc52338SCy Schubert if (ext_feature_isset(ext_features, len,
6284bc52338SCy Schubert NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER))
6294bc52338SCy Schubert capa->flags |= WPA_DRIVER_FLAGS_FTM_RESPONDER;
630c1d255d3SCy Schubert
631c1d255d3SCy Schubert if (ext_feature_isset(ext_features, len,
632c1d255d3SCy Schubert NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211))
633c1d255d3SCy Schubert capa->flags |= WPA_DRIVER_FLAGS_CONTROL_PORT;
634c1d255d3SCy Schubert if (ext_feature_isset(ext_features, len,
635c1d255d3SCy Schubert NL80211_EXT_FEATURE_CONTROL_PORT_NO_PREAUTH))
636c1d255d3SCy Schubert capa->flags2 |= WPA_DRIVER_FLAGS2_CONTROL_PORT_RX;
637c1d255d3SCy Schubert if (ext_feature_isset(
638c1d255d3SCy Schubert ext_features, len,
639c1d255d3SCy Schubert NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211_TX_STATUS))
640c1d255d3SCy Schubert capa->flags2 |= WPA_DRIVER_FLAGS2_CONTROL_PORT_TX_STATUS;
641c1d255d3SCy Schubert
642c1d255d3SCy Schubert if (ext_feature_isset(ext_features, len,
643c1d255d3SCy Schubert NL80211_EXT_FEATURE_VLAN_OFFLOAD))
644c1d255d3SCy Schubert capa->flags |= WPA_DRIVER_FLAGS_VLAN_OFFLOAD;
645c1d255d3SCy Schubert
646c1d255d3SCy Schubert if (ext_feature_isset(ext_features, len,
647c1d255d3SCy Schubert NL80211_EXT_FEATURE_CAN_REPLACE_PTK0))
648c1d255d3SCy Schubert capa->flags |= WPA_DRIVER_FLAGS_SAFE_PTK0_REKEYS;
649c1d255d3SCy Schubert
650c1d255d3SCy Schubert if (ext_feature_isset(ext_features, len,
651c1d255d3SCy Schubert NL80211_EXT_FEATURE_BEACON_PROTECTION))
652c1d255d3SCy Schubert capa->flags |= WPA_DRIVER_FLAGS_BEACON_PROTECTION;
653c1d255d3SCy Schubert
654c1d255d3SCy Schubert if (ext_feature_isset(ext_features, len,
655c1d255d3SCy Schubert NL80211_EXT_FEATURE_EXT_KEY_ID))
656c1d255d3SCy Schubert capa->flags |= WPA_DRIVER_FLAGS_EXTENDED_KEY_ID;
657c1d255d3SCy Schubert
658c1d255d3SCy Schubert if (ext_feature_isset(ext_features, len,
659c1d255d3SCy Schubert NL80211_EXT_FEATURE_MULTICAST_REGISTRATIONS))
660c1d255d3SCy Schubert info->drv->multicast_registrations = 1;
661c1d255d3SCy Schubert
662c1d255d3SCy Schubert if (ext_feature_isset(ext_features, len,
663c1d255d3SCy Schubert NL80211_EXT_FEATURE_FILS_DISCOVERY))
664c1d255d3SCy Schubert info->drv->fils_discovery = 1;
665c1d255d3SCy Schubert
666c1d255d3SCy Schubert if (ext_feature_isset(ext_features, len,
667c1d255d3SCy Schubert NL80211_EXT_FEATURE_UNSOL_BCAST_PROBE_RESP))
668c1d255d3SCy Schubert info->drv->unsol_bcast_probe_resp = 1;
669c1d255d3SCy Schubert
670*a90b9d01SCy Schubert if (ext_feature_isset(ext_features, len, NL80211_EXT_FEATURE_PUNCT))
671*a90b9d01SCy Schubert info->drv->puncturing = 1;
672*a90b9d01SCy Schubert
673c1d255d3SCy Schubert if (ext_feature_isset(ext_features, len,
674c1d255d3SCy Schubert NL80211_EXT_FEATURE_BEACON_PROTECTION_CLIENT))
675c1d255d3SCy Schubert capa->flags2 |= WPA_DRIVER_FLAGS2_BEACON_PROTECTION_CLIENT;
676c1d255d3SCy Schubert
677c1d255d3SCy Schubert if (ext_feature_isset(ext_features, len,
678c1d255d3SCy Schubert NL80211_EXT_FEATURE_OPERATING_CHANNEL_VALIDATION))
679c1d255d3SCy Schubert capa->flags2 |= WPA_DRIVER_FLAGS2_OCV;
680*a90b9d01SCy Schubert
681*a90b9d01SCy Schubert if (ext_feature_isset(ext_features, len,
682*a90b9d01SCy Schubert NL80211_EXT_FEATURE_RADAR_BACKGROUND))
683*a90b9d01SCy Schubert capa->flags2 |= WPA_DRIVER_FLAGS2_RADAR_BACKGROUND;
684*a90b9d01SCy Schubert
685*a90b9d01SCy Schubert if (ext_feature_isset(ext_features, len,
686*a90b9d01SCy Schubert NL80211_EXT_FEATURE_SECURE_LTF)) {
687*a90b9d01SCy Schubert capa->flags2 |= WPA_DRIVER_FLAGS2_SEC_LTF_STA;
688*a90b9d01SCy Schubert capa->flags2 |= WPA_DRIVER_FLAGS2_SEC_LTF_AP;
689*a90b9d01SCy Schubert }
690*a90b9d01SCy Schubert
691*a90b9d01SCy Schubert if (ext_feature_isset(ext_features, len,
692*a90b9d01SCy Schubert NL80211_EXT_FEATURE_SECURE_RTT)) {
693*a90b9d01SCy Schubert capa->flags2 |= WPA_DRIVER_FLAGS2_SEC_RTT_STA;
694*a90b9d01SCy Schubert capa->flags2 |= WPA_DRIVER_FLAGS2_SEC_RTT_AP;
695*a90b9d01SCy Schubert }
696*a90b9d01SCy Schubert
697*a90b9d01SCy Schubert if (ext_feature_isset(
698*a90b9d01SCy Schubert ext_features, len,
699*a90b9d01SCy Schubert NL80211_EXT_FEATURE_PROT_RANGE_NEGO_AND_MEASURE)) {
700*a90b9d01SCy Schubert capa->flags2 |= WPA_DRIVER_FLAGS2_PROT_RANGE_NEG_STA;
701*a90b9d01SCy Schubert capa->flags2 |= WPA_DRIVER_FLAGS2_PROT_RANGE_NEG_AP;
702*a90b9d01SCy Schubert }
703*a90b9d01SCy Schubert
704*a90b9d01SCy Schubert if (ext_feature_isset(ext_features, len,
705*a90b9d01SCy Schubert NL80211_EXT_FEATURE_SCAN_MIN_PREQ_CONTENT))
706*a90b9d01SCy Schubert capa->flags2 |= WPA_DRIVER_FLAGS2_SCAN_MIN_PREQ;
707*a90b9d01SCy Schubert
708*a90b9d01SCy Schubert if (ext_feature_isset(ext_features, len,
709*a90b9d01SCy Schubert NL80211_EXT_FEATURE_4WAY_HANDSHAKE_AP_PSK))
710*a90b9d01SCy Schubert capa->flags2 |= WPA_DRIVER_FLAGS2_4WAY_HANDSHAKE_AP_PSK;
711*a90b9d01SCy Schubert
712*a90b9d01SCy Schubert if (ext_feature_isset(ext_features, len,
713*a90b9d01SCy Schubert NL80211_EXT_FEATURE_OWE_OFFLOAD))
714*a90b9d01SCy Schubert capa->flags2 |= WPA_DRIVER_FLAGS2_OWE_OFFLOAD_STA;
715*a90b9d01SCy Schubert
716*a90b9d01SCy Schubert if (ext_feature_isset(ext_features, len,
717*a90b9d01SCy Schubert NL80211_EXT_FEATURE_OWE_OFFLOAD_AP))
718*a90b9d01SCy Schubert capa->flags2 |= WPA_DRIVER_FLAGS2_OWE_OFFLOAD_AP;
719*a90b9d01SCy Schubert
720*a90b9d01SCy Schubert if (ext_feature_isset(ext_features, len,
721*a90b9d01SCy Schubert NL80211_EXT_FEATURE_SAE_OFFLOAD_AP))
722*a90b9d01SCy Schubert capa->flags2 |= WPA_DRIVER_FLAGS2_SAE_OFFLOAD_AP;
723325151a3SRui Paulo }
724325151a3SRui Paulo
725325151a3SRui Paulo
wiphy_info_feature_flags(struct wiphy_info_data * info,struct nlattr * tb)7265b9c547cSRui Paulo static void wiphy_info_feature_flags(struct wiphy_info_data *info,
7275b9c547cSRui Paulo struct nlattr *tb)
7285b9c547cSRui Paulo {
7295b9c547cSRui Paulo u32 flags;
7305b9c547cSRui Paulo struct wpa_driver_capa *capa = info->capa;
7315b9c547cSRui Paulo
7325b9c547cSRui Paulo if (tb == NULL)
7335b9c547cSRui Paulo return;
7345b9c547cSRui Paulo
7355b9c547cSRui Paulo flags = nla_get_u32(tb);
7365b9c547cSRui Paulo
7375b9c547cSRui Paulo if (flags & NL80211_FEATURE_SK_TX_STATUS)
7385b9c547cSRui Paulo info->data_tx_status = 1;
7395b9c547cSRui Paulo
7405b9c547cSRui Paulo if (flags & NL80211_FEATURE_INACTIVITY_TIMER)
7415b9c547cSRui Paulo capa->flags |= WPA_DRIVER_FLAGS_INACTIVITY_TIMER;
7425b9c547cSRui Paulo
7435b9c547cSRui Paulo if (flags & NL80211_FEATURE_SAE)
7445b9c547cSRui Paulo capa->flags |= WPA_DRIVER_FLAGS_SAE;
7455b9c547cSRui Paulo
7465b9c547cSRui Paulo if (flags & NL80211_FEATURE_NEED_OBSS_SCAN)
7475b9c547cSRui Paulo capa->flags |= WPA_DRIVER_FLAGS_OBSS_SCAN;
7485b9c547cSRui Paulo
7495b9c547cSRui Paulo if (flags & NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)
7505b9c547cSRui Paulo capa->flags |= WPA_DRIVER_FLAGS_HT_2040_COEX;
7515b9c547cSRui Paulo
7525b9c547cSRui Paulo if (flags & NL80211_FEATURE_TDLS_CHANNEL_SWITCH) {
7535b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "nl80211: TDLS channel switch");
7545b9c547cSRui Paulo capa->flags |= WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH;
7555b9c547cSRui Paulo }
7565b9c547cSRui Paulo
7575b9c547cSRui Paulo if (flags & NL80211_FEATURE_P2P_GO_CTWIN)
7585b9c547cSRui Paulo info->p2p_go_ctwindow_supported = 1;
7595b9c547cSRui Paulo
7605b9c547cSRui Paulo if (flags & NL80211_FEATURE_LOW_PRIORITY_SCAN)
7615b9c547cSRui Paulo info->have_low_prio_scan = 1;
7625b9c547cSRui Paulo
7635b9c547cSRui Paulo if (flags & NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)
7645b9c547cSRui Paulo info->mac_addr_rand_scan_supported = 1;
7655b9c547cSRui Paulo
7665b9c547cSRui Paulo if (flags & NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR)
7675b9c547cSRui Paulo info->mac_addr_rand_sched_scan_supported = 1;
7685b9c547cSRui Paulo
7695b9c547cSRui Paulo if (flags & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
7705b9c547cSRui Paulo info->wmm_ac_supported = 1;
7715b9c547cSRui Paulo
7725b9c547cSRui Paulo if (flags & NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES)
7735b9c547cSRui Paulo capa->rrm_flags |= WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES;
7745b9c547cSRui Paulo
7755b9c547cSRui Paulo if (flags & NL80211_FEATURE_WFA_TPC_IE_IN_PROBES)
7765b9c547cSRui Paulo capa->rrm_flags |= WPA_DRIVER_FLAGS_WFA_TPC_IE_IN_PROBES;
7775b9c547cSRui Paulo
7785b9c547cSRui Paulo if (flags & NL80211_FEATURE_QUIET)
7795b9c547cSRui Paulo capa->rrm_flags |= WPA_DRIVER_FLAGS_QUIET;
7805b9c547cSRui Paulo
7815b9c547cSRui Paulo if (flags & NL80211_FEATURE_TX_POWER_INSERTION)
7825b9c547cSRui Paulo capa->rrm_flags |= WPA_DRIVER_FLAGS_TX_POWER_INSERTION;
7835b9c547cSRui Paulo
7845b9c547cSRui Paulo if (flags & NL80211_FEATURE_HT_IBSS)
7855b9c547cSRui Paulo capa->flags |= WPA_DRIVER_FLAGS_HT_IBSS;
786780fb4a2SCy Schubert
787780fb4a2SCy Schubert if (flags & NL80211_FEATURE_FULL_AP_CLIENT_STATE)
788780fb4a2SCy Schubert capa->flags |= WPA_DRIVER_FLAGS_FULL_AP_CLIENT_STATE;
7895b9c547cSRui Paulo }
7905b9c547cSRui Paulo
7915b9c547cSRui Paulo
wiphy_info_probe_resp_offload(struct wpa_driver_capa * capa,struct nlattr * tb)7925b9c547cSRui Paulo static void wiphy_info_probe_resp_offload(struct wpa_driver_capa *capa,
7935b9c547cSRui Paulo struct nlattr *tb)
7945b9c547cSRui Paulo {
7955b9c547cSRui Paulo u32 protocols;
7965b9c547cSRui Paulo
7975b9c547cSRui Paulo if (tb == NULL)
7985b9c547cSRui Paulo return;
7995b9c547cSRui Paulo
8005b9c547cSRui Paulo protocols = nla_get_u32(tb);
8015b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "nl80211: Supports Probe Response offload in AP "
8025b9c547cSRui Paulo "mode");
8035b9c547cSRui Paulo capa->flags |= WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD;
8045b9c547cSRui Paulo capa->probe_resp_offloads = probe_resp_offload_support(protocols);
8055b9c547cSRui Paulo }
8065b9c547cSRui Paulo
8075b9c547cSRui Paulo
wiphy_info_wowlan_triggers(struct wpa_driver_capa * capa,struct nlattr * tb)8085b9c547cSRui Paulo static void wiphy_info_wowlan_triggers(struct wpa_driver_capa *capa,
8095b9c547cSRui Paulo struct nlattr *tb)
8105b9c547cSRui Paulo {
8115b9c547cSRui Paulo struct nlattr *triggers[MAX_NL80211_WOWLAN_TRIG + 1];
8125b9c547cSRui Paulo
8135b9c547cSRui Paulo if (tb == NULL)
8145b9c547cSRui Paulo return;
8155b9c547cSRui Paulo
8165b9c547cSRui Paulo if (nla_parse_nested(triggers, MAX_NL80211_WOWLAN_TRIG,
8175b9c547cSRui Paulo tb, NULL))
8185b9c547cSRui Paulo return;
8195b9c547cSRui Paulo
8205b9c547cSRui Paulo if (triggers[NL80211_WOWLAN_TRIG_ANY])
8215b9c547cSRui Paulo capa->wowlan_triggers.any = 1;
8225b9c547cSRui Paulo if (triggers[NL80211_WOWLAN_TRIG_DISCONNECT])
8235b9c547cSRui Paulo capa->wowlan_triggers.disconnect = 1;
8245b9c547cSRui Paulo if (triggers[NL80211_WOWLAN_TRIG_MAGIC_PKT])
8255b9c547cSRui Paulo capa->wowlan_triggers.magic_pkt = 1;
8265b9c547cSRui Paulo if (triggers[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE])
8275b9c547cSRui Paulo capa->wowlan_triggers.gtk_rekey_failure = 1;
8285b9c547cSRui Paulo if (triggers[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST])
8295b9c547cSRui Paulo capa->wowlan_triggers.eap_identity_req = 1;
8305b9c547cSRui Paulo if (triggers[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE])
8315b9c547cSRui Paulo capa->wowlan_triggers.four_way_handshake = 1;
8325b9c547cSRui Paulo if (triggers[NL80211_WOWLAN_TRIG_RFKILL_RELEASE])
8335b9c547cSRui Paulo capa->wowlan_triggers.rfkill_release = 1;
8345b9c547cSRui Paulo }
8355b9c547cSRui Paulo
8365b9c547cSRui Paulo
wiphy_info_extended_capab(struct wpa_driver_nl80211_data * drv,struct nlattr * tb)837780fb4a2SCy Schubert static void wiphy_info_extended_capab(struct wpa_driver_nl80211_data *drv,
838780fb4a2SCy Schubert struct nlattr *tb)
839780fb4a2SCy Schubert {
840780fb4a2SCy Schubert int rem = 0, i;
841780fb4a2SCy Schubert struct nlattr *tb1[NL80211_ATTR_MAX + 1], *attr;
842780fb4a2SCy Schubert
843*a90b9d01SCy Schubert if (!tb || drv->num_iface_capa == NL80211_IFTYPE_MAX)
844780fb4a2SCy Schubert return;
845780fb4a2SCy Schubert
846780fb4a2SCy Schubert nla_for_each_nested(attr, tb, rem) {
847780fb4a2SCy Schubert unsigned int len;
848*a90b9d01SCy Schubert struct drv_nl80211_iface_capa *capa;
849780fb4a2SCy Schubert
850780fb4a2SCy Schubert nla_parse(tb1, NL80211_ATTR_MAX, nla_data(attr),
851780fb4a2SCy Schubert nla_len(attr), NULL);
852780fb4a2SCy Schubert
853780fb4a2SCy Schubert if (!tb1[NL80211_ATTR_IFTYPE] ||
854780fb4a2SCy Schubert !tb1[NL80211_ATTR_EXT_CAPA] ||
855780fb4a2SCy Schubert !tb1[NL80211_ATTR_EXT_CAPA_MASK])
856780fb4a2SCy Schubert continue;
857780fb4a2SCy Schubert
858*a90b9d01SCy Schubert capa = &drv->iface_capa[drv->num_iface_capa];
859780fb4a2SCy Schubert capa->iftype = nla_get_u32(tb1[NL80211_ATTR_IFTYPE]);
860780fb4a2SCy Schubert wpa_printf(MSG_DEBUG,
861780fb4a2SCy Schubert "nl80211: Driver-advertised extended capabilities for interface type %s",
862780fb4a2SCy Schubert nl80211_iftype_str(capa->iftype));
863780fb4a2SCy Schubert
864780fb4a2SCy Schubert len = nla_len(tb1[NL80211_ATTR_EXT_CAPA]);
86585732ac8SCy Schubert capa->ext_capa = os_memdup(nla_data(tb1[NL80211_ATTR_EXT_CAPA]),
86685732ac8SCy Schubert len);
867780fb4a2SCy Schubert if (!capa->ext_capa)
868780fb4a2SCy Schubert goto err;
869780fb4a2SCy Schubert
870780fb4a2SCy Schubert capa->ext_capa_len = len;
871780fb4a2SCy Schubert wpa_hexdump(MSG_DEBUG, "nl80211: Extended capabilities",
872780fb4a2SCy Schubert capa->ext_capa, capa->ext_capa_len);
873780fb4a2SCy Schubert
874780fb4a2SCy Schubert len = nla_len(tb1[NL80211_ATTR_EXT_CAPA_MASK]);
87585732ac8SCy Schubert capa->ext_capa_mask =
87685732ac8SCy Schubert os_memdup(nla_data(tb1[NL80211_ATTR_EXT_CAPA_MASK]),
87785732ac8SCy Schubert len);
878780fb4a2SCy Schubert if (!capa->ext_capa_mask)
879780fb4a2SCy Schubert goto err;
880780fb4a2SCy Schubert
881780fb4a2SCy Schubert wpa_hexdump(MSG_DEBUG, "nl80211: Extended capabilities mask",
882780fb4a2SCy Schubert capa->ext_capa_mask, capa->ext_capa_len);
883780fb4a2SCy Schubert
884*a90b9d01SCy Schubert if (tb1[NL80211_ATTR_EML_CAPABILITY] &&
885*a90b9d01SCy Schubert tb1[NL80211_ATTR_MLD_CAPA_AND_OPS]) {
886*a90b9d01SCy Schubert capa->eml_capa =
887*a90b9d01SCy Schubert nla_get_u16(tb1[NL80211_ATTR_EML_CAPABILITY]);
888*a90b9d01SCy Schubert capa->mld_capa_and_ops =
889*a90b9d01SCy Schubert nla_get_u16(tb1[NL80211_ATTR_MLD_CAPA_AND_OPS]);
890*a90b9d01SCy Schubert }
891*a90b9d01SCy Schubert
892*a90b9d01SCy Schubert wpa_printf(MSG_DEBUG,
893*a90b9d01SCy Schubert "nl80211: EML Capability: 0x%x MLD Capability: 0x%x",
894*a90b9d01SCy Schubert capa->eml_capa, capa->mld_capa_and_ops);
895*a90b9d01SCy Schubert
896*a90b9d01SCy Schubert drv->num_iface_capa++;
897*a90b9d01SCy Schubert if (drv->num_iface_capa == NL80211_IFTYPE_MAX)
898780fb4a2SCy Schubert break;
899780fb4a2SCy Schubert }
900780fb4a2SCy Schubert
901780fb4a2SCy Schubert return;
902780fb4a2SCy Schubert
903780fb4a2SCy Schubert err:
904780fb4a2SCy Schubert /* Cleanup allocated memory on error */
905780fb4a2SCy Schubert for (i = 0; i < NL80211_IFTYPE_MAX; i++) {
906*a90b9d01SCy Schubert os_free(drv->iface_capa[i].ext_capa);
907*a90b9d01SCy Schubert drv->iface_capa[i].ext_capa = NULL;
908*a90b9d01SCy Schubert os_free(drv->iface_capa[i].ext_capa_mask);
909*a90b9d01SCy Schubert drv->iface_capa[i].ext_capa_mask = NULL;
910*a90b9d01SCy Schubert drv->iface_capa[i].ext_capa_len = 0;
911780fb4a2SCy Schubert }
912*a90b9d01SCy Schubert drv->num_iface_capa = 0;
913*a90b9d01SCy Schubert }
914*a90b9d01SCy Schubert
915*a90b9d01SCy Schubert
wiphy_info_mbssid(struct wpa_driver_capa * cap,struct nlattr * attr)916*a90b9d01SCy Schubert static void wiphy_info_mbssid(struct wpa_driver_capa *cap, struct nlattr *attr)
917*a90b9d01SCy Schubert {
918*a90b9d01SCy Schubert struct nlattr *config[NL80211_MBSSID_CONFIG_ATTR_MAX + 1];
919*a90b9d01SCy Schubert
920*a90b9d01SCy Schubert if (nla_parse_nested(config, NL80211_MBSSID_CONFIG_ATTR_MAX, attr,
921*a90b9d01SCy Schubert NULL))
922*a90b9d01SCy Schubert return;
923*a90b9d01SCy Schubert
924*a90b9d01SCy Schubert if (!config[NL80211_MBSSID_CONFIG_ATTR_MAX_INTERFACES])
925*a90b9d01SCy Schubert return;
926*a90b9d01SCy Schubert
927*a90b9d01SCy Schubert cap->mbssid_max_interfaces =
928*a90b9d01SCy Schubert nla_get_u8(config[NL80211_MBSSID_CONFIG_ATTR_MAX_INTERFACES]);
929*a90b9d01SCy Schubert
930*a90b9d01SCy Schubert if (config[NL80211_MBSSID_CONFIG_ATTR_MAX_EMA_PROFILE_PERIODICITY])
931*a90b9d01SCy Schubert cap->ema_max_periodicity =
932*a90b9d01SCy Schubert nla_get_u8(config[NL80211_MBSSID_CONFIG_ATTR_MAX_EMA_PROFILE_PERIODICITY]);
933*a90b9d01SCy Schubert
934*a90b9d01SCy Schubert wpa_printf(MSG_DEBUG,
935*a90b9d01SCy Schubert "mbssid: max interfaces %u, max profile periodicity %u",
936*a90b9d01SCy Schubert cap->mbssid_max_interfaces, cap->ema_max_periodicity);
937780fb4a2SCy Schubert }
938780fb4a2SCy Schubert
939780fb4a2SCy Schubert
wiphy_info_handler(struct nl_msg * msg,void * arg)9405b9c547cSRui Paulo static int wiphy_info_handler(struct nl_msg *msg, void *arg)
9415b9c547cSRui Paulo {
9425b9c547cSRui Paulo struct nlattr *tb[NL80211_ATTR_MAX + 1];
9435b9c547cSRui Paulo struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
9445b9c547cSRui Paulo struct wiphy_info_data *info = arg;
9455b9c547cSRui Paulo struct wpa_driver_capa *capa = info->capa;
9465b9c547cSRui Paulo struct wpa_driver_nl80211_data *drv = info->drv;
9475b9c547cSRui Paulo
9485b9c547cSRui Paulo nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
9495b9c547cSRui Paulo genlmsg_attrlen(gnlh, 0), NULL);
9505b9c547cSRui Paulo
951780fb4a2SCy Schubert if (tb[NL80211_ATTR_WIPHY])
952780fb4a2SCy Schubert drv->wiphy_idx = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
953780fb4a2SCy Schubert
9545b9c547cSRui Paulo if (tb[NL80211_ATTR_WIPHY_NAME])
9555b9c547cSRui Paulo os_strlcpy(drv->phyname,
9565b9c547cSRui Paulo nla_get_string(tb[NL80211_ATTR_WIPHY_NAME]),
9575b9c547cSRui Paulo sizeof(drv->phyname));
9585b9c547cSRui Paulo if (tb[NL80211_ATTR_MAX_NUM_SCAN_SSIDS])
9595b9c547cSRui Paulo capa->max_scan_ssids =
9605b9c547cSRui Paulo nla_get_u8(tb[NL80211_ATTR_MAX_NUM_SCAN_SSIDS]);
9615b9c547cSRui Paulo
9625b9c547cSRui Paulo if (tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS])
9635b9c547cSRui Paulo capa->max_sched_scan_ssids =
9645b9c547cSRui Paulo nla_get_u8(tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS]);
9655b9c547cSRui Paulo
966780fb4a2SCy Schubert if (tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS] &&
967780fb4a2SCy Schubert tb[NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL] &&
968780fb4a2SCy Schubert tb[NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS]) {
969780fb4a2SCy Schubert capa->max_sched_scan_plans =
970780fb4a2SCy Schubert nla_get_u32(tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS]);
971780fb4a2SCy Schubert
972780fb4a2SCy Schubert capa->max_sched_scan_plan_interval =
973780fb4a2SCy Schubert nla_get_u32(tb[NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL]);
974780fb4a2SCy Schubert
975780fb4a2SCy Schubert capa->max_sched_scan_plan_iterations =
976780fb4a2SCy Schubert nla_get_u32(tb[NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS]);
977780fb4a2SCy Schubert }
978780fb4a2SCy Schubert
9795b9c547cSRui Paulo if (tb[NL80211_ATTR_MAX_MATCH_SETS])
9805b9c547cSRui Paulo capa->max_match_sets =
9815b9c547cSRui Paulo nla_get_u8(tb[NL80211_ATTR_MAX_MATCH_SETS]);
9825b9c547cSRui Paulo
9835b9c547cSRui Paulo if (tb[NL80211_ATTR_MAC_ACL_MAX])
9845b9c547cSRui Paulo capa->max_acl_mac_addrs =
985c1d255d3SCy Schubert nla_get_u32(tb[NL80211_ATTR_MAC_ACL_MAX]);
9865b9c547cSRui Paulo
9875b9c547cSRui Paulo wiphy_info_supported_iftypes(info, tb[NL80211_ATTR_SUPPORTED_IFTYPES]);
9885b9c547cSRui Paulo wiphy_info_iface_comb(info, tb[NL80211_ATTR_INTERFACE_COMBINATIONS]);
9895b9c547cSRui Paulo wiphy_info_supp_cmds(info, tb[NL80211_ATTR_SUPPORTED_COMMANDS]);
9905b9c547cSRui Paulo wiphy_info_cipher_suites(info, tb[NL80211_ATTR_CIPHER_SUITES]);
991c1d255d3SCy Schubert wiphy_info_akm_suites(info, tb[NL80211_ATTR_AKM_SUITES]);
992c1d255d3SCy Schubert wiphy_info_iftype_akm_suites(info, tb[NL80211_ATTR_IFTYPE_AKM_SUITES]);
9935b9c547cSRui Paulo
9945b9c547cSRui Paulo if (tb[NL80211_ATTR_OFFCHANNEL_TX_OK]) {
9955b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "nl80211: Using driver-based "
9965b9c547cSRui Paulo "off-channel TX");
9975b9c547cSRui Paulo capa->flags |= WPA_DRIVER_FLAGS_OFFCHANNEL_TX;
9985b9c547cSRui Paulo }
9995b9c547cSRui Paulo
10005b9c547cSRui Paulo if (tb[NL80211_ATTR_ROAM_SUPPORT]) {
10015b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "nl80211: Using driver-based roaming");
10025b9c547cSRui Paulo capa->flags |= WPA_DRIVER_FLAGS_BSS_SELECTION;
10035b9c547cSRui Paulo }
10045b9c547cSRui Paulo
10055b9c547cSRui Paulo wiphy_info_max_roc(capa,
10065b9c547cSRui Paulo tb[NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION]);
10075b9c547cSRui Paulo
10085b9c547cSRui Paulo if (tb[NL80211_ATTR_SUPPORT_AP_UAPSD])
10095b9c547cSRui Paulo capa->flags |= WPA_DRIVER_FLAGS_AP_UAPSD;
10105b9c547cSRui Paulo
10115b9c547cSRui Paulo wiphy_info_tdls(capa, tb[NL80211_ATTR_TDLS_SUPPORT],
10125b9c547cSRui Paulo tb[NL80211_ATTR_TDLS_EXTERNAL_SETUP]);
10135b9c547cSRui Paulo
1014*a90b9d01SCy Schubert if (tb[NL80211_ATTR_DEVICE_AP_SME]) {
1015*a90b9d01SCy Schubert u32 ap_sme_features_flags =
1016*a90b9d01SCy Schubert nla_get_u32(tb[NL80211_ATTR_DEVICE_AP_SME]);
1017*a90b9d01SCy Schubert
1018*a90b9d01SCy Schubert if (ap_sme_features_flags & NL80211_AP_SME_SA_QUERY_OFFLOAD)
1019*a90b9d01SCy Schubert capa->flags2 |= WPA_DRIVER_FLAGS2_SA_QUERY_OFFLOAD_AP;
1020*a90b9d01SCy Schubert
10215b9c547cSRui Paulo info->device_ap_sme = 1;
1022*a90b9d01SCy Schubert }
10235b9c547cSRui Paulo
10245b9c547cSRui Paulo wiphy_info_feature_flags(info, tb[NL80211_ATTR_FEATURE_FLAGS]);
1025325151a3SRui Paulo wiphy_info_ext_feature_flags(info, tb[NL80211_ATTR_EXT_FEATURES]);
10265b9c547cSRui Paulo wiphy_info_probe_resp_offload(capa,
10275b9c547cSRui Paulo tb[NL80211_ATTR_PROBE_RESP_OFFLOAD]);
10285b9c547cSRui Paulo
10295b9c547cSRui Paulo if (tb[NL80211_ATTR_EXT_CAPA] && tb[NL80211_ATTR_EXT_CAPA_MASK] &&
10305b9c547cSRui Paulo drv->extended_capa == NULL) {
10315b9c547cSRui Paulo drv->extended_capa =
10325b9c547cSRui Paulo os_malloc(nla_len(tb[NL80211_ATTR_EXT_CAPA]));
10335b9c547cSRui Paulo if (drv->extended_capa) {
10345b9c547cSRui Paulo os_memcpy(drv->extended_capa,
10355b9c547cSRui Paulo nla_data(tb[NL80211_ATTR_EXT_CAPA]),
10365b9c547cSRui Paulo nla_len(tb[NL80211_ATTR_EXT_CAPA]));
10375b9c547cSRui Paulo drv->extended_capa_len =
10385b9c547cSRui Paulo nla_len(tb[NL80211_ATTR_EXT_CAPA]);
1039780fb4a2SCy Schubert wpa_hexdump(MSG_DEBUG,
1040780fb4a2SCy Schubert "nl80211: Driver-advertised extended capabilities (default)",
1041780fb4a2SCy Schubert drv->extended_capa, drv->extended_capa_len);
10425b9c547cSRui Paulo }
10435b9c547cSRui Paulo drv->extended_capa_mask =
10445b9c547cSRui Paulo os_malloc(nla_len(tb[NL80211_ATTR_EXT_CAPA_MASK]));
10455b9c547cSRui Paulo if (drv->extended_capa_mask) {
10465b9c547cSRui Paulo os_memcpy(drv->extended_capa_mask,
10475b9c547cSRui Paulo nla_data(tb[NL80211_ATTR_EXT_CAPA_MASK]),
10485b9c547cSRui Paulo nla_len(tb[NL80211_ATTR_EXT_CAPA_MASK]));
1049780fb4a2SCy Schubert wpa_hexdump(MSG_DEBUG,
1050780fb4a2SCy Schubert "nl80211: Driver-advertised extended capabilities mask (default)",
1051780fb4a2SCy Schubert drv->extended_capa_mask,
1052780fb4a2SCy Schubert drv->extended_capa_len);
10535b9c547cSRui Paulo } else {
10545b9c547cSRui Paulo os_free(drv->extended_capa);
10555b9c547cSRui Paulo drv->extended_capa = NULL;
10565b9c547cSRui Paulo drv->extended_capa_len = 0;
10575b9c547cSRui Paulo }
10585b9c547cSRui Paulo }
10595b9c547cSRui Paulo
1060780fb4a2SCy Schubert wiphy_info_extended_capab(drv, tb[NL80211_ATTR_IFTYPE_EXT_CAPA]);
1061780fb4a2SCy Schubert
10625b9c547cSRui Paulo if (tb[NL80211_ATTR_VENDOR_DATA]) {
10635b9c547cSRui Paulo struct nlattr *nl;
10645b9c547cSRui Paulo int rem;
10655b9c547cSRui Paulo
10665b9c547cSRui Paulo nla_for_each_nested(nl, tb[NL80211_ATTR_VENDOR_DATA], rem) {
10675b9c547cSRui Paulo struct nl80211_vendor_cmd_info *vinfo;
10685b9c547cSRui Paulo if (nla_len(nl) != sizeof(*vinfo)) {
10695b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "nl80211: Unexpected vendor data info");
10705b9c547cSRui Paulo continue;
10715b9c547cSRui Paulo }
10725b9c547cSRui Paulo vinfo = nla_data(nl);
1073325151a3SRui Paulo if (vinfo->vendor_id == OUI_QCA) {
10745b9c547cSRui Paulo switch (vinfo->subcmd) {
10755b9c547cSRui Paulo case QCA_NL80211_VENDOR_SUBCMD_TEST:
10765b9c547cSRui Paulo drv->vendor_cmd_test_avail = 1;
10775b9c547cSRui Paulo break;
1078780fb4a2SCy Schubert #ifdef CONFIG_DRIVER_NL80211_QCA
10795b9c547cSRui Paulo case QCA_NL80211_VENDOR_SUBCMD_ROAMING:
10805b9c547cSRui Paulo drv->roaming_vendor_cmd_avail = 1;
10815b9c547cSRui Paulo break;
10825b9c547cSRui Paulo case QCA_NL80211_VENDOR_SUBCMD_DFS_CAPABILITY:
10835b9c547cSRui Paulo drv->dfs_vendor_cmd_avail = 1;
10845b9c547cSRui Paulo break;
10855b9c547cSRui Paulo case QCA_NL80211_VENDOR_SUBCMD_GET_FEATURES:
10865b9c547cSRui Paulo drv->get_features_vendor_cmd_avail = 1;
10875b9c547cSRui Paulo break;
1088325151a3SRui Paulo case QCA_NL80211_VENDOR_SUBCMD_GET_PREFERRED_FREQ_LIST:
1089325151a3SRui Paulo drv->get_pref_freq_list = 1;
10905b9c547cSRui Paulo break;
1091325151a3SRui Paulo case QCA_NL80211_VENDOR_SUBCMD_SET_PROBABLE_OPER_CHANNEL:
1092325151a3SRui Paulo drv->set_prob_oper_freq = 1;
1093325151a3SRui Paulo break;
1094325151a3SRui Paulo case QCA_NL80211_VENDOR_SUBCMD_DO_ACS:
1095325151a3SRui Paulo drv->capa.flags |=
1096325151a3SRui Paulo WPA_DRIVER_FLAGS_ACS_OFFLOAD;
1097c1d255d3SCy Schubert drv->qca_do_acs = 1;
1098325151a3SRui Paulo break;
1099325151a3SRui Paulo case QCA_NL80211_VENDOR_SUBCMD_SETBAND:
1100325151a3SRui Paulo drv->setband_vendor_cmd_avail = 1;
1101325151a3SRui Paulo break;
1102780fb4a2SCy Schubert case QCA_NL80211_VENDOR_SUBCMD_TRIGGER_SCAN:
1103780fb4a2SCy Schubert drv->scan_vendor_cmd_avail = 1;
1104780fb4a2SCy Schubert break;
1105780fb4a2SCy Schubert case QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION:
1106780fb4a2SCy Schubert drv->set_wifi_conf_vendor_cmd_avail = 1;
1107780fb4a2SCy Schubert break;
110885732ac8SCy Schubert case QCA_NL80211_VENDOR_SUBCMD_FETCH_BSS_TRANSITION_STATUS:
110985732ac8SCy Schubert drv->fetch_bss_trans_status = 1;
111085732ac8SCy Schubert break;
111185732ac8SCy Schubert case QCA_NL80211_VENDOR_SUBCMD_ROAM:
111285732ac8SCy Schubert drv->roam_vendor_cmd_avail = 1;
111385732ac8SCy Schubert break;
1114c1d255d3SCy Schubert case QCA_NL80211_VENDOR_SUBCMD_ADD_STA_NODE:
1115c1d255d3SCy Schubert drv->add_sta_node_vendor_cmd_avail = 1;
1116c1d255d3SCy Schubert break;
1117c1d255d3SCy Schubert case QCA_NL80211_VENDOR_SUBCMD_GET_STA_INFO:
1118c1d255d3SCy Schubert drv->get_sta_info_vendor_cmd_avail = 1;
11194bc52338SCy Schubert break;
1120*a90b9d01SCy Schubert case QCA_NL80211_VENDOR_SUBCMD_SECURE_RANGING_CONTEXT:
1121*a90b9d01SCy Schubert drv->secure_ranging_ctx_vendor_cmd_avail = 1;
1122*a90b9d01SCy Schubert break;
1123780fb4a2SCy Schubert #endif /* CONFIG_DRIVER_NL80211_QCA */
1124325151a3SRui Paulo }
1125c1d255d3SCy Schubert #ifdef CONFIG_DRIVER_NL80211_BRCM
1126c1d255d3SCy Schubert } else if (vinfo->vendor_id == OUI_BRCM) {
1127c1d255d3SCy Schubert switch (vinfo->subcmd) {
1128c1d255d3SCy Schubert case BRCM_VENDOR_SCMD_ACS:
1129c1d255d3SCy Schubert drv->capa.flags |=
1130c1d255d3SCy Schubert WPA_DRIVER_FLAGS_ACS_OFFLOAD;
1131c1d255d3SCy Schubert wpa_printf(MSG_DEBUG,
1132c1d255d3SCy Schubert "Enabled BRCM ACS");
1133c1d255d3SCy Schubert drv->brcm_do_acs = 1;
1134c1d255d3SCy Schubert break;
1135c1d255d3SCy Schubert }
1136c1d255d3SCy Schubert #endif /* CONFIG_DRIVER_NL80211_BRCM */
11375b9c547cSRui Paulo }
11385b9c547cSRui Paulo
11395b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "nl80211: Supported vendor command: vendor_id=0x%x subcmd=%u",
11405b9c547cSRui Paulo vinfo->vendor_id, vinfo->subcmd);
11415b9c547cSRui Paulo }
11425b9c547cSRui Paulo }
11435b9c547cSRui Paulo
11445b9c547cSRui Paulo if (tb[NL80211_ATTR_VENDOR_EVENTS]) {
11455b9c547cSRui Paulo struct nlattr *nl;
11465b9c547cSRui Paulo int rem;
11475b9c547cSRui Paulo
11485b9c547cSRui Paulo nla_for_each_nested(nl, tb[NL80211_ATTR_VENDOR_EVENTS], rem) {
11495b9c547cSRui Paulo struct nl80211_vendor_cmd_info *vinfo;
11505b9c547cSRui Paulo if (nla_len(nl) != sizeof(*vinfo)) {
11515b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "nl80211: Unexpected vendor data info");
11525b9c547cSRui Paulo continue;
11535b9c547cSRui Paulo }
11545b9c547cSRui Paulo vinfo = nla_data(nl);
11555b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "nl80211: Supported vendor event: vendor_id=0x%x subcmd=%u",
11565b9c547cSRui Paulo vinfo->vendor_id, vinfo->subcmd);
11575b9c547cSRui Paulo }
11585b9c547cSRui Paulo }
11595b9c547cSRui Paulo
11605b9c547cSRui Paulo wiphy_info_wowlan_triggers(capa,
11615b9c547cSRui Paulo tb[NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED]);
11625b9c547cSRui Paulo
11635b9c547cSRui Paulo if (tb[NL80211_ATTR_MAX_AP_ASSOC_STA])
11645b9c547cSRui Paulo capa->max_stations =
11655b9c547cSRui Paulo nla_get_u32(tb[NL80211_ATTR_MAX_AP_ASSOC_STA]);
11665b9c547cSRui Paulo
1167780fb4a2SCy Schubert if (tb[NL80211_ATTR_MAX_CSA_COUNTERS])
1168780fb4a2SCy Schubert capa->max_csa_counters =
1169780fb4a2SCy Schubert nla_get_u8(tb[NL80211_ATTR_MAX_CSA_COUNTERS]);
1170780fb4a2SCy Schubert
117185732ac8SCy Schubert if (tb[NL80211_ATTR_WIPHY_SELF_MANAGED_REG])
117285732ac8SCy Schubert capa->flags |= WPA_DRIVER_FLAGS_SELF_MANAGED_REGULATORY;
117385732ac8SCy Schubert
1174*a90b9d01SCy Schubert if (tb[NL80211_ATTR_MAX_NUM_AKM_SUITES])
1175*a90b9d01SCy Schubert capa->max_num_akms =
1176*a90b9d01SCy Schubert nla_get_u16(tb[NL80211_ATTR_MAX_NUM_AKM_SUITES]);
1177*a90b9d01SCy Schubert
1178*a90b9d01SCy Schubert if (tb[NL80211_ATTR_MBSSID_CONFIG])
1179*a90b9d01SCy Schubert wiphy_info_mbssid(capa, tb[NL80211_ATTR_MBSSID_CONFIG]);
1180*a90b9d01SCy Schubert
1181*a90b9d01SCy Schubert if (tb[NL80211_ATTR_MLO_SUPPORT])
1182*a90b9d01SCy Schubert capa->flags2 |= WPA_DRIVER_FLAGS2_MLO;
1183*a90b9d01SCy Schubert
11845b9c547cSRui Paulo return NL_SKIP;
11855b9c547cSRui Paulo }
11865b9c547cSRui Paulo
11875b9c547cSRui Paulo
wpa_driver_nl80211_get_info(struct wpa_driver_nl80211_data * drv,struct wiphy_info_data * info)11885b9c547cSRui Paulo static int wpa_driver_nl80211_get_info(struct wpa_driver_nl80211_data *drv,
11895b9c547cSRui Paulo struct wiphy_info_data *info)
11905b9c547cSRui Paulo {
11915b9c547cSRui Paulo u32 feat;
11925b9c547cSRui Paulo struct nl_msg *msg;
11935b9c547cSRui Paulo int flags = 0;
11945b9c547cSRui Paulo
11955b9c547cSRui Paulo os_memset(info, 0, sizeof(*info));
11965b9c547cSRui Paulo info->capa = &drv->capa;
11975b9c547cSRui Paulo info->drv = drv;
11985b9c547cSRui Paulo
11995b9c547cSRui Paulo feat = get_nl80211_protocol_features(drv);
12005b9c547cSRui Paulo if (feat & NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)
12015b9c547cSRui Paulo flags = NLM_F_DUMP;
12025b9c547cSRui Paulo msg = nl80211_cmd_msg(drv->first_bss, flags, NL80211_CMD_GET_WIPHY);
12035b9c547cSRui Paulo if (!msg || nla_put_flag(msg, NL80211_ATTR_SPLIT_WIPHY_DUMP)) {
12045b9c547cSRui Paulo nlmsg_free(msg);
12055b9c547cSRui Paulo return -1;
12065b9c547cSRui Paulo }
12075b9c547cSRui Paulo
1208*a90b9d01SCy Schubert if (send_and_recv_resp(drv, msg, wiphy_info_handler, info))
12095b9c547cSRui Paulo return -1;
12105b9c547cSRui Paulo
12115b9c547cSRui Paulo if (info->auth_supported)
12125b9c547cSRui Paulo drv->capa.flags |= WPA_DRIVER_FLAGS_SME;
12135b9c547cSRui Paulo else if (!info->connect_supported) {
12145b9c547cSRui Paulo wpa_printf(MSG_INFO, "nl80211: Driver does not support "
12155b9c547cSRui Paulo "authentication/association or connect commands");
12165b9c547cSRui Paulo info->error = 1;
12175b9c547cSRui Paulo }
12185b9c547cSRui Paulo
12195b9c547cSRui Paulo if (info->p2p_go_supported && info->p2p_client_supported)
12205b9c547cSRui Paulo drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CAPABLE;
12215b9c547cSRui Paulo if (info->p2p_concurrent) {
12225b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group "
12235b9c547cSRui Paulo "interface (driver advertised support)");
12245b9c547cSRui Paulo drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT;
12255b9c547cSRui Paulo drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P;
12265b9c547cSRui Paulo }
12275b9c547cSRui Paulo if (info->num_multichan_concurrent > 1) {
12285b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "nl80211: Enable multi-channel "
12295b9c547cSRui Paulo "concurrent (driver advertised support)");
12305b9c547cSRui Paulo drv->capa.num_multichan_concurrent =
12315b9c547cSRui Paulo info->num_multichan_concurrent;
12325b9c547cSRui Paulo }
12335b9c547cSRui Paulo if (drv->capa.flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)
12345b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "nl80211: use P2P_DEVICE support");
12355b9c547cSRui Paulo
12365b9c547cSRui Paulo /* default to 5000 since early versions of mac80211 don't set it */
12375b9c547cSRui Paulo if (!drv->capa.max_remain_on_chan)
12385b9c547cSRui Paulo drv->capa.max_remain_on_chan = 5000;
12395b9c547cSRui Paulo
12405b9c547cSRui Paulo drv->capa.wmm_ac_supported = info->wmm_ac_supported;
12415b9c547cSRui Paulo
12425b9c547cSRui Paulo drv->capa.mac_addr_rand_sched_scan_supported =
12435b9c547cSRui Paulo info->mac_addr_rand_sched_scan_supported;
12445b9c547cSRui Paulo drv->capa.mac_addr_rand_scan_supported =
12455b9c547cSRui Paulo info->mac_addr_rand_scan_supported;
12465b9c547cSRui Paulo
1247780fb4a2SCy Schubert if (info->channel_switch_supported) {
1248780fb4a2SCy Schubert drv->capa.flags |= WPA_DRIVER_FLAGS_AP_CSA;
1249780fb4a2SCy Schubert if (!drv->capa.max_csa_counters)
1250780fb4a2SCy Schubert drv->capa.max_csa_counters = 1;
1251780fb4a2SCy Schubert }
1252780fb4a2SCy Schubert
1253780fb4a2SCy Schubert if (!drv->capa.max_sched_scan_plans) {
1254780fb4a2SCy Schubert drv->capa.max_sched_scan_plans = 1;
1255780fb4a2SCy Schubert drv->capa.max_sched_scan_plan_interval = UINT32_MAX;
1256780fb4a2SCy Schubert drv->capa.max_sched_scan_plan_iterations = 0;
1257780fb4a2SCy Schubert }
1258780fb4a2SCy Schubert
1259c1d255d3SCy Schubert if (info->update_ft_ies_supported)
1260c1d255d3SCy Schubert drv->capa.flags |= WPA_DRIVER_FLAGS_UPDATE_FT_IES;
1261c1d255d3SCy Schubert
1262*a90b9d01SCy Schubert if (!drv->capa.max_num_akms)
1263*a90b9d01SCy Schubert drv->capa.max_num_akms = NL80211_MAX_NR_AKM_SUITES;
1264*a90b9d01SCy Schubert
12655b9c547cSRui Paulo return 0;
12665b9c547cSRui Paulo }
12675b9c547cSRui Paulo
12685b9c547cSRui Paulo
1269780fb4a2SCy Schubert #ifdef CONFIG_DRIVER_NL80211_QCA
1270780fb4a2SCy Schubert
dfs_info_handler(struct nl_msg * msg,void * arg)12715b9c547cSRui Paulo static int dfs_info_handler(struct nl_msg *msg, void *arg)
12725b9c547cSRui Paulo {
12735b9c547cSRui Paulo struct nlattr *tb[NL80211_ATTR_MAX + 1];
12745b9c547cSRui Paulo struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
12755b9c547cSRui Paulo int *dfs_capability_ptr = arg;
12765b9c547cSRui Paulo
12775b9c547cSRui Paulo nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
12785b9c547cSRui Paulo genlmsg_attrlen(gnlh, 0), NULL);
12795b9c547cSRui Paulo
12805b9c547cSRui Paulo if (tb[NL80211_ATTR_VENDOR_DATA]) {
12815b9c547cSRui Paulo struct nlattr *nl_vend = tb[NL80211_ATTR_VENDOR_DATA];
12825b9c547cSRui Paulo struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1];
12835b9c547cSRui Paulo
12845b9c547cSRui Paulo nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX,
12855b9c547cSRui Paulo nla_data(nl_vend), nla_len(nl_vend), NULL);
12865b9c547cSRui Paulo
12875b9c547cSRui Paulo if (tb_vendor[QCA_WLAN_VENDOR_ATTR_DFS]) {
12885b9c547cSRui Paulo u32 val;
12895b9c547cSRui Paulo val = nla_get_u32(tb_vendor[QCA_WLAN_VENDOR_ATTR_DFS]);
12905b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "nl80211: DFS offload capability: %u",
12915b9c547cSRui Paulo val);
12925b9c547cSRui Paulo *dfs_capability_ptr = val;
12935b9c547cSRui Paulo }
12945b9c547cSRui Paulo }
12955b9c547cSRui Paulo
12965b9c547cSRui Paulo return NL_SKIP;
12975b9c547cSRui Paulo }
12985b9c547cSRui Paulo
12995b9c547cSRui Paulo
qca_nl80211_check_dfs_capa(struct wpa_driver_nl80211_data * drv)13005b9c547cSRui Paulo static void qca_nl80211_check_dfs_capa(struct wpa_driver_nl80211_data *drv)
13015b9c547cSRui Paulo {
13025b9c547cSRui Paulo struct nl_msg *msg;
13035b9c547cSRui Paulo int dfs_capability = 0;
13045b9c547cSRui Paulo int ret;
13055b9c547cSRui Paulo
13065b9c547cSRui Paulo if (!drv->dfs_vendor_cmd_avail)
13075b9c547cSRui Paulo return;
13085b9c547cSRui Paulo
13095b9c547cSRui Paulo if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
13105b9c547cSRui Paulo nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
13115b9c547cSRui Paulo nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
13125b9c547cSRui Paulo QCA_NL80211_VENDOR_SUBCMD_DFS_CAPABILITY)) {
13135b9c547cSRui Paulo nlmsg_free(msg);
13145b9c547cSRui Paulo return;
13155b9c547cSRui Paulo }
13165b9c547cSRui Paulo
1317*a90b9d01SCy Schubert ret = send_and_recv_resp(drv, msg, dfs_info_handler, &dfs_capability);
13185b9c547cSRui Paulo if (!ret && dfs_capability)
13195b9c547cSRui Paulo drv->capa.flags |= WPA_DRIVER_FLAGS_DFS_OFFLOAD;
13205b9c547cSRui Paulo }
13215b9c547cSRui Paulo
13225b9c547cSRui Paulo
13235b9c547cSRui Paulo struct features_info {
13245b9c547cSRui Paulo u8 *flags;
13255b9c547cSRui Paulo size_t flags_len;
1326325151a3SRui Paulo struct wpa_driver_capa *capa;
13275b9c547cSRui Paulo };
13285b9c547cSRui Paulo
13295b9c547cSRui Paulo
features_info_handler(struct nl_msg * msg,void * arg)13305b9c547cSRui Paulo static int features_info_handler(struct nl_msg *msg, void *arg)
13315b9c547cSRui Paulo {
13325b9c547cSRui Paulo struct nlattr *tb[NL80211_ATTR_MAX + 1];
13335b9c547cSRui Paulo struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
13345b9c547cSRui Paulo struct features_info *info = arg;
13355b9c547cSRui Paulo struct nlattr *nl_vend, *attr;
13365b9c547cSRui Paulo
13375b9c547cSRui Paulo nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
13385b9c547cSRui Paulo genlmsg_attrlen(gnlh, 0), NULL);
13395b9c547cSRui Paulo
13405b9c547cSRui Paulo nl_vend = tb[NL80211_ATTR_VENDOR_DATA];
13415b9c547cSRui Paulo if (nl_vend) {
13425b9c547cSRui Paulo struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1];
13435b9c547cSRui Paulo
13445b9c547cSRui Paulo nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX,
13455b9c547cSRui Paulo nla_data(nl_vend), nla_len(nl_vend), NULL);
13465b9c547cSRui Paulo
13475b9c547cSRui Paulo attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_FEATURE_FLAGS];
13485b9c547cSRui Paulo if (attr) {
1349780fb4a2SCy Schubert int len = nla_len(attr);
1350780fb4a2SCy Schubert info->flags = os_malloc(len);
1351780fb4a2SCy Schubert if (info->flags != NULL) {
1352780fb4a2SCy Schubert os_memcpy(info->flags, nla_data(attr), len);
1353780fb4a2SCy Schubert info->flags_len = len;
1354780fb4a2SCy Schubert }
13555b9c547cSRui Paulo }
1356325151a3SRui Paulo attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_CONCURRENCY_CAPA];
1357325151a3SRui Paulo if (attr)
1358325151a3SRui Paulo info->capa->conc_capab = nla_get_u32(attr);
1359325151a3SRui Paulo
1360325151a3SRui Paulo attr = tb_vendor[
1361325151a3SRui Paulo QCA_WLAN_VENDOR_ATTR_MAX_CONCURRENT_CHANNELS_2_4_BAND];
1362325151a3SRui Paulo if (attr)
1363325151a3SRui Paulo info->capa->max_conc_chan_2_4 = nla_get_u32(attr);
1364325151a3SRui Paulo
1365325151a3SRui Paulo attr = tb_vendor[
1366325151a3SRui Paulo QCA_WLAN_VENDOR_ATTR_MAX_CONCURRENT_CHANNELS_5_0_BAND];
1367325151a3SRui Paulo if (attr)
1368325151a3SRui Paulo info->capa->max_conc_chan_5_0 = nla_get_u32(attr);
13695b9c547cSRui Paulo }
13705b9c547cSRui Paulo
13715b9c547cSRui Paulo return NL_SKIP;
13725b9c547cSRui Paulo }
13735b9c547cSRui Paulo
13745b9c547cSRui Paulo
check_feature(enum qca_wlan_vendor_features feature,struct features_info * info)13755b9c547cSRui Paulo static int check_feature(enum qca_wlan_vendor_features feature,
13765b9c547cSRui Paulo struct features_info *info)
13775b9c547cSRui Paulo {
13785b9c547cSRui Paulo size_t idx = feature / 8;
13795b9c547cSRui Paulo
13805b9c547cSRui Paulo return (idx < info->flags_len) &&
13815b9c547cSRui Paulo (info->flags[idx] & BIT(feature % 8));
13825b9c547cSRui Paulo }
13835b9c547cSRui Paulo
13845b9c547cSRui Paulo
qca_nl80211_get_features(struct wpa_driver_nl80211_data * drv)13855b9c547cSRui Paulo static void qca_nl80211_get_features(struct wpa_driver_nl80211_data *drv)
13865b9c547cSRui Paulo {
13875b9c547cSRui Paulo struct nl_msg *msg;
13885b9c547cSRui Paulo struct features_info info;
13895b9c547cSRui Paulo int ret;
13905b9c547cSRui Paulo
13915b9c547cSRui Paulo if (!drv->get_features_vendor_cmd_avail)
13925b9c547cSRui Paulo return;
13935b9c547cSRui Paulo
13945b9c547cSRui Paulo if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
13955b9c547cSRui Paulo nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
13965b9c547cSRui Paulo nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
13975b9c547cSRui Paulo QCA_NL80211_VENDOR_SUBCMD_GET_FEATURES)) {
13985b9c547cSRui Paulo nlmsg_free(msg);
13995b9c547cSRui Paulo return;
14005b9c547cSRui Paulo }
14015b9c547cSRui Paulo
14025b9c547cSRui Paulo os_memset(&info, 0, sizeof(info));
1403325151a3SRui Paulo info.capa = &drv->capa;
1404*a90b9d01SCy Schubert ret = send_and_recv_resp(drv, msg, features_info_handler, &info);
14055b9c547cSRui Paulo if (ret || !info.flags)
14065b9c547cSRui Paulo return;
14075b9c547cSRui Paulo
14085b9c547cSRui Paulo if (check_feature(QCA_WLAN_VENDOR_FEATURE_KEY_MGMT_OFFLOAD, &info))
14095b9c547cSRui Paulo drv->capa.flags |= WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD;
1410325151a3SRui Paulo
1411325151a3SRui Paulo if (check_feature(QCA_WLAN_VENDOR_FEATURE_SUPPORT_HW_MODE_ANY, &info))
1412325151a3SRui Paulo drv->capa.flags |= WPA_DRIVER_FLAGS_SUPPORT_HW_MODE_ANY;
1413780fb4a2SCy Schubert
1414780fb4a2SCy Schubert if (check_feature(QCA_WLAN_VENDOR_FEATURE_OFFCHANNEL_SIMULTANEOUS,
1415780fb4a2SCy Schubert &info))
1416780fb4a2SCy Schubert drv->capa.flags |= WPA_DRIVER_FLAGS_OFFCHANNEL_SIMULTANEOUS;
1417780fb4a2SCy Schubert if (check_feature(QCA_WLAN_VENDOR_FEATURE_P2P_LISTEN_OFFLOAD, &info))
1418780fb4a2SCy Schubert drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD;
141985732ac8SCy Schubert if (check_feature(QCA_WLAN_VENDOR_FEATURE_OCE_STA, &info))
142085732ac8SCy Schubert drv->capa.flags |= WPA_DRIVER_FLAGS_OCE_STA;
142185732ac8SCy Schubert if (check_feature(QCA_WLAN_VENDOR_FEATURE_OCE_AP, &info))
142285732ac8SCy Schubert drv->capa.flags |= WPA_DRIVER_FLAGS_OCE_AP;
142385732ac8SCy Schubert if (check_feature(QCA_WLAN_VENDOR_FEATURE_OCE_STA_CFON, &info))
142485732ac8SCy Schubert drv->capa.flags |= WPA_DRIVER_FLAGS_OCE_STA_CFON;
1425*a90b9d01SCy Schubert if (check_feature(QCA_WLAN_VENDOR_FEATURE_SECURE_LTF_STA, &info))
1426*a90b9d01SCy Schubert drv->capa.flags2 |= WPA_DRIVER_FLAGS2_SEC_LTF_STA;
1427*a90b9d01SCy Schubert if (check_feature(QCA_WLAN_VENDOR_FEATURE_SECURE_LTF_AP, &info))
1428*a90b9d01SCy Schubert drv->capa.flags2 |= WPA_DRIVER_FLAGS2_SEC_LTF_AP;
1429*a90b9d01SCy Schubert if (check_feature(QCA_WLAN_VENDOR_FEATURE_SECURE_RTT_STA, &info))
1430*a90b9d01SCy Schubert drv->capa.flags2 |= WPA_DRIVER_FLAGS2_SEC_RTT_STA;
1431*a90b9d01SCy Schubert if (check_feature(QCA_WLAN_VENDOR_FEATURE_SECURE_RTT_AP, &info))
1432*a90b9d01SCy Schubert drv->capa.flags2 |= WPA_DRIVER_FLAGS2_SEC_RTT_AP;
1433*a90b9d01SCy Schubert if (check_feature(
1434*a90b9d01SCy Schubert QCA_WLAN_VENDOR_FEATURE_PROT_RANGE_NEGO_AND_MEASURE_STA,
1435*a90b9d01SCy Schubert &info))
1436*a90b9d01SCy Schubert drv->capa.flags2 |= WPA_DRIVER_FLAGS2_PROT_RANGE_NEG_STA;
1437*a90b9d01SCy Schubert if (check_feature(
1438*a90b9d01SCy Schubert QCA_WLAN_VENDOR_FEATURE_PROT_RANGE_NEGO_AND_MEASURE_AP,
1439*a90b9d01SCy Schubert &info))
1440*a90b9d01SCy Schubert drv->capa.flags2 |= WPA_DRIVER_FLAGS2_PROT_RANGE_NEG_AP;
1441*a90b9d01SCy Schubert if (check_feature(QCA_WLAN_VENDOR_FEATURE_AP_ALLOWED_FREQ_LIST,
1442*a90b9d01SCy Schubert &info))
1443*a90b9d01SCy Schubert drv->qca_ap_allowed_freqs = 1;
1444*a90b9d01SCy Schubert if (check_feature(QCA_WLAN_VENDOR_FEATURE_HT_VHT_TWT_RESPONDER, &info))
1445*a90b9d01SCy Schubert drv->capa.flags2 |= WPA_DRIVER_FLAGS2_HT_VHT_TWT_RESPONDER;
1446780fb4a2SCy Schubert os_free(info.flags);
14475b9c547cSRui Paulo }
14485b9c547cSRui Paulo
1449780fb4a2SCy Schubert #endif /* CONFIG_DRIVER_NL80211_QCA */
1450780fb4a2SCy Schubert
14515b9c547cSRui Paulo
wpa_driver_nl80211_capa(struct wpa_driver_nl80211_data * drv)14525b9c547cSRui Paulo int wpa_driver_nl80211_capa(struct wpa_driver_nl80211_data *drv)
14535b9c547cSRui Paulo {
14545b9c547cSRui Paulo struct wiphy_info_data info;
1455c1d255d3SCy Schubert int i;
1456c1d255d3SCy Schubert
14575b9c547cSRui Paulo if (wpa_driver_nl80211_get_info(drv, &info))
14585b9c547cSRui Paulo return -1;
14595b9c547cSRui Paulo
14605b9c547cSRui Paulo if (info.error)
14615b9c547cSRui Paulo return -1;
14625b9c547cSRui Paulo
14635b9c547cSRui Paulo drv->has_capability = 1;
1464c1d255d3SCy Schubert drv->has_driver_key_mgmt = info.has_key_mgmt | info.has_key_mgmt_iftype;
1465c1d255d3SCy Schubert
1466*a90b9d01SCy Schubert /* Fallback to hardcoded defaults if the driver does not advertise any
1467c1d255d3SCy Schubert * AKM capabilities. */
1468c1d255d3SCy Schubert if (!drv->has_driver_key_mgmt) {
14695b9c547cSRui Paulo drv->capa.key_mgmt = WPA_DRIVER_CAPA_KEY_MGMT_WPA |
14705b9c547cSRui Paulo WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
14715b9c547cSRui Paulo WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
14725b9c547cSRui Paulo WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK |
14735b9c547cSRui Paulo WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B |
147485732ac8SCy Schubert WPA_DRIVER_CAPA_KEY_MGMT_OWE |
147585732ac8SCy Schubert WPA_DRIVER_CAPA_KEY_MGMT_DPP;
147685732ac8SCy Schubert
1477c1d255d3SCy Schubert if (drv->capa.enc & (WPA_DRIVER_CAPA_ENC_CCMP_256 |
1478c1d255d3SCy Schubert WPA_DRIVER_CAPA_ENC_GCMP_256))
1479c1d255d3SCy Schubert drv->capa.key_mgmt |=
1480c1d255d3SCy Schubert WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192;
1481c1d255d3SCy Schubert
148285732ac8SCy Schubert if (drv->capa.flags & WPA_DRIVER_FLAGS_SME)
1483c1d255d3SCy Schubert drv->capa.key_mgmt |=
1484c1d255d3SCy Schubert WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256 |
148585732ac8SCy Schubert WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384 |
148685732ac8SCy Schubert WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA256 |
14874bc52338SCy Schubert WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA384 |
14884bc52338SCy Schubert WPA_DRIVER_CAPA_KEY_MGMT_SAE;
148985732ac8SCy Schubert else if (drv->capa.flags & WPA_DRIVER_FLAGS_FILS_SK_OFFLOAD)
1490c1d255d3SCy Schubert drv->capa.key_mgmt |=
1491c1d255d3SCy Schubert WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256 |
149285732ac8SCy Schubert WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384;
1493c1d255d3SCy Schubert }
149485732ac8SCy Schubert
1495c1d255d3SCy Schubert if (!info.has_key_mgmt_iftype) {
1496c1d255d3SCy Schubert /* If the driver does not advertize per interface AKM
1497c1d255d3SCy Schubert * capabilities, consider all interfaces to support default AKMs
1498c1d255d3SCy Schubert * in key_mgmt. */
1499c1d255d3SCy Schubert for (i = 0; i < WPA_IF_MAX; i++)
1500c1d255d3SCy Schubert drv->capa.key_mgmt_iftype[i] = drv->capa.key_mgmt;
1501c1d255d3SCy Schubert } else if (info.has_key_mgmt_iftype && !info.has_key_mgmt) {
1502c1d255d3SCy Schubert /* If the driver advertizes only per interface supported AKMs
1503c1d255d3SCy Schubert * but does not advertize per wiphy AKM capabilities, consider
1504c1d255d3SCy Schubert * the default key_mgmt as a mask of per interface supported
1505c1d255d3SCy Schubert * AKMs. */
1506c1d255d3SCy Schubert drv->capa.key_mgmt = 0;
1507c1d255d3SCy Schubert for (i = 0; i < WPA_IF_MAX; i++)
1508c1d255d3SCy Schubert drv->capa.key_mgmt |= drv->capa.key_mgmt_iftype[i];
1509c1d255d3SCy Schubert } else if (info.has_key_mgmt_iftype && info.has_key_mgmt) {
1510c1d255d3SCy Schubert /* If the driver advertizes AKM capabilities both per wiphy and
1511c1d255d3SCy Schubert * per interface, consider the interfaces for which per
1512c1d255d3SCy Schubert * interface AKM capabilities were not received to support the
1513c1d255d3SCy Schubert * default key_mgmt capabilities.
1514c1d255d3SCy Schubert */
1515c1d255d3SCy Schubert for (i = 0; i < WPA_IF_MAX; i++)
1516c1d255d3SCy Schubert if (!drv->capa.key_mgmt_iftype[i])
1517c1d255d3SCy Schubert drv->capa.key_mgmt_iftype[i] =
1518c1d255d3SCy Schubert drv->capa.key_mgmt;
1519c1d255d3SCy Schubert }
15204bc52338SCy Schubert
15215b9c547cSRui Paulo drv->capa.auth = WPA_DRIVER_AUTH_OPEN |
15225b9c547cSRui Paulo WPA_DRIVER_AUTH_SHARED |
15235b9c547cSRui Paulo WPA_DRIVER_AUTH_LEAP;
15245b9c547cSRui Paulo
15254b72b91aSCy Schubert drv->capa.flags |= WPA_DRIVER_FLAGS_VALID_ERROR_CODES;
15265b9c547cSRui Paulo drv->capa.flags |= WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE;
15275b9c547cSRui Paulo drv->capa.flags |= WPA_DRIVER_FLAGS_EAPOL_TX_STATUS;
15285b9c547cSRui Paulo
15295b9c547cSRui Paulo /*
15305b9c547cSRui Paulo * As all cfg80211 drivers must support cases where the AP interface is
15315b9c547cSRui Paulo * removed without the knowledge of wpa_supplicant/hostapd, e.g., in
15325b9c547cSRui Paulo * case that the user space daemon has crashed, they must be able to
15335b9c547cSRui Paulo * cleanup all stations and key entries in the AP tear down flow. Thus,
15345b9c547cSRui Paulo * this flag can/should always be set for cfg80211 drivers.
15355b9c547cSRui Paulo */
15365b9c547cSRui Paulo drv->capa.flags |= WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT;
15375b9c547cSRui Paulo
15385b9c547cSRui Paulo if (!info.device_ap_sme) {
15395b9c547cSRui Paulo drv->capa.flags |= WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS;
1540c1d255d3SCy Schubert drv->capa.flags2 |= WPA_DRIVER_FLAGS2_AP_SME;
15415b9c547cSRui Paulo
15425b9c547cSRui Paulo /*
15435b9c547cSRui Paulo * No AP SME is currently assumed to also indicate no AP MLME
15445b9c547cSRui Paulo * in the driver/firmware.
15455b9c547cSRui Paulo */
15465b9c547cSRui Paulo drv->capa.flags |= WPA_DRIVER_FLAGS_AP_MLME;
15475b9c547cSRui Paulo }
15485b9c547cSRui Paulo
15495b9c547cSRui Paulo drv->device_ap_sme = info.device_ap_sme;
15505b9c547cSRui Paulo drv->poll_command_supported = info.poll_command_supported;
15515b9c547cSRui Paulo drv->data_tx_status = info.data_tx_status;
15525b9c547cSRui Paulo drv->p2p_go_ctwindow_supported = info.p2p_go_ctwindow_supported;
15535b9c547cSRui Paulo if (info.set_qos_map_supported)
15545b9c547cSRui Paulo drv->capa.flags |= WPA_DRIVER_FLAGS_QOS_MAPPING;
15555b9c547cSRui Paulo drv->have_low_prio_scan = info.have_low_prio_scan;
15565b9c547cSRui Paulo
15575b9c547cSRui Paulo /*
15585b9c547cSRui Paulo * If poll command and tx status are supported, mac80211 is new enough
15595b9c547cSRui Paulo * to have everything we need to not need monitor interfaces.
15605b9c547cSRui Paulo */
1561780fb4a2SCy Schubert drv->use_monitor = !info.device_ap_sme &&
1562780fb4a2SCy Schubert (!info.poll_command_supported || !info.data_tx_status);
15635b9c547cSRui Paulo
15645b9c547cSRui Paulo /*
15655b9c547cSRui Paulo * If we aren't going to use monitor interfaces, but the
15665b9c547cSRui Paulo * driver doesn't support data TX status, we won't get TX
15675b9c547cSRui Paulo * status for EAPOL frames.
15685b9c547cSRui Paulo */
15695b9c547cSRui Paulo if (!drv->use_monitor && !info.data_tx_status)
15705b9c547cSRui Paulo drv->capa.flags &= ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS;
15715b9c547cSRui Paulo
1572780fb4a2SCy Schubert #ifdef CONFIG_DRIVER_NL80211_QCA
157385732ac8SCy Schubert if (!(info.capa->flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD))
15745b9c547cSRui Paulo qca_nl80211_check_dfs_capa(drv);
15755b9c547cSRui Paulo qca_nl80211_get_features(drv);
15765b9c547cSRui Paulo
1577780fb4a2SCy Schubert /*
1578780fb4a2SCy Schubert * To enable offchannel simultaneous support in wpa_supplicant, the
1579780fb4a2SCy Schubert * underlying driver needs to support the same along with offchannel TX.
1580780fb4a2SCy Schubert * Offchannel TX support is needed since remain_on_channel and
1581780fb4a2SCy Schubert * action_tx use some common data structures and hence cannot be
1582780fb4a2SCy Schubert * scheduled simultaneously.
1583780fb4a2SCy Schubert */
1584780fb4a2SCy Schubert if (!(drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX))
1585780fb4a2SCy Schubert drv->capa.flags &= ~WPA_DRIVER_FLAGS_OFFCHANNEL_SIMULTANEOUS;
1586780fb4a2SCy Schubert #endif /* CONFIG_DRIVER_NL80211_QCA */
1587780fb4a2SCy Schubert
1588c1d255d3SCy Schubert wpa_printf(MSG_DEBUG,
1589*a90b9d01SCy Schubert "nl80211: key_mgmt=0x%x enc=0x%x auth=0x%x flags=0x%llx flags2=0x%llx rrm_flags=0x%x probe_resp_offloads=0x%x max_stations=%u max_remain_on_chan=%u max_scan_ssids=%d",
1590c1d255d3SCy Schubert drv->capa.key_mgmt, drv->capa.enc, drv->capa.auth,
1591*a90b9d01SCy Schubert (unsigned long long) drv->capa.flags,
1592*a90b9d01SCy Schubert (unsigned long long) drv->capa.flags2, drv->capa.rrm_flags,
1593c1d255d3SCy Schubert drv->capa.probe_resp_offloads, drv->capa.max_stations,
1594c1d255d3SCy Schubert drv->capa.max_remain_on_chan, drv->capa.max_scan_ssids);
15955b9c547cSRui Paulo return 0;
15965b9c547cSRui Paulo }
15975b9c547cSRui Paulo
15985b9c547cSRui Paulo
15995b9c547cSRui Paulo struct phy_info_arg {
16005b9c547cSRui Paulo u16 *num_modes;
16015b9c547cSRui Paulo struct hostapd_hw_modes *modes;
16025b9c547cSRui Paulo int last_mode, last_chan_idx;
1603780fb4a2SCy Schubert int failed;
160485732ac8SCy Schubert u8 dfs_domain;
16055b9c547cSRui Paulo };
16065b9c547cSRui Paulo
phy_info_ht_capa(struct hostapd_hw_modes * mode,struct nlattr * capa,struct nlattr * ampdu_factor,struct nlattr * ampdu_density,struct nlattr * mcs_set)16075b9c547cSRui Paulo static void phy_info_ht_capa(struct hostapd_hw_modes *mode, struct nlattr *capa,
16085b9c547cSRui Paulo struct nlattr *ampdu_factor,
16095b9c547cSRui Paulo struct nlattr *ampdu_density,
16105b9c547cSRui Paulo struct nlattr *mcs_set)
16115b9c547cSRui Paulo {
16125b9c547cSRui Paulo if (capa)
16135b9c547cSRui Paulo mode->ht_capab = nla_get_u16(capa);
16145b9c547cSRui Paulo
16155b9c547cSRui Paulo if (ampdu_factor)
16165b9c547cSRui Paulo mode->a_mpdu_params |= nla_get_u8(ampdu_factor) & 0x03;
16175b9c547cSRui Paulo
16185b9c547cSRui Paulo if (ampdu_density)
16195b9c547cSRui Paulo mode->a_mpdu_params |= nla_get_u8(ampdu_density) << 2;
16205b9c547cSRui Paulo
16215b9c547cSRui Paulo if (mcs_set && nla_len(mcs_set) >= 16) {
16225b9c547cSRui Paulo u8 *mcs;
16235b9c547cSRui Paulo mcs = nla_data(mcs_set);
16245b9c547cSRui Paulo os_memcpy(mode->mcs_set, mcs, 16);
16255b9c547cSRui Paulo }
16265b9c547cSRui Paulo }
16275b9c547cSRui Paulo
16285b9c547cSRui Paulo
phy_info_vht_capa(struct hostapd_hw_modes * mode,struct nlattr * capa,struct nlattr * mcs_set)16295b9c547cSRui Paulo static void phy_info_vht_capa(struct hostapd_hw_modes *mode,
16305b9c547cSRui Paulo struct nlattr *capa,
16315b9c547cSRui Paulo struct nlattr *mcs_set)
16325b9c547cSRui Paulo {
16335b9c547cSRui Paulo if (capa)
16345b9c547cSRui Paulo mode->vht_capab = nla_get_u32(capa);
16355b9c547cSRui Paulo
16365b9c547cSRui Paulo if (mcs_set && nla_len(mcs_set) >= 8) {
16375b9c547cSRui Paulo u8 *mcs;
16385b9c547cSRui Paulo mcs = nla_data(mcs_set);
16395b9c547cSRui Paulo os_memcpy(mode->vht_mcs_set, mcs, 8);
16405b9c547cSRui Paulo }
16415b9c547cSRui Paulo }
16425b9c547cSRui Paulo
16435b9c547cSRui Paulo
phy_info_edmg_capa(struct hostapd_hw_modes * mode,struct nlattr * bw_config,struct nlattr * channels)1644c1d255d3SCy Schubert static int phy_info_edmg_capa(struct hostapd_hw_modes *mode,
1645c1d255d3SCy Schubert struct nlattr *bw_config,
1646c1d255d3SCy Schubert struct nlattr *channels)
1647c1d255d3SCy Schubert {
1648c1d255d3SCy Schubert if (!bw_config || !channels)
1649c1d255d3SCy Schubert return NL_OK;
1650c1d255d3SCy Schubert
1651c1d255d3SCy Schubert mode->edmg.bw_config = nla_get_u8(bw_config);
1652c1d255d3SCy Schubert mode->edmg.channels = nla_get_u8(channels);
1653c1d255d3SCy Schubert
1654c1d255d3SCy Schubert if (!mode->edmg.channels || !mode->edmg.bw_config)
1655c1d255d3SCy Schubert return NL_STOP;
1656c1d255d3SCy Schubert
1657c1d255d3SCy Schubert return NL_OK;
1658c1d255d3SCy Schubert }
1659c1d255d3SCy Schubert
1660c1d255d3SCy Schubert
cw2ecw(unsigned int cw)1661c1d255d3SCy Schubert static int cw2ecw(unsigned int cw)
1662c1d255d3SCy Schubert {
1663c1d255d3SCy Schubert int bit;
1664c1d255d3SCy Schubert
1665c1d255d3SCy Schubert if (cw == 0)
1666c1d255d3SCy Schubert return 0;
1667c1d255d3SCy Schubert
1668c1d255d3SCy Schubert for (bit = 1; cw != 1; bit++)
1669c1d255d3SCy Schubert cw >>= 1;
1670c1d255d3SCy Schubert
1671c1d255d3SCy Schubert return bit;
1672c1d255d3SCy Schubert }
1673c1d255d3SCy Schubert
1674c1d255d3SCy Schubert
phy_info_freq(struct hostapd_hw_modes * mode,struct hostapd_channel_data * chan,struct nlattr * tb_freq[])16755b9c547cSRui Paulo static void phy_info_freq(struct hostapd_hw_modes *mode,
16765b9c547cSRui Paulo struct hostapd_channel_data *chan,
16775b9c547cSRui Paulo struct nlattr *tb_freq[])
16785b9c547cSRui Paulo {
16795b9c547cSRui Paulo u8 channel;
1680c1d255d3SCy Schubert
1681c1d255d3SCy Schubert os_memset(chan, 0, sizeof(*chan));
16825b9c547cSRui Paulo chan->freq = nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_FREQ]);
16835b9c547cSRui Paulo chan->flag = 0;
16844bc52338SCy Schubert chan->allowed_bw = ~0;
16855b9c547cSRui Paulo chan->dfs_cac_ms = 0;
16865b9c547cSRui Paulo if (ieee80211_freq_to_chan(chan->freq, &channel) != NUM_HOSTAPD_MODES)
16875b9c547cSRui Paulo chan->chan = channel;
1688c1d255d3SCy Schubert else
1689c1d255d3SCy Schubert wpa_printf(MSG_DEBUG,
1690c1d255d3SCy Schubert "nl80211: No channel number found for frequency %u MHz",
1691c1d255d3SCy Schubert chan->freq);
16925b9c547cSRui Paulo
16935b9c547cSRui Paulo if (tb_freq[NL80211_FREQUENCY_ATTR_DISABLED])
16945b9c547cSRui Paulo chan->flag |= HOSTAPD_CHAN_DISABLED;
16955b9c547cSRui Paulo if (tb_freq[NL80211_FREQUENCY_ATTR_NO_IR])
16965b9c547cSRui Paulo chan->flag |= HOSTAPD_CHAN_NO_IR;
16975b9c547cSRui Paulo if (tb_freq[NL80211_FREQUENCY_ATTR_RADAR])
16985b9c547cSRui Paulo chan->flag |= HOSTAPD_CHAN_RADAR;
16995b9c547cSRui Paulo if (tb_freq[NL80211_FREQUENCY_ATTR_INDOOR_ONLY])
17005b9c547cSRui Paulo chan->flag |= HOSTAPD_CHAN_INDOOR_ONLY;
17015b9c547cSRui Paulo if (tb_freq[NL80211_FREQUENCY_ATTR_GO_CONCURRENT])
17025b9c547cSRui Paulo chan->flag |= HOSTAPD_CHAN_GO_CONCURRENT;
17035b9c547cSRui Paulo
17044bc52338SCy Schubert if (tb_freq[NL80211_FREQUENCY_ATTR_NO_10MHZ])
17054bc52338SCy Schubert chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_10;
17064bc52338SCy Schubert if (tb_freq[NL80211_FREQUENCY_ATTR_NO_20MHZ])
17074bc52338SCy Schubert chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_20;
17084bc52338SCy Schubert if (tb_freq[NL80211_FREQUENCY_ATTR_NO_HT40_PLUS])
17094bc52338SCy Schubert chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_40P;
17104bc52338SCy Schubert if (tb_freq[NL80211_FREQUENCY_ATTR_NO_HT40_MINUS])
17114bc52338SCy Schubert chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_40M;
17124bc52338SCy Schubert if (tb_freq[NL80211_FREQUENCY_ATTR_NO_80MHZ])
17134bc52338SCy Schubert chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_80;
17144bc52338SCy Schubert if (tb_freq[NL80211_FREQUENCY_ATTR_NO_160MHZ])
17154bc52338SCy Schubert chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_160;
17164bc52338SCy Schubert
17175b9c547cSRui Paulo if (tb_freq[NL80211_FREQUENCY_ATTR_DFS_STATE]) {
17185b9c547cSRui Paulo enum nl80211_dfs_state state =
17195b9c547cSRui Paulo nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_DFS_STATE]);
17205b9c547cSRui Paulo
17215b9c547cSRui Paulo switch (state) {
17225b9c547cSRui Paulo case NL80211_DFS_USABLE:
17235b9c547cSRui Paulo chan->flag |= HOSTAPD_CHAN_DFS_USABLE;
17245b9c547cSRui Paulo break;
17255b9c547cSRui Paulo case NL80211_DFS_AVAILABLE:
17265b9c547cSRui Paulo chan->flag |= HOSTAPD_CHAN_DFS_AVAILABLE;
17275b9c547cSRui Paulo break;
17285b9c547cSRui Paulo case NL80211_DFS_UNAVAILABLE:
17295b9c547cSRui Paulo chan->flag |= HOSTAPD_CHAN_DFS_UNAVAILABLE;
17305b9c547cSRui Paulo break;
17315b9c547cSRui Paulo }
17325b9c547cSRui Paulo }
17335b9c547cSRui Paulo
17345b9c547cSRui Paulo if (tb_freq[NL80211_FREQUENCY_ATTR_DFS_CAC_TIME]) {
17355b9c547cSRui Paulo chan->dfs_cac_ms = nla_get_u32(
17365b9c547cSRui Paulo tb_freq[NL80211_FREQUENCY_ATTR_DFS_CAC_TIME]);
17375b9c547cSRui Paulo }
1738206b73d0SCy Schubert
1739206b73d0SCy Schubert chan->wmm_rules_valid = 0;
1740206b73d0SCy Schubert if (tb_freq[NL80211_FREQUENCY_ATTR_WMM]) {
1741206b73d0SCy Schubert static struct nla_policy wmm_policy[NL80211_WMMR_MAX + 1] = {
1742206b73d0SCy Schubert [NL80211_WMMR_CW_MIN] = { .type = NLA_U16 },
1743206b73d0SCy Schubert [NL80211_WMMR_CW_MAX] = { .type = NLA_U16 },
1744206b73d0SCy Schubert [NL80211_WMMR_AIFSN] = { .type = NLA_U8 },
1745206b73d0SCy Schubert [NL80211_WMMR_TXOP] = { .type = NLA_U16 },
1746206b73d0SCy Schubert };
1747c1d255d3SCy Schubert static const u8 wmm_map[4] = {
1748c1d255d3SCy Schubert [NL80211_AC_BE] = WMM_AC_BE,
1749c1d255d3SCy Schubert [NL80211_AC_BK] = WMM_AC_BK,
1750c1d255d3SCy Schubert [NL80211_AC_VI] = WMM_AC_VI,
1751c1d255d3SCy Schubert [NL80211_AC_VO] = WMM_AC_VO,
1752c1d255d3SCy Schubert };
1753206b73d0SCy Schubert struct nlattr *nl_wmm;
1754206b73d0SCy Schubert struct nlattr *tb_wmm[NL80211_WMMR_MAX + 1];
1755206b73d0SCy Schubert int rem_wmm, ac, count = 0;
1756206b73d0SCy Schubert
1757206b73d0SCy Schubert nla_for_each_nested(nl_wmm, tb_freq[NL80211_FREQUENCY_ATTR_WMM],
1758206b73d0SCy Schubert rem_wmm) {
1759206b73d0SCy Schubert if (nla_parse_nested(tb_wmm, NL80211_WMMR_MAX, nl_wmm,
1760206b73d0SCy Schubert wmm_policy)) {
1761206b73d0SCy Schubert wpa_printf(MSG_DEBUG,
1762206b73d0SCy Schubert "nl80211: Failed to parse WMM rules attribute");
1763206b73d0SCy Schubert return;
1764206b73d0SCy Schubert }
1765206b73d0SCy Schubert if (!tb_wmm[NL80211_WMMR_CW_MIN] ||
1766206b73d0SCy Schubert !tb_wmm[NL80211_WMMR_CW_MAX] ||
1767206b73d0SCy Schubert !tb_wmm[NL80211_WMMR_AIFSN] ||
1768206b73d0SCy Schubert !tb_wmm[NL80211_WMMR_TXOP]) {
1769206b73d0SCy Schubert wpa_printf(MSG_DEBUG,
1770206b73d0SCy Schubert "nl80211: Channel is missing WMM rule attribute");
1771206b73d0SCy Schubert return;
1772206b73d0SCy Schubert }
1773206b73d0SCy Schubert ac = nl_wmm->nla_type;
1774c1d255d3SCy Schubert if ((unsigned int) ac >= ARRAY_SIZE(wmm_map)) {
1775206b73d0SCy Schubert wpa_printf(MSG_DEBUG,
1776206b73d0SCy Schubert "nl80211: Invalid AC value %d", ac);
1777206b73d0SCy Schubert return;
1778206b73d0SCy Schubert }
1779206b73d0SCy Schubert
1780c1d255d3SCy Schubert ac = wmm_map[ac];
1781206b73d0SCy Schubert chan->wmm_rules[ac].min_cwmin =
1782c1d255d3SCy Schubert cw2ecw(nla_get_u16(
1783c1d255d3SCy Schubert tb_wmm[NL80211_WMMR_CW_MIN]));
1784206b73d0SCy Schubert chan->wmm_rules[ac].min_cwmax =
1785c1d255d3SCy Schubert cw2ecw(nla_get_u16(
1786c1d255d3SCy Schubert tb_wmm[NL80211_WMMR_CW_MAX]));
1787206b73d0SCy Schubert chan->wmm_rules[ac].min_aifs =
1788206b73d0SCy Schubert nla_get_u8(tb_wmm[NL80211_WMMR_AIFSN]);
1789206b73d0SCy Schubert chan->wmm_rules[ac].max_txop =
1790206b73d0SCy Schubert nla_get_u16(tb_wmm[NL80211_WMMR_TXOP]) / 32;
1791206b73d0SCy Schubert count++;
1792206b73d0SCy Schubert }
1793206b73d0SCy Schubert
1794206b73d0SCy Schubert /* Set valid flag if all the AC rules are present */
1795206b73d0SCy Schubert if (count == WMM_AC_NUM)
1796206b73d0SCy Schubert chan->wmm_rules_valid = 1;
1797206b73d0SCy Schubert }
17985b9c547cSRui Paulo }
17995b9c547cSRui Paulo
18005b9c547cSRui Paulo
phy_info_freqs(struct phy_info_arg * phy_info,struct hostapd_hw_modes * mode,struct nlattr * tb)18015b9c547cSRui Paulo static int phy_info_freqs(struct phy_info_arg *phy_info,
18025b9c547cSRui Paulo struct hostapd_hw_modes *mode, struct nlattr *tb)
18035b9c547cSRui Paulo {
18045b9c547cSRui Paulo static struct nla_policy freq_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = {
18055b9c547cSRui Paulo [NL80211_FREQUENCY_ATTR_FREQ] = { .type = NLA_U32 },
18065b9c547cSRui Paulo [NL80211_FREQUENCY_ATTR_DISABLED] = { .type = NLA_FLAG },
18075b9c547cSRui Paulo [NL80211_FREQUENCY_ATTR_NO_IR] = { .type = NLA_FLAG },
18085b9c547cSRui Paulo [NL80211_FREQUENCY_ATTR_RADAR] = { .type = NLA_FLAG },
18095b9c547cSRui Paulo [NL80211_FREQUENCY_ATTR_MAX_TX_POWER] = { .type = NLA_U32 },
18105b9c547cSRui Paulo [NL80211_FREQUENCY_ATTR_DFS_STATE] = { .type = NLA_U32 },
18114bc52338SCy Schubert [NL80211_FREQUENCY_ATTR_NO_10MHZ] = { .type = NLA_FLAG },
18124bc52338SCy Schubert [NL80211_FREQUENCY_ATTR_NO_20MHZ] = { .type = NLA_FLAG },
18134bc52338SCy Schubert [NL80211_FREQUENCY_ATTR_NO_HT40_PLUS] = { .type = NLA_FLAG },
18144bc52338SCy Schubert [NL80211_FREQUENCY_ATTR_NO_HT40_MINUS] = { .type = NLA_FLAG },
18154bc52338SCy Schubert [NL80211_FREQUENCY_ATTR_NO_80MHZ] = { .type = NLA_FLAG },
18164bc52338SCy Schubert [NL80211_FREQUENCY_ATTR_NO_160MHZ] = { .type = NLA_FLAG },
18175b9c547cSRui Paulo };
18185b9c547cSRui Paulo int new_channels = 0;
18195b9c547cSRui Paulo struct hostapd_channel_data *channel;
18205b9c547cSRui Paulo struct nlattr *tb_freq[NL80211_FREQUENCY_ATTR_MAX + 1];
18215b9c547cSRui Paulo struct nlattr *nl_freq;
18225b9c547cSRui Paulo int rem_freq, idx;
18235b9c547cSRui Paulo
18245b9c547cSRui Paulo if (tb == NULL)
18255b9c547cSRui Paulo return NL_OK;
18265b9c547cSRui Paulo
18275b9c547cSRui Paulo nla_for_each_nested(nl_freq, tb, rem_freq) {
18285b9c547cSRui Paulo nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX,
18295b9c547cSRui Paulo nla_data(nl_freq), nla_len(nl_freq), freq_policy);
18305b9c547cSRui Paulo if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ])
18315b9c547cSRui Paulo continue;
18325b9c547cSRui Paulo new_channels++;
18335b9c547cSRui Paulo }
18345b9c547cSRui Paulo
18355b9c547cSRui Paulo channel = os_realloc_array(mode->channels,
18365b9c547cSRui Paulo mode->num_channels + new_channels,
18375b9c547cSRui Paulo sizeof(struct hostapd_channel_data));
18385b9c547cSRui Paulo if (!channel)
1839780fb4a2SCy Schubert return NL_STOP;
18405b9c547cSRui Paulo
18415b9c547cSRui Paulo mode->channels = channel;
18425b9c547cSRui Paulo mode->num_channels += new_channels;
18435b9c547cSRui Paulo
18445b9c547cSRui Paulo idx = phy_info->last_chan_idx;
18455b9c547cSRui Paulo
18465b9c547cSRui Paulo nla_for_each_nested(nl_freq, tb, rem_freq) {
18475b9c547cSRui Paulo nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX,
18485b9c547cSRui Paulo nla_data(nl_freq), nla_len(nl_freq), freq_policy);
18495b9c547cSRui Paulo if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ])
18505b9c547cSRui Paulo continue;
18515b9c547cSRui Paulo phy_info_freq(mode, &mode->channels[idx], tb_freq);
18525b9c547cSRui Paulo idx++;
18535b9c547cSRui Paulo }
18545b9c547cSRui Paulo phy_info->last_chan_idx = idx;
18555b9c547cSRui Paulo
18565b9c547cSRui Paulo return NL_OK;
18575b9c547cSRui Paulo }
18585b9c547cSRui Paulo
18595b9c547cSRui Paulo
phy_info_rates(struct hostapd_hw_modes * mode,struct nlattr * tb)18605b9c547cSRui Paulo static int phy_info_rates(struct hostapd_hw_modes *mode, struct nlattr *tb)
18615b9c547cSRui Paulo {
18625b9c547cSRui Paulo static struct nla_policy rate_policy[NL80211_BITRATE_ATTR_MAX + 1] = {
18635b9c547cSRui Paulo [NL80211_BITRATE_ATTR_RATE] = { .type = NLA_U32 },
18645b9c547cSRui Paulo [NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE] =
18655b9c547cSRui Paulo { .type = NLA_FLAG },
18665b9c547cSRui Paulo };
18675b9c547cSRui Paulo struct nlattr *tb_rate[NL80211_BITRATE_ATTR_MAX + 1];
18685b9c547cSRui Paulo struct nlattr *nl_rate;
18695b9c547cSRui Paulo int rem_rate, idx;
18705b9c547cSRui Paulo
18715b9c547cSRui Paulo if (tb == NULL)
18725b9c547cSRui Paulo return NL_OK;
18735b9c547cSRui Paulo
18745b9c547cSRui Paulo nla_for_each_nested(nl_rate, tb, rem_rate) {
18755b9c547cSRui Paulo nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX,
18765b9c547cSRui Paulo nla_data(nl_rate), nla_len(nl_rate),
18775b9c547cSRui Paulo rate_policy);
18785b9c547cSRui Paulo if (!tb_rate[NL80211_BITRATE_ATTR_RATE])
18795b9c547cSRui Paulo continue;
18805b9c547cSRui Paulo mode->num_rates++;
18815b9c547cSRui Paulo }
18825b9c547cSRui Paulo
18835b9c547cSRui Paulo mode->rates = os_calloc(mode->num_rates, sizeof(int));
18845b9c547cSRui Paulo if (!mode->rates)
1885780fb4a2SCy Schubert return NL_STOP;
18865b9c547cSRui Paulo
18875b9c547cSRui Paulo idx = 0;
18885b9c547cSRui Paulo
18895b9c547cSRui Paulo nla_for_each_nested(nl_rate, tb, rem_rate) {
18905b9c547cSRui Paulo nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX,
18915b9c547cSRui Paulo nla_data(nl_rate), nla_len(nl_rate),
18925b9c547cSRui Paulo rate_policy);
18935b9c547cSRui Paulo if (!tb_rate[NL80211_BITRATE_ATTR_RATE])
18945b9c547cSRui Paulo continue;
18955b9c547cSRui Paulo mode->rates[idx] = nla_get_u32(
18965b9c547cSRui Paulo tb_rate[NL80211_BITRATE_ATTR_RATE]);
18975b9c547cSRui Paulo idx++;
18985b9c547cSRui Paulo }
18995b9c547cSRui Paulo
19005b9c547cSRui Paulo return NL_OK;
19015b9c547cSRui Paulo }
19025b9c547cSRui Paulo
19035b9c547cSRui Paulo
phy_info_iftype_copy(struct hostapd_hw_modes * mode,enum ieee80211_op_mode opmode,struct nlattr ** tb,struct nlattr ** tb_flags)1904*a90b9d01SCy Schubert static void phy_info_iftype_copy(struct hostapd_hw_modes *mode,
1905206b73d0SCy Schubert enum ieee80211_op_mode opmode,
1906206b73d0SCy Schubert struct nlattr **tb, struct nlattr **tb_flags)
1907206b73d0SCy Schubert {
1908206b73d0SCy Schubert enum nl80211_iftype iftype;
1909206b73d0SCy Schubert size_t len;
1910*a90b9d01SCy Schubert struct he_capabilities *he_capab = &mode->he_capab[opmode];
1911*a90b9d01SCy Schubert struct eht_capabilities *eht_capab = &mode->eht_capab[opmode];
1912206b73d0SCy Schubert
1913206b73d0SCy Schubert switch (opmode) {
1914206b73d0SCy Schubert case IEEE80211_MODE_INFRA:
1915206b73d0SCy Schubert iftype = NL80211_IFTYPE_STATION;
1916206b73d0SCy Schubert break;
1917206b73d0SCy Schubert case IEEE80211_MODE_IBSS:
1918206b73d0SCy Schubert iftype = NL80211_IFTYPE_ADHOC;
1919206b73d0SCy Schubert break;
1920206b73d0SCy Schubert case IEEE80211_MODE_AP:
1921206b73d0SCy Schubert iftype = NL80211_IFTYPE_AP;
1922206b73d0SCy Schubert break;
1923206b73d0SCy Schubert case IEEE80211_MODE_MESH:
1924206b73d0SCy Schubert iftype = NL80211_IFTYPE_MESH_POINT;
1925206b73d0SCy Schubert break;
1926206b73d0SCy Schubert default:
1927206b73d0SCy Schubert return;
1928206b73d0SCy Schubert }
1929206b73d0SCy Schubert
1930206b73d0SCy Schubert if (!nla_get_flag(tb_flags[iftype]))
1931206b73d0SCy Schubert return;
1932206b73d0SCy Schubert
1933206b73d0SCy Schubert he_capab->he_supported = 1;
1934206b73d0SCy Schubert
1935206b73d0SCy Schubert if (tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY]) {
1936206b73d0SCy Schubert len = nla_len(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY]);
1937206b73d0SCy Schubert
1938206b73d0SCy Schubert if (len > sizeof(he_capab->phy_cap))
1939206b73d0SCy Schubert len = sizeof(he_capab->phy_cap);
1940206b73d0SCy Schubert os_memcpy(he_capab->phy_cap,
1941206b73d0SCy Schubert nla_data(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY]),
1942206b73d0SCy Schubert len);
1943206b73d0SCy Schubert }
1944206b73d0SCy Schubert
1945206b73d0SCy Schubert if (tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC]) {
1946206b73d0SCy Schubert len = nla_len(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC]);
1947206b73d0SCy Schubert
1948206b73d0SCy Schubert if (len > sizeof(he_capab->mac_cap))
1949206b73d0SCy Schubert len = sizeof(he_capab->mac_cap);
1950206b73d0SCy Schubert os_memcpy(he_capab->mac_cap,
1951206b73d0SCy Schubert nla_data(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC]),
1952206b73d0SCy Schubert len);
1953206b73d0SCy Schubert }
1954206b73d0SCy Schubert
1955206b73d0SCy Schubert if (tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET]) {
1956206b73d0SCy Schubert len = nla_len(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET]);
1957206b73d0SCy Schubert
1958206b73d0SCy Schubert if (len > sizeof(he_capab->mcs))
1959206b73d0SCy Schubert len = sizeof(he_capab->mcs);
1960206b73d0SCy Schubert os_memcpy(he_capab->mcs,
1961206b73d0SCy Schubert nla_data(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET]),
1962206b73d0SCy Schubert len);
1963206b73d0SCy Schubert }
1964206b73d0SCy Schubert
1965206b73d0SCy Schubert if (tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE]) {
1966206b73d0SCy Schubert len = nla_len(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE]);
1967206b73d0SCy Schubert
1968206b73d0SCy Schubert if (len > sizeof(he_capab->ppet))
1969206b73d0SCy Schubert len = sizeof(he_capab->ppet);
1970206b73d0SCy Schubert os_memcpy(&he_capab->ppet,
1971206b73d0SCy Schubert nla_data(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE]),
1972206b73d0SCy Schubert len);
1973206b73d0SCy Schubert }
1974c1d255d3SCy Schubert
1975c1d255d3SCy Schubert if (tb[NL80211_BAND_IFTYPE_ATTR_HE_6GHZ_CAPA]) {
1976c1d255d3SCy Schubert u16 capa;
1977c1d255d3SCy Schubert
1978c1d255d3SCy Schubert capa = nla_get_u16(tb[NL80211_BAND_IFTYPE_ATTR_HE_6GHZ_CAPA]);
1979c1d255d3SCy Schubert he_capab->he_6ghz_capa = le_to_host16(capa);
1980c1d255d3SCy Schubert }
1981*a90b9d01SCy Schubert
1982*a90b9d01SCy Schubert if (!tb[NL80211_BAND_IFTYPE_ATTR_EHT_CAP_MAC] ||
1983*a90b9d01SCy Schubert !tb[NL80211_BAND_IFTYPE_ATTR_EHT_CAP_PHY])
1984*a90b9d01SCy Schubert return;
1985*a90b9d01SCy Schubert
1986*a90b9d01SCy Schubert eht_capab->eht_supported = true;
1987*a90b9d01SCy Schubert
1988*a90b9d01SCy Schubert if (tb[NL80211_BAND_IFTYPE_ATTR_EHT_CAP_MAC] &&
1989*a90b9d01SCy Schubert nla_len(tb[NL80211_BAND_IFTYPE_ATTR_EHT_CAP_MAC]) >= 2) {
1990*a90b9d01SCy Schubert const u8 *pos;
1991*a90b9d01SCy Schubert
1992*a90b9d01SCy Schubert pos = nla_data(tb[NL80211_BAND_IFTYPE_ATTR_EHT_CAP_MAC]);
1993*a90b9d01SCy Schubert eht_capab->mac_cap = WPA_GET_LE16(pos);
1994*a90b9d01SCy Schubert }
1995*a90b9d01SCy Schubert
1996*a90b9d01SCy Schubert if (tb[NL80211_BAND_IFTYPE_ATTR_EHT_CAP_PHY]) {
1997*a90b9d01SCy Schubert len = nla_len(tb[NL80211_BAND_IFTYPE_ATTR_EHT_CAP_PHY]);
1998*a90b9d01SCy Schubert if (len > sizeof(eht_capab->phy_cap))
1999*a90b9d01SCy Schubert len = sizeof(eht_capab->phy_cap);
2000*a90b9d01SCy Schubert os_memcpy(eht_capab->phy_cap,
2001*a90b9d01SCy Schubert nla_data(tb[NL80211_BAND_IFTYPE_ATTR_EHT_CAP_PHY]),
2002*a90b9d01SCy Schubert len);
2003*a90b9d01SCy Schubert }
2004*a90b9d01SCy Schubert
2005*a90b9d01SCy Schubert if (tb[NL80211_BAND_IFTYPE_ATTR_EHT_CAP_MCS_SET]) {
2006*a90b9d01SCy Schubert len = nla_len(tb[NL80211_BAND_IFTYPE_ATTR_EHT_CAP_MCS_SET]);
2007*a90b9d01SCy Schubert if (len > sizeof(eht_capab->mcs))
2008*a90b9d01SCy Schubert len = sizeof(eht_capab->mcs);
2009*a90b9d01SCy Schubert os_memcpy(eht_capab->mcs,
2010*a90b9d01SCy Schubert nla_data(tb[NL80211_BAND_IFTYPE_ATTR_EHT_CAP_MCS_SET]),
2011*a90b9d01SCy Schubert len);
2012*a90b9d01SCy Schubert }
2013*a90b9d01SCy Schubert
2014*a90b9d01SCy Schubert if (tb[NL80211_BAND_IFTYPE_ATTR_EHT_CAP_PPE]) {
2015*a90b9d01SCy Schubert len = nla_len(tb[NL80211_BAND_IFTYPE_ATTR_EHT_CAP_PPE]);
2016*a90b9d01SCy Schubert if (len > sizeof(eht_capab->ppet))
2017*a90b9d01SCy Schubert len = sizeof(eht_capab->ppet);
2018*a90b9d01SCy Schubert os_memcpy(&eht_capab->ppet,
2019*a90b9d01SCy Schubert nla_data(tb[NL80211_BAND_IFTYPE_ATTR_EHT_CAP_PPE]),
2020*a90b9d01SCy Schubert len);
2021*a90b9d01SCy Schubert }
2022206b73d0SCy Schubert }
2023206b73d0SCy Schubert
2024206b73d0SCy Schubert
phy_info_iftype(struct hostapd_hw_modes * mode,struct nlattr * nl_iftype)2025206b73d0SCy Schubert static int phy_info_iftype(struct hostapd_hw_modes *mode,
2026206b73d0SCy Schubert struct nlattr *nl_iftype)
2027206b73d0SCy Schubert {
2028206b73d0SCy Schubert struct nlattr *tb[NL80211_BAND_IFTYPE_ATTR_MAX + 1];
2029206b73d0SCy Schubert struct nlattr *tb_flags[NL80211_IFTYPE_MAX + 1];
2030206b73d0SCy Schubert unsigned int i;
2031206b73d0SCy Schubert
2032206b73d0SCy Schubert nla_parse(tb, NL80211_BAND_IFTYPE_ATTR_MAX,
2033206b73d0SCy Schubert nla_data(nl_iftype), nla_len(nl_iftype), NULL);
2034206b73d0SCy Schubert
2035206b73d0SCy Schubert if (!tb[NL80211_BAND_IFTYPE_ATTR_IFTYPES])
2036206b73d0SCy Schubert return NL_STOP;
2037206b73d0SCy Schubert
2038206b73d0SCy Schubert if (nla_parse_nested(tb_flags, NL80211_IFTYPE_MAX,
2039206b73d0SCy Schubert tb[NL80211_BAND_IFTYPE_ATTR_IFTYPES], NULL))
2040206b73d0SCy Schubert return NL_STOP;
2041206b73d0SCy Schubert
2042206b73d0SCy Schubert for (i = 0; i < IEEE80211_MODE_NUM; i++)
2043*a90b9d01SCy Schubert phy_info_iftype_copy(mode, i, tb, tb_flags);
2044206b73d0SCy Schubert
2045206b73d0SCy Schubert return NL_OK;
2046206b73d0SCy Schubert }
2047206b73d0SCy Schubert
2048206b73d0SCy Schubert
phy_info_band(struct phy_info_arg * phy_info,struct nlattr * nl_band)20495b9c547cSRui Paulo static int phy_info_band(struct phy_info_arg *phy_info, struct nlattr *nl_band)
20505b9c547cSRui Paulo {
20515b9c547cSRui Paulo struct nlattr *tb_band[NL80211_BAND_ATTR_MAX + 1];
20525b9c547cSRui Paulo struct hostapd_hw_modes *mode;
20535b9c547cSRui Paulo int ret;
20545b9c547cSRui Paulo
20555b9c547cSRui Paulo if (phy_info->last_mode != nl_band->nla_type) {
20565b9c547cSRui Paulo mode = os_realloc_array(phy_info->modes,
20575b9c547cSRui Paulo *phy_info->num_modes + 1,
20585b9c547cSRui Paulo sizeof(*mode));
2059780fb4a2SCy Schubert if (!mode) {
2060780fb4a2SCy Schubert phy_info->failed = 1;
2061780fb4a2SCy Schubert return NL_STOP;
2062780fb4a2SCy Schubert }
20635b9c547cSRui Paulo phy_info->modes = mode;
20645b9c547cSRui Paulo
20655b9c547cSRui Paulo mode = &phy_info->modes[*(phy_info->num_modes)];
20665b9c547cSRui Paulo os_memset(mode, 0, sizeof(*mode));
20675b9c547cSRui Paulo mode->mode = NUM_HOSTAPD_MODES;
20685b9c547cSRui Paulo mode->flags = HOSTAPD_MODE_FLAG_HT_INFO_KNOWN |
2069*a90b9d01SCy Schubert HOSTAPD_MODE_FLAG_VHT_INFO_KNOWN |
2070*a90b9d01SCy Schubert HOSTAPD_MODE_FLAG_HE_INFO_KNOWN;
20715b9c547cSRui Paulo
20725b9c547cSRui Paulo /*
20735b9c547cSRui Paulo * Unsupported VHT MCS stream is defined as value 3, so the VHT
20745b9c547cSRui Paulo * MCS RX/TX map must be initialized with 0xffff to mark all 8
20755b9c547cSRui Paulo * possible streams as unsupported. This will be overridden if
20765b9c547cSRui Paulo * driver advertises VHT support.
20775b9c547cSRui Paulo */
20785b9c547cSRui Paulo mode->vht_mcs_set[0] = 0xff;
20795b9c547cSRui Paulo mode->vht_mcs_set[1] = 0xff;
20805b9c547cSRui Paulo mode->vht_mcs_set[4] = 0xff;
20815b9c547cSRui Paulo mode->vht_mcs_set[5] = 0xff;
20825b9c547cSRui Paulo
20835b9c547cSRui Paulo *(phy_info->num_modes) += 1;
20845b9c547cSRui Paulo phy_info->last_mode = nl_band->nla_type;
20855b9c547cSRui Paulo phy_info->last_chan_idx = 0;
20865b9c547cSRui Paulo } else
20875b9c547cSRui Paulo mode = &phy_info->modes[*(phy_info->num_modes) - 1];
20885b9c547cSRui Paulo
20895b9c547cSRui Paulo nla_parse(tb_band, NL80211_BAND_ATTR_MAX, nla_data(nl_band),
20905b9c547cSRui Paulo nla_len(nl_band), NULL);
20915b9c547cSRui Paulo
20925b9c547cSRui Paulo phy_info_ht_capa(mode, tb_band[NL80211_BAND_ATTR_HT_CAPA],
20935b9c547cSRui Paulo tb_band[NL80211_BAND_ATTR_HT_AMPDU_FACTOR],
20945b9c547cSRui Paulo tb_band[NL80211_BAND_ATTR_HT_AMPDU_DENSITY],
20955b9c547cSRui Paulo tb_band[NL80211_BAND_ATTR_HT_MCS_SET]);
20965b9c547cSRui Paulo phy_info_vht_capa(mode, tb_band[NL80211_BAND_ATTR_VHT_CAPA],
20975b9c547cSRui Paulo tb_band[NL80211_BAND_ATTR_VHT_MCS_SET]);
2098c1d255d3SCy Schubert ret = phy_info_edmg_capa(mode,
2099c1d255d3SCy Schubert tb_band[NL80211_BAND_ATTR_EDMG_BW_CONFIG],
2100c1d255d3SCy Schubert tb_band[NL80211_BAND_ATTR_EDMG_CHANNELS]);
2101c1d255d3SCy Schubert if (ret == NL_OK)
2102c1d255d3SCy Schubert ret = phy_info_freqs(phy_info, mode,
2103c1d255d3SCy Schubert tb_band[NL80211_BAND_ATTR_FREQS]);
2104780fb4a2SCy Schubert if (ret == NL_OK)
21055b9c547cSRui Paulo ret = phy_info_rates(mode, tb_band[NL80211_BAND_ATTR_RATES]);
2106780fb4a2SCy Schubert if (ret != NL_OK) {
2107780fb4a2SCy Schubert phy_info->failed = 1;
21085b9c547cSRui Paulo return ret;
2109780fb4a2SCy Schubert }
21105b9c547cSRui Paulo
2111206b73d0SCy Schubert if (tb_band[NL80211_BAND_ATTR_IFTYPE_DATA]) {
2112206b73d0SCy Schubert struct nlattr *nl_iftype;
2113206b73d0SCy Schubert int rem_band;
2114206b73d0SCy Schubert
2115206b73d0SCy Schubert nla_for_each_nested(nl_iftype,
2116206b73d0SCy Schubert tb_band[NL80211_BAND_ATTR_IFTYPE_DATA],
2117206b73d0SCy Schubert rem_band) {
2118206b73d0SCy Schubert ret = phy_info_iftype(mode, nl_iftype);
2119206b73d0SCy Schubert if (ret != NL_OK)
2120206b73d0SCy Schubert return ret;
2121206b73d0SCy Schubert }
2122206b73d0SCy Schubert }
2123206b73d0SCy Schubert
21245b9c547cSRui Paulo return NL_OK;
21255b9c547cSRui Paulo }
21265b9c547cSRui Paulo
21275b9c547cSRui Paulo
phy_info_handler(struct nl_msg * msg,void * arg)21285b9c547cSRui Paulo static int phy_info_handler(struct nl_msg *msg, void *arg)
21295b9c547cSRui Paulo {
21305b9c547cSRui Paulo struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
21315b9c547cSRui Paulo struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
21325b9c547cSRui Paulo struct phy_info_arg *phy_info = arg;
21335b9c547cSRui Paulo struct nlattr *nl_band;
21345b9c547cSRui Paulo int rem_band;
21355b9c547cSRui Paulo
21365b9c547cSRui Paulo nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
21375b9c547cSRui Paulo genlmsg_attrlen(gnlh, 0), NULL);
21385b9c547cSRui Paulo
21395b9c547cSRui Paulo if (!tb_msg[NL80211_ATTR_WIPHY_BANDS])
21405b9c547cSRui Paulo return NL_SKIP;
21415b9c547cSRui Paulo
21425b9c547cSRui Paulo nla_for_each_nested(nl_band, tb_msg[NL80211_ATTR_WIPHY_BANDS], rem_band)
21435b9c547cSRui Paulo {
21445b9c547cSRui Paulo int res = phy_info_band(phy_info, nl_band);
21455b9c547cSRui Paulo if (res != NL_OK)
21465b9c547cSRui Paulo return res;
21475b9c547cSRui Paulo }
21485b9c547cSRui Paulo
21495b9c547cSRui Paulo return NL_SKIP;
21505b9c547cSRui Paulo }
21515b9c547cSRui Paulo
21525b9c547cSRui Paulo
21535b9c547cSRui Paulo static struct hostapd_hw_modes *
wpa_driver_nl80211_postprocess_modes(struct hostapd_hw_modes * modes,u16 * num_modes)21545b9c547cSRui Paulo wpa_driver_nl80211_postprocess_modes(struct hostapd_hw_modes *modes,
21555b9c547cSRui Paulo u16 *num_modes)
21565b9c547cSRui Paulo {
21575b9c547cSRui Paulo u16 m;
21585b9c547cSRui Paulo struct hostapd_hw_modes *mode11g = NULL, *nmodes, *mode;
21595b9c547cSRui Paulo int i, mode11g_idx = -1;
21605b9c547cSRui Paulo
21615b9c547cSRui Paulo /* heuristic to set up modes */
21625b9c547cSRui Paulo for (m = 0; m < *num_modes; m++) {
21635b9c547cSRui Paulo if (!modes[m].num_channels)
21645b9c547cSRui Paulo continue;
2165*a90b9d01SCy Schubert
2166*a90b9d01SCy Schubert modes[m].is_6ghz = false;
2167*a90b9d01SCy Schubert
2168c1d255d3SCy Schubert if (modes[m].channels[0].freq < 2000) {
2169c1d255d3SCy Schubert modes[m].num_channels = 0;
2170c1d255d3SCy Schubert continue;
2171c1d255d3SCy Schubert } else if (modes[m].channels[0].freq < 4000) {
21725b9c547cSRui Paulo modes[m].mode = HOSTAPD_MODE_IEEE80211B;
21735b9c547cSRui Paulo for (i = 0; i < modes[m].num_rates; i++) {
21745b9c547cSRui Paulo if (modes[m].rates[i] > 200) {
21755b9c547cSRui Paulo modes[m].mode = HOSTAPD_MODE_IEEE80211G;
21765b9c547cSRui Paulo break;
21775b9c547cSRui Paulo }
21785b9c547cSRui Paulo }
2179*a90b9d01SCy Schubert } else if (modes[m].channels[0].freq > 50000) {
21805b9c547cSRui Paulo modes[m].mode = HOSTAPD_MODE_IEEE80211AD;
2181*a90b9d01SCy Schubert } else if (is_6ghz_freq(modes[m].channels[0].freq)) {
21825b9c547cSRui Paulo modes[m].mode = HOSTAPD_MODE_IEEE80211A;
2183*a90b9d01SCy Schubert modes[m].is_6ghz = true;
2184*a90b9d01SCy Schubert } else {
2185*a90b9d01SCy Schubert modes[m].mode = HOSTAPD_MODE_IEEE80211A;
2186*a90b9d01SCy Schubert }
21875b9c547cSRui Paulo }
21885b9c547cSRui Paulo
2189c1d255d3SCy Schubert /* Remove unsupported bands */
2190c1d255d3SCy Schubert m = 0;
2191c1d255d3SCy Schubert while (m < *num_modes) {
2192c1d255d3SCy Schubert if (modes[m].mode == NUM_HOSTAPD_MODES) {
2193c1d255d3SCy Schubert wpa_printf(MSG_DEBUG,
2194c1d255d3SCy Schubert "nl80211: Remove unsupported mode");
2195c1d255d3SCy Schubert os_free(modes[m].channels);
2196c1d255d3SCy Schubert os_free(modes[m].rates);
2197c1d255d3SCy Schubert if (m + 1 < *num_modes)
2198c1d255d3SCy Schubert os_memmove(&modes[m], &modes[m + 1],
2199c1d255d3SCy Schubert sizeof(struct hostapd_hw_modes) *
2200c1d255d3SCy Schubert (*num_modes - (m + 1)));
2201c1d255d3SCy Schubert (*num_modes)--;
2202c1d255d3SCy Schubert continue;
2203c1d255d3SCy Schubert }
2204c1d255d3SCy Schubert m++;
2205c1d255d3SCy Schubert }
2206c1d255d3SCy Schubert
22075b9c547cSRui Paulo /* If only 802.11g mode is included, use it to construct matching
22085b9c547cSRui Paulo * 802.11b mode data. */
22095b9c547cSRui Paulo
22105b9c547cSRui Paulo for (m = 0; m < *num_modes; m++) {
22115b9c547cSRui Paulo if (modes[m].mode == HOSTAPD_MODE_IEEE80211B)
22125b9c547cSRui Paulo return modes; /* 802.11b already included */
22135b9c547cSRui Paulo if (modes[m].mode == HOSTAPD_MODE_IEEE80211G)
22145b9c547cSRui Paulo mode11g_idx = m;
22155b9c547cSRui Paulo }
22165b9c547cSRui Paulo
22175b9c547cSRui Paulo if (mode11g_idx < 0)
22185b9c547cSRui Paulo return modes; /* 2.4 GHz band not supported at all */
22195b9c547cSRui Paulo
22205b9c547cSRui Paulo nmodes = os_realloc_array(modes, *num_modes + 1, sizeof(*nmodes));
22215b9c547cSRui Paulo if (nmodes == NULL)
22225b9c547cSRui Paulo return modes; /* Could not add 802.11b mode */
22235b9c547cSRui Paulo
22245b9c547cSRui Paulo mode = &nmodes[*num_modes];
22255b9c547cSRui Paulo os_memset(mode, 0, sizeof(*mode));
22265b9c547cSRui Paulo (*num_modes)++;
22275b9c547cSRui Paulo modes = nmodes;
22285b9c547cSRui Paulo
22295b9c547cSRui Paulo mode->mode = HOSTAPD_MODE_IEEE80211B;
22305b9c547cSRui Paulo
22315b9c547cSRui Paulo mode11g = &modes[mode11g_idx];
22325b9c547cSRui Paulo mode->num_channels = mode11g->num_channels;
223385732ac8SCy Schubert mode->channels = os_memdup(mode11g->channels,
223485732ac8SCy Schubert mode11g->num_channels *
22355b9c547cSRui Paulo sizeof(struct hostapd_channel_data));
22365b9c547cSRui Paulo if (mode->channels == NULL) {
22375b9c547cSRui Paulo (*num_modes)--;
22385b9c547cSRui Paulo return modes; /* Could not add 802.11b mode */
22395b9c547cSRui Paulo }
22405b9c547cSRui Paulo
22415b9c547cSRui Paulo mode->num_rates = 0;
22425b9c547cSRui Paulo mode->rates = os_malloc(4 * sizeof(int));
22435b9c547cSRui Paulo if (mode->rates == NULL) {
22445b9c547cSRui Paulo os_free(mode->channels);
22455b9c547cSRui Paulo (*num_modes)--;
22465b9c547cSRui Paulo return modes; /* Could not add 802.11b mode */
22475b9c547cSRui Paulo }
22485b9c547cSRui Paulo
22495b9c547cSRui Paulo for (i = 0; i < mode11g->num_rates; i++) {
22505b9c547cSRui Paulo if (mode11g->rates[i] != 10 && mode11g->rates[i] != 20 &&
22515b9c547cSRui Paulo mode11g->rates[i] != 55 && mode11g->rates[i] != 110)
22525b9c547cSRui Paulo continue;
22535b9c547cSRui Paulo mode->rates[mode->num_rates] = mode11g->rates[i];
22545b9c547cSRui Paulo mode->num_rates++;
22555b9c547cSRui Paulo if (mode->num_rates == 4)
22565b9c547cSRui Paulo break;
22575b9c547cSRui Paulo }
22585b9c547cSRui Paulo
22595b9c547cSRui Paulo if (mode->num_rates == 0) {
22605b9c547cSRui Paulo os_free(mode->channels);
22615b9c547cSRui Paulo os_free(mode->rates);
22625b9c547cSRui Paulo (*num_modes)--;
22635b9c547cSRui Paulo return modes; /* No 802.11b rates */
22645b9c547cSRui Paulo }
22655b9c547cSRui Paulo
22665b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "nl80211: Added 802.11b mode based on 802.11g "
22675b9c547cSRui Paulo "information");
22685b9c547cSRui Paulo
22695b9c547cSRui Paulo return modes;
22705b9c547cSRui Paulo }
22715b9c547cSRui Paulo
22725b9c547cSRui Paulo
nl80211_set_ht40_mode(struct hostapd_hw_modes * mode,int start,int end)22735b9c547cSRui Paulo static void nl80211_set_ht40_mode(struct hostapd_hw_modes *mode, int start,
22745b9c547cSRui Paulo int end)
22755b9c547cSRui Paulo {
22765b9c547cSRui Paulo int c;
22775b9c547cSRui Paulo
22785b9c547cSRui Paulo for (c = 0; c < mode->num_channels; c++) {
22795b9c547cSRui Paulo struct hostapd_channel_data *chan = &mode->channels[c];
22805b9c547cSRui Paulo if (chan->freq - 10 >= start && chan->freq + 10 <= end)
22815b9c547cSRui Paulo chan->flag |= HOSTAPD_CHAN_HT40;
22825b9c547cSRui Paulo }
22835b9c547cSRui Paulo }
22845b9c547cSRui Paulo
22855b9c547cSRui Paulo
nl80211_set_ht40_mode_sec(struct hostapd_hw_modes * mode,int start,int end)22865b9c547cSRui Paulo static void nl80211_set_ht40_mode_sec(struct hostapd_hw_modes *mode, int start,
22875b9c547cSRui Paulo int end)
22885b9c547cSRui Paulo {
22895b9c547cSRui Paulo int c;
22905b9c547cSRui Paulo
22915b9c547cSRui Paulo for (c = 0; c < mode->num_channels; c++) {
22925b9c547cSRui Paulo struct hostapd_channel_data *chan = &mode->channels[c];
22935b9c547cSRui Paulo if (!(chan->flag & HOSTAPD_CHAN_HT40))
22945b9c547cSRui Paulo continue;
22955b9c547cSRui Paulo if (chan->freq - 30 >= start && chan->freq - 10 <= end)
22965b9c547cSRui Paulo chan->flag |= HOSTAPD_CHAN_HT40MINUS;
22975b9c547cSRui Paulo if (chan->freq + 10 >= start && chan->freq + 30 <= end)
22985b9c547cSRui Paulo chan->flag |= HOSTAPD_CHAN_HT40PLUS;
22995b9c547cSRui Paulo }
23005b9c547cSRui Paulo }
23015b9c547cSRui Paulo
23025b9c547cSRui Paulo
nl80211_reg_rule_max_eirp(u32 start,u32 end,u32 max_eirp,struct phy_info_arg * results)23035b9c547cSRui Paulo static void nl80211_reg_rule_max_eirp(u32 start, u32 end, u32 max_eirp,
23045b9c547cSRui Paulo struct phy_info_arg *results)
23055b9c547cSRui Paulo {
23065b9c547cSRui Paulo u16 m;
23075b9c547cSRui Paulo
23085b9c547cSRui Paulo for (m = 0; m < *results->num_modes; m++) {
23095b9c547cSRui Paulo int c;
23105b9c547cSRui Paulo struct hostapd_hw_modes *mode = &results->modes[m];
23115b9c547cSRui Paulo
23125b9c547cSRui Paulo for (c = 0; c < mode->num_channels; c++) {
23135b9c547cSRui Paulo struct hostapd_channel_data *chan = &mode->channels[c];
23145b9c547cSRui Paulo if ((u32) chan->freq - 10 >= start &&
23155b9c547cSRui Paulo (u32) chan->freq + 10 <= end)
23165b9c547cSRui Paulo chan->max_tx_power = max_eirp;
23175b9c547cSRui Paulo }
23185b9c547cSRui Paulo }
23195b9c547cSRui Paulo }
23205b9c547cSRui Paulo
23215b9c547cSRui Paulo
nl80211_reg_rule_ht40(u32 start,u32 end,struct phy_info_arg * results)23225b9c547cSRui Paulo static void nl80211_reg_rule_ht40(u32 start, u32 end,
23235b9c547cSRui Paulo struct phy_info_arg *results)
23245b9c547cSRui Paulo {
23255b9c547cSRui Paulo u16 m;
23265b9c547cSRui Paulo
23275b9c547cSRui Paulo for (m = 0; m < *results->num_modes; m++) {
23285b9c547cSRui Paulo if (!(results->modes[m].ht_capab &
23295b9c547cSRui Paulo HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET))
23305b9c547cSRui Paulo continue;
23315b9c547cSRui Paulo nl80211_set_ht40_mode(&results->modes[m], start, end);
23325b9c547cSRui Paulo }
23335b9c547cSRui Paulo }
23345b9c547cSRui Paulo
23355b9c547cSRui Paulo
nl80211_reg_rule_sec(struct nlattr * tb[],struct phy_info_arg * results)23365b9c547cSRui Paulo static void nl80211_reg_rule_sec(struct nlattr *tb[],
23375b9c547cSRui Paulo struct phy_info_arg *results)
23385b9c547cSRui Paulo {
23395b9c547cSRui Paulo u32 start, end, max_bw;
23405b9c547cSRui Paulo u16 m;
23415b9c547cSRui Paulo
23425b9c547cSRui Paulo if (tb[NL80211_ATTR_FREQ_RANGE_START] == NULL ||
23435b9c547cSRui Paulo tb[NL80211_ATTR_FREQ_RANGE_END] == NULL ||
23445b9c547cSRui Paulo tb[NL80211_ATTR_FREQ_RANGE_MAX_BW] == NULL)
23455b9c547cSRui Paulo return;
23465b9c547cSRui Paulo
23475b9c547cSRui Paulo start = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]) / 1000;
23485b9c547cSRui Paulo end = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]) / 1000;
23495b9c547cSRui Paulo max_bw = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) / 1000;
23505b9c547cSRui Paulo
23515b9c547cSRui Paulo if (max_bw < 20)
23525b9c547cSRui Paulo return;
23535b9c547cSRui Paulo
23545b9c547cSRui Paulo for (m = 0; m < *results->num_modes; m++) {
23555b9c547cSRui Paulo if (!(results->modes[m].ht_capab &
23565b9c547cSRui Paulo HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET))
23575b9c547cSRui Paulo continue;
23585b9c547cSRui Paulo nl80211_set_ht40_mode_sec(&results->modes[m], start, end);
23595b9c547cSRui Paulo }
23605b9c547cSRui Paulo }
23615b9c547cSRui Paulo
23625b9c547cSRui Paulo
nl80211_set_vht_mode(struct hostapd_hw_modes * mode,int start,int end,int max_bw)23635b9c547cSRui Paulo static void nl80211_set_vht_mode(struct hostapd_hw_modes *mode, int start,
2364780fb4a2SCy Schubert int end, int max_bw)
23655b9c547cSRui Paulo {
23665b9c547cSRui Paulo int c;
23675b9c547cSRui Paulo
23685b9c547cSRui Paulo for (c = 0; c < mode->num_channels; c++) {
23695b9c547cSRui Paulo struct hostapd_channel_data *chan = &mode->channels[c];
23705b9c547cSRui Paulo
2371*a90b9d01SCy Schubert if (chan->freq - 10 < start || chan->freq + 10 > end)
2372*a90b9d01SCy Schubert continue;
23735b9c547cSRui Paulo
2374*a90b9d01SCy Schubert if (max_bw >= 80)
2375*a90b9d01SCy Schubert chan->flag |= HOSTAPD_CHAN_VHT_80MHZ_SUBCHANNEL;
23765b9c547cSRui Paulo
2377*a90b9d01SCy Schubert if (max_bw >= 160)
2378*a90b9d01SCy Schubert chan->flag |= HOSTAPD_CHAN_VHT_160MHZ_SUBCHANNEL;
23795b9c547cSRui Paulo }
23805b9c547cSRui Paulo }
23815b9c547cSRui Paulo
23825b9c547cSRui Paulo
nl80211_reg_rule_vht(struct nlattr * tb[],struct phy_info_arg * results)23835b9c547cSRui Paulo static void nl80211_reg_rule_vht(struct nlattr *tb[],
23845b9c547cSRui Paulo struct phy_info_arg *results)
23855b9c547cSRui Paulo {
23865b9c547cSRui Paulo u32 start, end, max_bw;
23875b9c547cSRui Paulo u16 m;
23885b9c547cSRui Paulo
23895b9c547cSRui Paulo if (tb[NL80211_ATTR_FREQ_RANGE_START] == NULL ||
23905b9c547cSRui Paulo tb[NL80211_ATTR_FREQ_RANGE_END] == NULL ||
23915b9c547cSRui Paulo tb[NL80211_ATTR_FREQ_RANGE_MAX_BW] == NULL)
23925b9c547cSRui Paulo return;
23935b9c547cSRui Paulo
23945b9c547cSRui Paulo start = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]) / 1000;
23955b9c547cSRui Paulo end = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]) / 1000;
23965b9c547cSRui Paulo max_bw = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) / 1000;
23975b9c547cSRui Paulo
23985b9c547cSRui Paulo if (max_bw < 80)
23995b9c547cSRui Paulo return;
24005b9c547cSRui Paulo
24015b9c547cSRui Paulo for (m = 0; m < *results->num_modes; m++) {
24025b9c547cSRui Paulo if (!(results->modes[m].ht_capab &
24035b9c547cSRui Paulo HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET))
24045b9c547cSRui Paulo continue;
24055b9c547cSRui Paulo /* TODO: use a real VHT support indication */
24065b9c547cSRui Paulo if (!results->modes[m].vht_capab)
24075b9c547cSRui Paulo continue;
24085b9c547cSRui Paulo
2409780fb4a2SCy Schubert nl80211_set_vht_mode(&results->modes[m], start, end, max_bw);
24105b9c547cSRui Paulo }
24115b9c547cSRui Paulo }
24125b9c547cSRui Paulo
24135b9c547cSRui Paulo
nl80211_set_6ghz_mode(struct hostapd_hw_modes * mode,int start,int end,int max_bw)2414*a90b9d01SCy Schubert static void nl80211_set_6ghz_mode(struct hostapd_hw_modes *mode, int start,
2415*a90b9d01SCy Schubert int end, int max_bw)
2416*a90b9d01SCy Schubert {
2417*a90b9d01SCy Schubert int c;
2418*a90b9d01SCy Schubert
2419*a90b9d01SCy Schubert for (c = 0; c < mode->num_channels; c++) {
2420*a90b9d01SCy Schubert struct hostapd_channel_data *chan = &mode->channels[c];
2421*a90b9d01SCy Schubert
2422*a90b9d01SCy Schubert if (chan->freq - 10 < start || chan->freq + 10 > end)
2423*a90b9d01SCy Schubert continue;
2424*a90b9d01SCy Schubert
2425*a90b9d01SCy Schubert if (max_bw >= 80)
2426*a90b9d01SCy Schubert chan->flag |= HOSTAPD_CHAN_VHT_80MHZ_SUBCHANNEL;
2427*a90b9d01SCy Schubert
2428*a90b9d01SCy Schubert if (max_bw >= 160)
2429*a90b9d01SCy Schubert chan->flag |= HOSTAPD_CHAN_VHT_160MHZ_SUBCHANNEL;
2430*a90b9d01SCy Schubert
2431*a90b9d01SCy Schubert if (max_bw >= 320)
2432*a90b9d01SCy Schubert chan->flag |= HOSTAPD_CHAN_EHT_320MHZ_SUBCHANNEL;
2433*a90b9d01SCy Schubert }
2434*a90b9d01SCy Schubert }
2435*a90b9d01SCy Schubert
2436*a90b9d01SCy Schubert
nl80211_reg_rule_6ghz(struct nlattr * tb[],struct phy_info_arg * results)2437*a90b9d01SCy Schubert static void nl80211_reg_rule_6ghz(struct nlattr *tb[],
2438*a90b9d01SCy Schubert struct phy_info_arg *results)
2439*a90b9d01SCy Schubert {
2440*a90b9d01SCy Schubert u32 start, end, max_bw;
2441*a90b9d01SCy Schubert u16 m;
2442*a90b9d01SCy Schubert
2443*a90b9d01SCy Schubert if (!tb[NL80211_ATTR_FREQ_RANGE_START] ||
2444*a90b9d01SCy Schubert !tb[NL80211_ATTR_FREQ_RANGE_END] ||
2445*a90b9d01SCy Schubert !tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
2446*a90b9d01SCy Schubert return;
2447*a90b9d01SCy Schubert
2448*a90b9d01SCy Schubert start = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]) / 1000;
2449*a90b9d01SCy Schubert end = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]) / 1000;
2450*a90b9d01SCy Schubert max_bw = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) / 1000;
2451*a90b9d01SCy Schubert
2452*a90b9d01SCy Schubert if (max_bw < 80)
2453*a90b9d01SCy Schubert return;
2454*a90b9d01SCy Schubert
2455*a90b9d01SCy Schubert for (m = 0; m < *results->num_modes; m++) {
2456*a90b9d01SCy Schubert if (results->modes[m].num_channels == 0 ||
2457*a90b9d01SCy Schubert !is_6ghz_freq(results->modes[m].channels[0].freq))
2458*a90b9d01SCy Schubert continue;
2459*a90b9d01SCy Schubert
2460*a90b9d01SCy Schubert nl80211_set_6ghz_mode(&results->modes[m], start, end, max_bw);
2461*a90b9d01SCy Schubert }
2462*a90b9d01SCy Schubert }
2463*a90b9d01SCy Schubert
2464*a90b9d01SCy Schubert
nl80211_set_dfs_domain(enum nl80211_dfs_regions region,u8 * dfs_domain)246585732ac8SCy Schubert static void nl80211_set_dfs_domain(enum nl80211_dfs_regions region,
246685732ac8SCy Schubert u8 *dfs_domain)
246785732ac8SCy Schubert {
246885732ac8SCy Schubert if (region == NL80211_DFS_FCC)
246985732ac8SCy Schubert *dfs_domain = HOSTAPD_DFS_REGION_FCC;
247085732ac8SCy Schubert else if (region == NL80211_DFS_ETSI)
247185732ac8SCy Schubert *dfs_domain = HOSTAPD_DFS_REGION_ETSI;
247285732ac8SCy Schubert else if (region == NL80211_DFS_JP)
247385732ac8SCy Schubert *dfs_domain = HOSTAPD_DFS_REGION_JP;
247485732ac8SCy Schubert else
247585732ac8SCy Schubert *dfs_domain = 0;
247685732ac8SCy Schubert }
247785732ac8SCy Schubert
247885732ac8SCy Schubert
dfs_domain_name(enum nl80211_dfs_regions region)24795b9c547cSRui Paulo static const char * dfs_domain_name(enum nl80211_dfs_regions region)
24805b9c547cSRui Paulo {
24815b9c547cSRui Paulo switch (region) {
24825b9c547cSRui Paulo case NL80211_DFS_UNSET:
24835b9c547cSRui Paulo return "DFS-UNSET";
24845b9c547cSRui Paulo case NL80211_DFS_FCC:
24855b9c547cSRui Paulo return "DFS-FCC";
24865b9c547cSRui Paulo case NL80211_DFS_ETSI:
24875b9c547cSRui Paulo return "DFS-ETSI";
24885b9c547cSRui Paulo case NL80211_DFS_JP:
24895b9c547cSRui Paulo return "DFS-JP";
24905b9c547cSRui Paulo default:
24915b9c547cSRui Paulo return "DFS-invalid";
24925b9c547cSRui Paulo }
24935b9c547cSRui Paulo }
24945b9c547cSRui Paulo
24955b9c547cSRui Paulo
nl80211_get_reg(struct nl_msg * msg,void * arg)24965b9c547cSRui Paulo static int nl80211_get_reg(struct nl_msg *msg, void *arg)
24975b9c547cSRui Paulo {
24985b9c547cSRui Paulo struct phy_info_arg *results = arg;
24995b9c547cSRui Paulo struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
25005b9c547cSRui Paulo struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
25015b9c547cSRui Paulo struct nlattr *nl_rule;
25025b9c547cSRui Paulo struct nlattr *tb_rule[NL80211_FREQUENCY_ATTR_MAX + 1];
25035b9c547cSRui Paulo int rem_rule;
25045b9c547cSRui Paulo static struct nla_policy reg_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = {
25055b9c547cSRui Paulo [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
25065b9c547cSRui Paulo [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
25075b9c547cSRui Paulo [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
25085b9c547cSRui Paulo [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
25095b9c547cSRui Paulo [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
25105b9c547cSRui Paulo [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
25115b9c547cSRui Paulo };
25125b9c547cSRui Paulo
25135b9c547cSRui Paulo nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
25145b9c547cSRui Paulo genlmsg_attrlen(gnlh, 0), NULL);
25155b9c547cSRui Paulo if (!tb_msg[NL80211_ATTR_REG_ALPHA2] ||
25165b9c547cSRui Paulo !tb_msg[NL80211_ATTR_REG_RULES]) {
25175b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "nl80211: No regulatory information "
25185b9c547cSRui Paulo "available");
25195b9c547cSRui Paulo return NL_SKIP;
25205b9c547cSRui Paulo }
25215b9c547cSRui Paulo
25225b9c547cSRui Paulo if (tb_msg[NL80211_ATTR_DFS_REGION]) {
25235b9c547cSRui Paulo enum nl80211_dfs_regions dfs_domain;
25245b9c547cSRui Paulo dfs_domain = nla_get_u8(tb_msg[NL80211_ATTR_DFS_REGION]);
252585732ac8SCy Schubert nl80211_set_dfs_domain(dfs_domain, &results->dfs_domain);
25265b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "nl80211: Regulatory information - country=%s (%s)",
25275b9c547cSRui Paulo (char *) nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]),
25285b9c547cSRui Paulo dfs_domain_name(dfs_domain));
25295b9c547cSRui Paulo } else {
25305b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "nl80211: Regulatory information - country=%s",
25315b9c547cSRui Paulo (char *) nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]));
25325b9c547cSRui Paulo }
25335b9c547cSRui Paulo
25345b9c547cSRui Paulo nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule)
25355b9c547cSRui Paulo {
25365b9c547cSRui Paulo u32 start, end, max_eirp = 0, max_bw = 0, flags = 0;
25375b9c547cSRui Paulo nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX,
25385b9c547cSRui Paulo nla_data(nl_rule), nla_len(nl_rule), reg_policy);
25395b9c547cSRui Paulo if (tb_rule[NL80211_ATTR_FREQ_RANGE_START] == NULL ||
25405b9c547cSRui Paulo tb_rule[NL80211_ATTR_FREQ_RANGE_END] == NULL)
25415b9c547cSRui Paulo continue;
25425b9c547cSRui Paulo start = nla_get_u32(tb_rule[NL80211_ATTR_FREQ_RANGE_START]) / 1000;
25435b9c547cSRui Paulo end = nla_get_u32(tb_rule[NL80211_ATTR_FREQ_RANGE_END]) / 1000;
25445b9c547cSRui Paulo if (tb_rule[NL80211_ATTR_POWER_RULE_MAX_EIRP])
25455b9c547cSRui Paulo max_eirp = nla_get_u32(tb_rule[NL80211_ATTR_POWER_RULE_MAX_EIRP]) / 100;
25465b9c547cSRui Paulo if (tb_rule[NL80211_ATTR_FREQ_RANGE_MAX_BW])
25475b9c547cSRui Paulo max_bw = nla_get_u32(tb_rule[NL80211_ATTR_FREQ_RANGE_MAX_BW]) / 1000;
25485b9c547cSRui Paulo if (tb_rule[NL80211_ATTR_REG_RULE_FLAGS])
25495b9c547cSRui Paulo flags = nla_get_u32(tb_rule[NL80211_ATTR_REG_RULE_FLAGS]);
25505b9c547cSRui Paulo
25515b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "nl80211: %u-%u @ %u MHz %u mBm%s%s%s%s%s%s%s%s",
25525b9c547cSRui Paulo start, end, max_bw, max_eirp,
25535b9c547cSRui Paulo flags & NL80211_RRF_NO_OFDM ? " (no OFDM)" : "",
25545b9c547cSRui Paulo flags & NL80211_RRF_NO_CCK ? " (no CCK)" : "",
25555b9c547cSRui Paulo flags & NL80211_RRF_NO_INDOOR ? " (no indoor)" : "",
25565b9c547cSRui Paulo flags & NL80211_RRF_NO_OUTDOOR ? " (no outdoor)" :
25575b9c547cSRui Paulo "",
25585b9c547cSRui Paulo flags & NL80211_RRF_DFS ? " (DFS)" : "",
25595b9c547cSRui Paulo flags & NL80211_RRF_PTP_ONLY ? " (PTP only)" : "",
25605b9c547cSRui Paulo flags & NL80211_RRF_PTMP_ONLY ? " (PTMP only)" : "",
25615b9c547cSRui Paulo flags & NL80211_RRF_NO_IR ? " (no IR)" : "");
25625b9c547cSRui Paulo if (max_bw >= 40)
25635b9c547cSRui Paulo nl80211_reg_rule_ht40(start, end, results);
25645b9c547cSRui Paulo if (tb_rule[NL80211_ATTR_POWER_RULE_MAX_EIRP])
25655b9c547cSRui Paulo nl80211_reg_rule_max_eirp(start, end, max_eirp,
25665b9c547cSRui Paulo results);
25675b9c547cSRui Paulo }
25685b9c547cSRui Paulo
25695b9c547cSRui Paulo nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule)
25705b9c547cSRui Paulo {
25715b9c547cSRui Paulo nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX,
25725b9c547cSRui Paulo nla_data(nl_rule), nla_len(nl_rule), reg_policy);
25735b9c547cSRui Paulo nl80211_reg_rule_sec(tb_rule, results);
25745b9c547cSRui Paulo }
25755b9c547cSRui Paulo
25765b9c547cSRui Paulo nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule)
25775b9c547cSRui Paulo {
25785b9c547cSRui Paulo nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX,
25795b9c547cSRui Paulo nla_data(nl_rule), nla_len(nl_rule), reg_policy);
25805b9c547cSRui Paulo nl80211_reg_rule_vht(tb_rule, results);
25815b9c547cSRui Paulo }
25825b9c547cSRui Paulo
2583*a90b9d01SCy Schubert nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule)
2584*a90b9d01SCy Schubert {
2585*a90b9d01SCy Schubert nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX,
2586*a90b9d01SCy Schubert nla_data(nl_rule), nla_len(nl_rule), reg_policy);
2587*a90b9d01SCy Schubert nl80211_reg_rule_6ghz(tb_rule, results);
2588*a90b9d01SCy Schubert }
2589*a90b9d01SCy Schubert
25905b9c547cSRui Paulo return NL_SKIP;
25915b9c547cSRui Paulo }
25925b9c547cSRui Paulo
25935b9c547cSRui Paulo
nl80211_set_regulatory_flags(struct wpa_driver_nl80211_data * drv,struct phy_info_arg * results)25945b9c547cSRui Paulo static int nl80211_set_regulatory_flags(struct wpa_driver_nl80211_data *drv,
25955b9c547cSRui Paulo struct phy_info_arg *results)
25965b9c547cSRui Paulo {
25975b9c547cSRui Paulo struct nl_msg *msg;
25985b9c547cSRui Paulo
25995b9c547cSRui Paulo msg = nlmsg_alloc();
26005b9c547cSRui Paulo if (!msg)
26015b9c547cSRui Paulo return -ENOMEM;
26025b9c547cSRui Paulo
26035b9c547cSRui Paulo nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG);
260485732ac8SCy Schubert if (drv->capa.flags & WPA_DRIVER_FLAGS_SELF_MANAGED_REGULATORY) {
260585732ac8SCy Schubert if (nla_put_u32(msg, NL80211_ATTR_WIPHY, drv->wiphy_idx)) {
260685732ac8SCy Schubert nlmsg_free(msg);
260785732ac8SCy Schubert return -1;
260885732ac8SCy Schubert }
260985732ac8SCy Schubert }
261085732ac8SCy Schubert
2611*a90b9d01SCy Schubert return send_and_recv_resp(drv, msg, nl80211_get_reg, results);
26125b9c547cSRui Paulo }
26135b9c547cSRui Paulo
26145b9c547cSRui Paulo
modestr(enum hostapd_hw_mode mode)26154bc52338SCy Schubert static const char * modestr(enum hostapd_hw_mode mode)
26164bc52338SCy Schubert {
26174bc52338SCy Schubert switch (mode) {
26184bc52338SCy Schubert case HOSTAPD_MODE_IEEE80211B:
26194bc52338SCy Schubert return "802.11b";
26204bc52338SCy Schubert case HOSTAPD_MODE_IEEE80211G:
26214bc52338SCy Schubert return "802.11g";
26224bc52338SCy Schubert case HOSTAPD_MODE_IEEE80211A:
26234bc52338SCy Schubert return "802.11a";
26244bc52338SCy Schubert case HOSTAPD_MODE_IEEE80211AD:
26254bc52338SCy Schubert return "802.11ad";
26264bc52338SCy Schubert default:
26274bc52338SCy Schubert return "?";
26284bc52338SCy Schubert }
26294bc52338SCy Schubert }
26304bc52338SCy Schubert
26314bc52338SCy Schubert
nl80211_dump_chan_list(struct wpa_driver_nl80211_data * drv,struct hostapd_hw_modes * modes,u16 num_modes)2632*a90b9d01SCy Schubert static void nl80211_dump_chan_list(struct wpa_driver_nl80211_data *drv,
2633*a90b9d01SCy Schubert struct hostapd_hw_modes *modes,
26344bc52338SCy Schubert u16 num_modes)
26354bc52338SCy Schubert {
26364bc52338SCy Schubert int i;
26374bc52338SCy Schubert
26384bc52338SCy Schubert if (!modes)
26394bc52338SCy Schubert return;
26404bc52338SCy Schubert
26414bc52338SCy Schubert for (i = 0; i < num_modes; i++) {
26424bc52338SCy Schubert struct hostapd_hw_modes *mode = &modes[i];
2643*a90b9d01SCy Schubert char str[1000];
26444bc52338SCy Schubert char *pos = str;
26454bc52338SCy Schubert char *end = pos + sizeof(str);
26464bc52338SCy Schubert int j, res;
26474bc52338SCy Schubert
26484bc52338SCy Schubert for (j = 0; j < mode->num_channels; j++) {
26494bc52338SCy Schubert struct hostapd_channel_data *chan = &mode->channels[j];
26504bc52338SCy Schubert
2651*a90b9d01SCy Schubert if (is_6ghz_freq(chan->freq))
2652*a90b9d01SCy Schubert drv->uses_6ghz = true;
2653*a90b9d01SCy Schubert if (chan->freq >= 900 && chan->freq < 1000)
2654*a90b9d01SCy Schubert drv->uses_s1g = true;
26554bc52338SCy Schubert res = os_snprintf(pos, end - pos, " %d%s%s%s",
26564bc52338SCy Schubert chan->freq,
26574bc52338SCy Schubert (chan->flag & HOSTAPD_CHAN_DISABLED) ?
26584bc52338SCy Schubert "[DISABLED]" : "",
26594bc52338SCy Schubert (chan->flag & HOSTAPD_CHAN_NO_IR) ?
26604bc52338SCy Schubert "[NO_IR]" : "",
26614bc52338SCy Schubert (chan->flag & HOSTAPD_CHAN_RADAR) ?
26624bc52338SCy Schubert "[RADAR]" : "");
26634bc52338SCy Schubert if (os_snprintf_error(end - pos, res))
26644bc52338SCy Schubert break;
26654bc52338SCy Schubert pos += res;
26664bc52338SCy Schubert }
26674bc52338SCy Schubert
26684bc52338SCy Schubert *pos = '\0';
26694bc52338SCy Schubert wpa_printf(MSG_DEBUG, "nl80211: Mode IEEE %s:%s",
26704bc52338SCy Schubert modestr(mode->mode), str);
26714bc52338SCy Schubert }
26724bc52338SCy Schubert }
26734bc52338SCy Schubert
26744bc52338SCy Schubert
26755b9c547cSRui Paulo struct hostapd_hw_modes *
nl80211_get_hw_feature_data(void * priv,u16 * num_modes,u16 * flags,u8 * dfs_domain)267685732ac8SCy Schubert nl80211_get_hw_feature_data(void *priv, u16 *num_modes, u16 *flags,
267785732ac8SCy Schubert u8 *dfs_domain)
26785b9c547cSRui Paulo {
26795b9c547cSRui Paulo u32 feat;
26805b9c547cSRui Paulo struct i802_bss *bss = priv;
26815b9c547cSRui Paulo struct wpa_driver_nl80211_data *drv = bss->drv;
26825b9c547cSRui Paulo int nl_flags = 0;
26835b9c547cSRui Paulo struct nl_msg *msg;
26845b9c547cSRui Paulo struct phy_info_arg result = {
26855b9c547cSRui Paulo .num_modes = num_modes,
26865b9c547cSRui Paulo .modes = NULL,
26875b9c547cSRui Paulo .last_mode = -1,
2688780fb4a2SCy Schubert .failed = 0,
268985732ac8SCy Schubert .dfs_domain = 0,
26905b9c547cSRui Paulo };
26915b9c547cSRui Paulo
26925b9c547cSRui Paulo *num_modes = 0;
26935b9c547cSRui Paulo *flags = 0;
269485732ac8SCy Schubert *dfs_domain = 0;
26955b9c547cSRui Paulo
26965b9c547cSRui Paulo feat = get_nl80211_protocol_features(drv);
26975b9c547cSRui Paulo if (feat & NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)
26985b9c547cSRui Paulo nl_flags = NLM_F_DUMP;
26995b9c547cSRui Paulo if (!(msg = nl80211_cmd_msg(bss, nl_flags, NL80211_CMD_GET_WIPHY)) ||
27005b9c547cSRui Paulo nla_put_flag(msg, NL80211_ATTR_SPLIT_WIPHY_DUMP)) {
27015b9c547cSRui Paulo nlmsg_free(msg);
27025b9c547cSRui Paulo return NULL;
27035b9c547cSRui Paulo }
27045b9c547cSRui Paulo
2705*a90b9d01SCy Schubert if (send_and_recv_resp(drv, msg, phy_info_handler, &result) == 0) {
27064bc52338SCy Schubert struct hostapd_hw_modes *modes;
27074bc52338SCy Schubert
27085b9c547cSRui Paulo nl80211_set_regulatory_flags(drv, &result);
2709780fb4a2SCy Schubert if (result.failed) {
2710780fb4a2SCy Schubert int i;
2711780fb4a2SCy Schubert
2712780fb4a2SCy Schubert for (i = 0; result.modes && i < *num_modes; i++) {
2713780fb4a2SCy Schubert os_free(result.modes[i].channels);
2714780fb4a2SCy Schubert os_free(result.modes[i].rates);
2715780fb4a2SCy Schubert }
2716780fb4a2SCy Schubert os_free(result.modes);
271785732ac8SCy Schubert *num_modes = 0;
2718780fb4a2SCy Schubert return NULL;
2719780fb4a2SCy Schubert }
272085732ac8SCy Schubert
272185732ac8SCy Schubert *dfs_domain = result.dfs_domain;
272285732ac8SCy Schubert
27234bc52338SCy Schubert modes = wpa_driver_nl80211_postprocess_modes(result.modes,
27245b9c547cSRui Paulo num_modes);
2725*a90b9d01SCy Schubert nl80211_dump_chan_list(drv, modes, *num_modes);
27264bc52338SCy Schubert return modes;
27275b9c547cSRui Paulo }
27285b9c547cSRui Paulo
27295b9c547cSRui Paulo return NULL;
27305b9c547cSRui Paulo }
2731